mirror of
https://github.com/kristoferssolo/cipher-workshop.git
synced 2025-12-20 11:04:38 +00:00
feat(web): add persistent theme
This commit is contained in:
parent
01eac0bc85
commit
045f49a9ef
@ -4,17 +4,17 @@ use std::fmt::Display;
|
||||
|
||||
#[component]
|
||||
pub fn Header() -> impl IntoView {
|
||||
let initial_theme = {
|
||||
let (theme, set_theme) = signal(Theme::Dark);
|
||||
|
||||
Effect::new(move |_| {
|
||||
if let Ok(Some(storage)) = window().local_storage()
|
||||
&& let Ok(Some(saved)) = storage.get_item("theme")
|
||||
{
|
||||
Theme::from_local_storage(&saved)
|
||||
} else {
|
||||
Theme::Dark
|
||||
let theme = Theme::from_local_storage(&saved);
|
||||
set_theme(theme);
|
||||
apply_theme(theme);
|
||||
}
|
||||
};
|
||||
|
||||
let (theme, set_theme) = signal(initial_theme);
|
||||
});
|
||||
|
||||
let toggle_theme = move |_| {
|
||||
set_theme.update(|t| *t = t.inverse());
|
||||
@ -22,7 +22,6 @@ pub fn Header() -> impl IntoView {
|
||||
if let Ok(Some(storage)) = window().local_storage() {
|
||||
let _ = storage.set_item("theme", theme.get().to_local_storage());
|
||||
}
|
||||
|
||||
apply_theme(theme.get());
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user