-
"Comunidad - Rust Lang en Español"
-
-
+
}
}
diff --git a/src/components/header.rs b/src/components/header.rs
index 63f806f..0eccbc2 100644
--- a/src/components/header.rs
+++ b/src/components/header.rs
@@ -1,18 +1,22 @@
use crate::{
- components::icons::{NewLogoRustDarkPageIcon, NewLogoRustLightPageIcon},
+ components::{
+ BOOK_PATH, JOIN_PATH,
+ icons::{NewLogoRustDarkPageIcon, NewLogoRustLightPageIcon},
+ },
context::theme_provider::{Theme, use_theme},
};
-use leptos::{leptos_dom::logging::console_log, prelude::*};
+use leptos::prelude::*;
use leptos_use::{use_media_query, use_window};
use rustlanges_components::{
button::{Button, Variant},
- icons::{Moon, SunLine, SunMoon},
+ icons::{Close, Menu, Moon, SunLine, SunMoon},
};
#[island]
pub fn Header() -> impl IntoView {
let this = use_window();
let path = RwSignal::new("/".to_string());
+ let menu_open = RwSignal::new(false);
Effect::new(move |_| {
let result = format!(
@@ -35,6 +39,18 @@ pub fn Header() -> impl IntoView {
Theme::System => view! {
}.into_any(),
};
+ let menu_handler = move |_| {
+ menu_open.update(|open| *open = !*open);
+ };
+
+ let menu_icon = move || {
+ if menu_open() {
+ view! {
}.into_any()
+ } else {
+ view! {
}.into_any()
+ }
+ };
+
let theme_switcher_icon = move || match theme() {
Theme::Dark => view! {
}.into_any(),
Theme::Light => view! {
}.into_any(),
@@ -43,25 +59,35 @@ pub fn Header() -> impl IntoView {
let active_link_class = move |link: &str| {
if path() == format!("{link:?}") {
- "text-red-500 dark:text-orange-300"
+ "font-bold text-red-500 dark:text-orange-300"
} else {
""
}
};
- let handler = move |_| {
+ let theme_handler = move |_| {
let current_theme = theme.get();
match current_theme {
- Theme::System => theme.set(Theme::Dark),
- Theme::Dark => theme.set(Theme::Light),
- Theme::Light => theme.set(Theme::System),
+ Theme::Light => theme.set(Theme::Dark),
+ Theme::Dark | Theme::System => theme.set(Theme::Light),
}
};
view! {
-
- {move || logo()}
-
+
+
+
+
+
diff --git a/src/components/mod.rs b/src/components/mod.rs
index c2432bd..ed278de 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -22,3 +22,9 @@ pub mod project_card;
pub mod resources;
pub mod sponsor_block;
pub mod why_rust;
+
+const BOOK_PATH: &str = "https://book.rustlang-es.org/";
+const JOIN_PATH: &str = "https://discord.rustlang-es.org/";
+const GITHUB_PATH: &str = "https://github.com/RustLangES";
+const LINKEDIN_PATH: &str = "https://www.linkedin.com/company/rustlanges";
+const TELEGRAM_PATH: &str = "https://t.me/rust_es";
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;