Added documentation
This commit is contained in:
parent
706e5ed07e
commit
febfbb90b0
@ -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>
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user