From 1a189cf7a4ba61ca83d831c214e4e8ef143fc09e Mon Sep 17 00:00:00 2001 From: Maccesch Date: Mon, 2 Sep 2024 18:21:21 +0100 Subject: [PATCH] fixed use_color_mode with cookie enabled. fixes #170 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- examples/ssr/Cargo.toml | 2 +- src/use_color_mode.rs | 12 ++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce9fc39..ab33695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.13.3] - 2024-09-02 + +### Fix 🍕 + +- Fixed `use_color_mode` with cookies enabled + ## [0.13.2] - 2024-09-02 ### Fix 🍕 diff --git a/Cargo.toml b/Cargo.toml index 28dc9c5..449515f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leptos-use" -version = "0.13.2" +version = "0.13.3" edition = "2021" authors = ["Marc-Stefan Cassola"] categories = ["gui", "web-programming"] diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml index 8840456..05616e1 100644 --- a/examples/ssr/Cargo.toml +++ b/examples/ssr/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -codee.workspace = true +codee = "0.2" console_error_panic_hook = "0.1" console_log = "1" cfg-if = "1" diff --git a/src/use_color_mode.rs b/src/use_color_mode.rs index 28ded80..06df246 100644 --- a/src/use_color_mode.rs +++ b/src/use_color_mode.rs @@ -215,11 +215,15 @@ where let _ = sync_signal_with_options( (cookie, set_cookie), (store, set_store), - SyncSignalOptions::with_transforms( - move |cookie: &Option| { - cookie.clone().unwrap_or_else(|| store.get_untracked()) + SyncSignalOptions::with_assigns( + move |store: &mut ColorMode, cookie: &Option| { + if let Some(cookie) = cookie { + *store = cookie.clone(); + } + }, + move |cookie: &mut Option, store: &ColorMode| { + *cookie = Some(store.clone()) }, - move |store: &ColorMode| Some(store.clone()), ), ); }