(
#[prop()] key: String,
#[prop()] title: K,
#[prop()] tooltip: K1,
#[prop()] show_input: bool,
#[prop()] inp_type: String,
#[prop()] mobile: bool,
)
| 152 | #[tracing::instrument(level = "debug", skip(key, title, tooltip, show_input, inp_type))] |
| 153 | #[component()] |
| 154 | pub fn InputPref<K, H, K1, H1>( |
| 155 | #[prop()] key: String, |
| 156 | #[prop()] title: K, |
| 157 | #[prop()] tooltip: K1, |
| 158 | #[prop()] show_input: bool, |
| 159 | #[prop()] inp_type: String, |
| 160 | #[prop()] mobile: bool, |
| 161 | ) -> impl IntoView |
| 162 | where |
| 163 | K: Fn() -> H + Send + Sync + 'static, |
| 164 | H: IntoView + Copy + 'static, |
| 165 | K1: Fn() -> H1 + Send + Sync + 'static, |
| 166 | H1: IntoView + Copy + 'static, |
| 167 | { |
| 168 | let ui_store = expect_context::<RwSignal<UiStore>>(); |
| 169 | let is_mobile = create_read_slice(ui_store, |u| u.get_is_mobile()).get(); |
| 170 | if is_mobile && !mobile { |
| 171 | return ().into_any(); |
| 172 | } |
| 173 | |
| 174 | let should_write = RwSignal::new(false); |
| 175 | let pref_value = RwSignal::new(Default::default()); |
| 176 | let pref_key = key.clone(); |
| 177 | |
| 178 | if inp_type == "number" { |
| 179 | let num_pref = RwSignal::new(f64::default()); |
| 180 | load_selective(pref_key.clone(), num_pref.write_only()); |
| 181 | Effect::new(move || { |
| 182 | let num_pref = num_pref.get(); |
| 183 | pref_value.set(format!("{}", num_pref)); |
| 184 | }); |
| 185 | } else { |
| 186 | load_selective(pref_key.clone(), pref_value.write_only()); |
| 187 | } |
| 188 | let inp_type_clone = inp_type.clone(); |
| 189 | Effect::new(move || { |
| 190 | let value = pref_value.get(); |
| 191 | if !should_write.get_untracked() { |
| 192 | untrack(|| should_write.set(true)); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | tracing::debug!("Input type - {}", inp_type_clone); |
| 197 | if inp_type_clone.clone() == "number" { |
| 198 | save_selective_number(pref_key.clone(), value); |
| 199 | } else { |
| 200 | save_selective(pref_key.clone(), value); |
| 201 | } |
| 202 | }); |
| 203 | |
| 204 | let inp_type_clone = inp_type.clone(); |
| 205 | let debounced_update = use_debounce_fn_with_arg( |
| 206 | move |event: web_sys::Event| { |
| 207 | let value = event_target_value(&event); |
| 208 | if inp_type_clone.clone() == "number" && value.parse::<f64>().is_err() { |
| 209 | tracing::debug!("Invalid number"); |
| 210 | return; |
| 211 | } |
nothing calls this directly
no test coverage detected