Compare commits
No commits in common. "abad7e2b40cfbac97795a19cb1773cc8197871ea" and "706e5ed07ebda5367353e8092793826caec46f78" have entirely different histories.
abad7e2b40
...
706e5ed07e
@ -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 the signin was successfull
|
// only show the outlet if data have loaded
|
||||||
<Show when=move || websocket.authenticated.get() fallback=login::Login>
|
<Show when=move || websocket.authenticated.get() fallback=login::Login>
|
||||||
<Outlet/>
|
<Outlet/>
|
||||||
</Show>
|
</Show>
|
||||||
|
@ -73,13 +73,11 @@ 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");
|
||||||
|
|
||||||
@ -97,7 +95,6 @@ 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,
|
||||||
@ -105,11 +102,9 @@ 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()),
|
||||||
@ -121,7 +116,6 @@ 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…
x
Reference in New Issue
Block a user