Added documentation #7

Merged
xeovalyte merged 1 commits from documentation into main 2024-02-19 10:55:06 +01:00
2 changed files with 7 additions and 1 deletions

View File

@ -63,7 +63,7 @@ pub fn App() -> impl IntoView {
<Routes>
<Route path="/" view=move || {
view! {
// only show the outlet if data have loaded
// only show the outlet if the signin was successfull
<Show when=move || websocket.authenticated.get() fallback=login::Login>
<Outlet/>
</Show>

View File

@ -73,11 +73,13 @@ impl SurrealContext {
}
}
/// Send a string to surrealDB
#[inline(always)]
pub fn send(&self, message: &str) {
(self.send)(message)
}
/// sigin SurrealDB
pub fn signin(&self, pass: String) {
log::debug!("Signing into surrealdb");
@ -95,6 +97,7 @@ impl SurrealContext {
}
pub fn init_surrealdb() {
// Initialize a connection to surrealDB
let UseWebsocketReturn {
ready_state,
message,
@ -102,9 +105,11 @@ pub fn init_surrealdb() {
..
} = use_websocket("ws://localhost:80/rpc");
// Create reactive signals for the websocket connection to surrealDB
let (participants, _set_participants) = create_signal::<Vec<Participant>>(vec![]);
let (authenticated, set_authenticated) = create_signal::<bool>(false);
// Bind the websocket connection to a context
let websocket = SurrealContext::new(
message,
Rc::new(send.clone()),
@ -116,6 +121,7 @@ pub fn init_surrealdb() {
provide_context(websocket);
provide_context(ParticipantsContext(participants));
// Watch for a message recieved from the surrealDB connection
create_effect(move |prev_value| {
let msg = message.get();