Problem: use_color_mode doesn't work with new use_storage API. Use StringCodec

This commit is contained in:
Joshua McQuistan 2023-10-27 20:46:53 +01:00
parent 1371b81b67
commit f23d8ad31c

View file

@ -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<String> for ColorMode {
}
}
impl FromStr for ColorMode {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(ColorMode::from(s))
}
}
#[derive(DefaultBuilder)]
pub struct UseColorModeOptions<El, T>
where