-
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
base: shared-components
Are you sure you want to change the base?
Header #103
Changes from all commits
577e143
bbe2e6e
5f97f6b
335c309
9a7cc0d
5a080bf
47d577b
e812ca2
4fef642
ad99970
ba2f006
9a728d3
2baf604
7b2631f
3a0c660
File filter
Filter by extension
Conversations
Jump to
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.
| 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
Contributor
Author
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. Estaba configurado previamente con storage, pero como es SSR, la config que enviaba el cliente no matcheaba con el por defecto que generaba el server, entonces entraba eso en conflicto, por ello se realizó este cambio a cookies.
Contributor
Author
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.
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. Pero igual el target no es SSR, es CSR, en todo caso lo que podemos hacer es un feature flag para hacer conditional compilation ✨ Eso
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. Dejame ver Ted Lasso Mario, espabila que la vida te va a comer
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.
Contributor
Author
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. Presumiendo el privilegio de mac user
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. Sactamente 🙏
Contributor
Author
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.
Dime mañana, en tu video no dices nada de eso:
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. Maldición Mario, tienes razón, y encima no tengo ningún video acerca de conditional compilation (CREO) 😭 |
||||||||||
|
|
||||||||||
| /// 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.