Remove derive Default for User and make user signal Option type instead
This commit is contained in:
parent
f78066d7a8
commit
f104a14f98
@ -18,7 +18,8 @@ pub fn Personal() -> impl IntoView {
|
||||
pub fn Profile() -> impl IntoView {
|
||||
let (dropdown_open, set_dropdown_open) = create_signal(false);
|
||||
let logged_in = create_rw_signal(false);
|
||||
let user_signal = create_rw_signal(User::default());
|
||||
// user signal is an option because the user may not be logged in
|
||||
let user_signal = create_rw_signal(None);
|
||||
|
||||
let open_dropdown = move |_| {
|
||||
spawn_local(async move {
|
||||
@ -26,7 +27,7 @@ pub fn Profile() -> impl IntoView {
|
||||
if let Ok(user) = user {
|
||||
logged_in.set(true);
|
||||
user_signal.update(|value| {
|
||||
*value = user;
|
||||
*value = Some(user);
|
||||
});
|
||||
} else {
|
||||
logged_in.set(false);
|
||||
@ -63,7 +64,7 @@ pub fn DropDownNotLoggedIn() -> impl IntoView {
|
||||
}
|
||||
}
|
||||
#[component]
|
||||
pub fn DropDownLoggedIn(user_signal: RwSignal<User>, logged_in: RwSignal<bool>) -> impl IntoView {
|
||||
pub fn DropDownLoggedIn(user_signal: RwSignal<Option<User>>, logged_in: RwSignal<bool>) -> impl IntoView {
|
||||
|
||||
let logout = move |_| {
|
||||
spawn_local(async move {
|
||||
@ -72,7 +73,7 @@ pub fn DropDownLoggedIn(user_signal: RwSignal<User>, logged_in: RwSignal<bool>)
|
||||
log!("Error logging out: {:?}", err);
|
||||
} else {
|
||||
log!("Logged out successfully");
|
||||
user_signal.update(|value| *value = User::default());
|
||||
user_signal.update(|value| *value = None);
|
||||
logged_in.set(false);
|
||||
}
|
||||
});
|
||||
@ -82,7 +83,13 @@ pub fn DropDownLoggedIn(user_signal: RwSignal<User>, logged_in: RwSignal<bool>)
|
||||
<div class="dropdown-logged">
|
||||
<h1>"Logged In"</h1>
|
||||
<div class="profile-info">
|
||||
<h1>{move || user_signal.with(|user| user.username.clone())}</h1>
|
||||
<h1>{move || user_signal.with(|user|
|
||||
if let Some(user) = user {
|
||||
user.username.clone()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
)}</h1>
|
||||
</div>
|
||||
<button on:click=logout class="auth-button">Log Out</button>
|
||||
</div>
|
||||
|
@ -25,7 +25,7 @@ cfg_if! {
|
||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))]
|
||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::users))]
|
||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct User {
|
||||
/// A unique id for the user
|
||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||
|
Loading…
x
Reference in New Issue
Block a user