MCPcopy Create free account
hub / github.com/Moosync/Moosync / PathsPref

Function PathsPref

src/components/prefs/components.rs:52–150  ·  view source on GitHub ↗
(
    #[prop()] key: String,
    #[prop()] title: K,
    #[prop()] tooltip: K1,
    #[prop()] mobile: bool,
)

Source from the content-addressed store, hash-verified

50#[tracing::instrument(level = "debug", skip(key, title, tooltip))]
51#[component]
52pub fn PathsPref<K, H, K1, H1>(
53 #[prop()] key: String,
54 #[prop()] title: K,
55 #[prop()] tooltip: K1,
56 #[prop()] mobile: bool,
57) -> impl IntoView
58where
59 K: Fn() -> H + Send + Sync + 'static,
60 H: IntoView + Copy + 'static,
61 K1: Fn() -> H1 + Send + Sync + 'static,
62 H1: IntoView + Copy + 'static,
63{
64 let ui_store = expect_context::<RwSignal<UiStore>>();
65 let is_mobile = create_read_slice(ui_store, |u| u.get_is_mobile()).get();
66 if is_mobile && !mobile {
67 return ().into_any();
68 }
69
70 let should_write = RwSignal::new(false);
71 let paths: RwSignal<Vec<String>> = RwSignal::new(vec![]);
72 load_selective(key.clone(), paths.write_only());
73 let selected_paths = RwSignal::new(vec![]);
74 Effect::new(move || {
75 let new_paths = selected_paths.get();
76 tracing::debug!("Got new paths: {:?}", new_paths);
77 if !new_paths.is_empty() {
78 paths.update(|paths| paths.extend(new_paths.iter().cloned()));
79 }
80 });
81
82 let start_scan = move |_| {
83 spawn_local(async move {
84 let _ = crate::utils::invoke::start_scan(None).await;
85 })
86 };
87
88 let key_clone = key.clone();
89 Effect::new(move || {
90 let value = paths.get();
91 tracing::debug!("Should write {}, {:?}", should_write.get_untracked(), value);
92 if !should_write.get_untracked() {
93 untrack(|| should_write.set(true));
94 return;
95 }
96 tracing::debug!("Saving paths: {:?}", value);
97 save_selective(key_clone.clone(), value);
98 });
99 let i18n = use_i18n();
100 view! {
101 <div class="container-fluid mt-4">
102 <div class="row no-gutters align-items-center">
103 <div class="row no-gutters">
104 <div class="col-auto align-self-center title d-flex preference-title">
105 {title()}
106 </div>
107 <div class="col-auto ml-2">
108 <Tooltip>{tooltip()}</Tooltip>
109 </div>

Callers

nothing calls this directly

Calls 7

load_selectiveFunction · 0.85
start_scanFunction · 0.85
save_selectiveFunction · 0.85
getMethod · 0.80
get_is_mobileMethod · 0.80
cloneMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected