From f23d8ad31cf966f510b92bdb06f50634f241c905 Mon Sep 17 00:00:00 2001 From: Joshua McQuistan Date: Fri, 27 Oct 2023 20:46:53 +0100 Subject: [PATCH] Problem: use_color_mode doesn't work with new use_storage API. Use StringCodec --- src/use_color_mode.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/use_color_mode.rs b/src/use_color_mode.rs index 86efba4..af7e2b8 100644 --- a/src/use_color_mode.rs +++ b/src/use_color_mode.rs @@ -1,6 +1,7 @@ use crate::core::{ElementMaybeSignal, MaybeRwSignal}; use crate::storage::{use_storage_with_options, UseStorageOptions}; use std::fmt::{Display, Formatter}; +use std::str::FromStr; use crate::core::StorageType; use crate::use_preferred_dark; @@ -263,13 +264,14 @@ fn get_store_signal( let (store, set_store) = storage_signal.split(); (store.into(), set_store) } else if storage_enabled { - use_storage_with_options( + let (store, set_store, _) = use_storage_with_options( + storage, storage_key, - initial_value, - UseStorageOptions::default() + UseStorageOptions::string_codec() .listen_to_storage_changes(listen_to_storage_changes) - .storage_type(storage), - ) + .default_value(initial_value), + ); + (store, set_store) } else { initial_value.into_signal() } @@ -306,6 +308,14 @@ impl From for ColorMode { } } +impl FromStr for ColorMode { + type Err = (); + + fn from_str(s: &str) -> Result { + Ok(ColorMode::from(s)) + } +} + #[derive(DefaultBuilder)] pub struct UseColorModeOptions where