Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21
Header#103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Header #103
Changes from all commits
577e143bbe2e6e5f97f6b335c3099a7cc0d5a080bf47d577be812ca24fef642ad99970ba2f0069a728d32baf6047b2631f3a0c660File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,6 +8,8 @@ bundled.css | ||
| /assets/gen_assets/ | ||
| /src/extras/ | ||
| Cargo.lock | ||
| # NixOs output folder | ||
| /result | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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}; | ||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||||||
| 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"; | ||||||||||
Comment on lines
+41
to
+42
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Es mejor mediante storage, no tiene sentido enviar esa información en requests
| ||||||||||
| /// 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::<Theme, JsonSerdeCodec>(STORAGE_KEY); | ||||||||||
| let (theme_storage_state, set_theme_storage_state) = | ||||||||||
| use_cookie::<Theme, JsonSerdeCodec>(COOKIE_KEY); | ||||||||||
Comment on lines
+106
to
+107
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||||||
| 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(), | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| use leptos::{IntoView, component}; | ||
| #[component] | ||
| pub fn Blog() -> impl IntoView {} |
Uh oh!
There was an error while loading. Please reload this page.

Uh oh!
There was an error while loading. Please reload this page.