diff --git a/src/context/theme_provider.rs b/src/context/theme_provider.rs
index 6a1c0fa..ab68919 100644
--- a/src/context/theme_provider.rs
+++ b/src/context/theme_provider.rs
@@ -1,13 +1,14 @@
+use std::fmt::Display;
+
use leptos::{
children::Children,
prelude::{RwSignal, use_context, *},
server::codee::string::JsonSerdeCodec,
*,
};
-use leptos_use::{storage::use_local_storage, use_media_query};
+use leptos_use::{use_cookie, use_media_query};
use serde::{Deserialize, Serialize};
-/// Defines an enumeration for UI themes.
-///
+
/// This enum can be cloned, copied, and compared for equality.
/// It also supports serialization and deserialization for local storage.
#[derive(Clone, Copy, PartialEq, Serialize, Deserialize, Debug)]
@@ -17,28 +18,28 @@ pub enum Theme {
System,
}
-// Implementation of the default value for the `Theme` enum
impl Default for Theme {
- /// provides the default theme as `Dark`
fn default() -> Self {
Theme::Dark
}
}
-#[allow(clippy::inherent_to_string)]
-impl Theme {
- /// Converts the `Theme` variant into a corresponding string.
- pub fn to_string(self) -> String {
- String::from(match self {
- Theme::Light => "light",
- Theme::Dark => "dark",
- Theme::System => "system",
- })
+impl Display for Theme {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ Theme::Light => "light",
+ Theme::Dark => "dark",
+ Theme::System => "system",
+ }
+ )
}
}
-/// Define a constant for the local storage key used to store the theme setting.
-const STORAGE_KEY: &str = "theme";
+/// Define a constant for the cookie key used to store the theme setting.
+const COOKIE_KEY: &str = "theme";
/// Updates the class selector for the respective theme.
/// This function is responsible for applying the correct CSS class to the HTML and body elements based on the current theme.
@@ -102,16 +103,16 @@ pub fn ThemeProvider(children: Children) -> impl IntoView {
let is_dark_preferred_signal = use_media_query("(prefers-color-scheme: dark)");
// Attempt to retrieve the theme from local storage
- let (theme_storage_state, set_theme_storage_state, _) =
- use_local_storage::(STORAGE_KEY);
+ let (theme_storage_state, set_theme_storage_state) =
+ use_cookie::(COOKIE_KEY);
- let theme_state = RwSignal::new(theme_storage_state.get_untracked());
+ let theme_state = RwSignal::new(theme_storage_state.get_untracked().unwrap_or_default());
provide_context(theme_state);
// Update local storage and CSS whenever the theme state changes
Effect::new(move |_| {
- let current_theme = theme_state();
- set_theme_storage_state.set(current_theme);
+ let current_theme: Theme = theme_state();
+ set_theme_storage_state.set(Some(current_theme));
update_css_for_theme(
current_theme,
is_dark_preferred_signal(),
diff --git a/src/pages/blog.rs b/src/pages/blog.rs
new file mode 100644
index 0000000..ca0436e
--- /dev/null
+++ b/src/pages/blog.rs
@@ -0,0 +1,4 @@
+use leptos::{IntoView, component};
+
+#[component]
+pub fn Blog() -> impl IntoView {}
diff --git a/src/pages/events.rs b/src/pages/events.rs
new file mode 100644
index 0000000..b92f451
--- /dev/null
+++ b/src/pages/events.rs
@@ -0,0 +1,4 @@
+use leptos::{IntoView, component};
+
+#[component]
+pub fn Events() -> impl IntoView {}
diff --git a/src/pages/mod.rs b/src/pages/mod.rs
index 0e86d06..be6f22e 100644
--- a/src/pages/mod.rs
+++ b/src/pages/mod.rs
@@ -1,11 +1,15 @@
mod aprende;
+mod blog;
mod communities;
mod contributors;
+mod events;
mod index;
mod projects;
pub use aprende::Aprende;
+pub use blog::Blog;
pub use communities::Communities;
pub use contributors::Contributors;
+pub use events::Events;
pub use index::Index;
pub use projects::Projects;