Skip to content

Commit

Permalink
Set current_user attribute on register
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Dec 14, 2023
1 parent 1943a82 commit 7fa46e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/polyphony-wasm/src/app/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ async fn register(input: &(String, String, String)) -> ChorusResult<()> {
debug!("Got account with token {}", account.as_ref().unwrap().token);
if let Ok(account) = account {
let user_store = use_context::<RwSignal<HashMap<GlobalIdentifier, ChorusUser>>>().unwrap();
let current_user = use_context::<RwSignal<Option<GlobalIdentifier>>>().unwrap();
let id = account.object.read().unwrap().id;
user_store.update(move |map| {
user_store.update(|map| {
map.insert((urls.clone(), id), account);
});
current_user.set(Some((urls.clone(), id)));
Ok(())
} else {
Err(account.unwrap_err())
Expand Down
2 changes: 2 additions & 0 deletions crates/polyphony-wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ fn App() -> impl IntoView {
let chorus_store = ChorusStore::default();
provide_context(chorus_store.instances);
provide_context(chorus_store.users);
provide_context(chorus_store.current_user);
debug!("Rendering the App view");
view! {
<Router>
<main>
<Routes>
<Route path="/" view=|| view! { "welcome" }/>
<Route path="/register" view=Register/>
<Route path="/u" view=|| view! { "hi" }>
<Route path=":id" view=|| view! {"meow"}/>
Expand Down
1 change: 1 addition & 0 deletions crates/polyphony-wasm/src/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ use crate::GlobalIdentifier;
pub(crate) struct ChorusStore {
pub(crate) instances: RwSignal<HashMap<UrlBundle, Instance>>,
pub(crate) users: RwSignal<HashMap<GlobalIdentifier, ChorusUser>>,
pub(crate) current_user: RwSignal<Option<GlobalIdentifier>>,
}

0 comments on commit 7fa46e9

Please sign in to comment.