Use GlobalState instead of passing play_status/logged_in_user everywhere
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
use crate::auth::login;
|
||||
use crate::util::state::GlobalState;
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use crate::users::UserCredentials;
|
||||
use crate::app::LoggedInUserResource;
|
||||
|
||||
#[component]
|
||||
pub fn Login(user: LoggedInUserResource) -> impl IntoView {
|
||||
pub fn Login() -> impl IntoView {
|
||||
let (username_or_email, set_username_or_email) = create_signal("".to_string());
|
||||
let (password, set_password) = create_signal("".to_string());
|
||||
|
||||
@ -28,6 +28,8 @@ pub fn Login(user: LoggedInUserResource) -> impl IntoView {
|
||||
username_or_email: username_or_email1,
|
||||
password: password1
|
||||
};
|
||||
|
||||
let user = GlobalState::logged_in_user();
|
||||
|
||||
let login_result = login(user_credentials).await;
|
||||
if let Err(err) = login_result {
|
||||
|
@ -11,9 +11,9 @@ use crate::components::error::*;
|
||||
|
||||
use crate::api::profile::*;
|
||||
|
||||
use crate::app::LoggedInUserResource;
|
||||
use crate::models::User;
|
||||
use crate::users::get_user_by_id;
|
||||
use crate::util::state::GlobalState;
|
||||
|
||||
/// Duration in seconds backwards from now to aggregate history data for
|
||||
const HISTORY_SECS: i64 = 60 * 60 * 24 * 30;
|
||||
@ -29,7 +29,7 @@ const TOP_ARTISTS_COUNT: i64 = 10;
|
||||
/// Profile page
|
||||
/// Shows the current user's profile if no id is specified, or a user's profile if an id is specified in the path
|
||||
#[component]
|
||||
pub fn Profile(logged_in_user: LoggedInUserResource) -> impl IntoView {
|
||||
pub fn Profile() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
|
||||
view! {
|
||||
@ -38,7 +38,7 @@ pub fn Profile(logged_in_user: LoggedInUserResource) -> impl IntoView {
|
||||
match params.get("id").map(|id| id.parse::<i32>()) {
|
||||
None => {
|
||||
// No id specified, show the current user's profile
|
||||
view! { <OwnProfile logged_in_user /> }.into_view()
|
||||
view! { <OwnProfile /> }.into_view()
|
||||
},
|
||||
Some(Ok(id)) => {
|
||||
// Id specified, get the user and show their profile
|
||||
@ -61,12 +61,12 @@ pub fn Profile(logged_in_user: LoggedInUserResource) -> impl IntoView {
|
||||
|
||||
/// Show the logged in user's profile
|
||||
#[component]
|
||||
fn OwnProfile(logged_in_user: LoggedInUserResource) -> impl IntoView {
|
||||
fn OwnProfile() -> impl IntoView {
|
||||
view! {
|
||||
<Transition
|
||||
fallback=move || view! { <LoadingPage /> }
|
||||
>
|
||||
{move || logged_in_user.get().map(|user| {
|
||||
{move || GlobalState::logged_in_user().get().map(|user| {
|
||||
match user {
|
||||
Some(user) => {
|
||||
let user_id = user.id.unwrap();
|
||||
|
@ -1,12 +1,12 @@
|
||||
use crate::auth::signup;
|
||||
use crate::models::User;
|
||||
use crate::util::state::GlobalState;
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use crate::app::LoggedInUserResource;
|
||||
|
||||
#[component]
|
||||
pub fn Signup(user: LoggedInUserResource) -> impl IntoView {
|
||||
pub fn Signup() -> impl IntoView {
|
||||
let (username, set_username) = create_signal("".to_string());
|
||||
let (email, set_email) = create_signal("".to_string());
|
||||
let (password, set_password) = create_signal("".to_string());
|
||||
@ -30,6 +30,8 @@ pub fn Signup(user: LoggedInUserResource) -> impl IntoView {
|
||||
};
|
||||
log!("new user: {:?}", new_user);
|
||||
|
||||
let user = GlobalState::logged_in_user();
|
||||
|
||||
spawn_local(async move {
|
||||
if let Err(err) = signup(new_user.clone()).await {
|
||||
// Handle the error here, e.g., log it or display to the user
|
||||
|
Reference in New Issue
Block a user