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> <Routes>
<Route path="/" view=move || { <Route path="/" view=move || {
view! { 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> <Show when=move || websocket.authenticated.get() fallback=login::Login>
<Outlet/> <Outlet/>
</Show> </Show>

View File

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