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

Function AllPlaylists

src/pages/playlists.rs:177–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175#[tracing::instrument(level = "debug", skip())]
176#[component()]
177pub fn AllPlaylists() -> impl IntoView {
178 let playlists = RwSignal::new(vec![]);
179
180 let owner = Owner::new();
181 let refresh_playlist_items: Arc<Box<dyn Fn() + Send + Sync>> = Arc::new(Box::new(move || {
182 tracing::debug!("Refreshing playlists");
183 owner.with(|| {
184 get_playlists_by_option(QueryablePlaylist::default(), playlists.write_only());
185 });
186 }));
187
188 refresh_playlist_items.as_ref()();
189
190 let modal_manager = expect_context::<RwSignal<ModalStore>>();
191 let refresh_item_clone = refresh_playlist_items.clone();
192 let open_new_playlist_modal = move |_| {
193 modal_manager.update(|m| {
194 m.set_active_modal(Modals::NewPlaylistModal(PlaylistModalState::None, None));
195 let refresh_item_clone = refresh_item_clone.clone();
196 m.on_modal_close(move || {
197 refresh_item_clone.as_ref()();
198 });
199 });
200 };
201
202 let ui_store = expect_context::<RwSignal<UiStore>>();
203 let playlist_context_menu = create_context_menu(PlaylistContextMenu {
204 refresh_cb: refresh_playlist_items.clone(),
205 });
206
207 let playlist_sort = create_read_slice(ui_store, |u| u.get_playlist_sort_by());
208
209 let sorted_playlists = Memo::new(move |_| {
210 let mut playlists = playlists.get();
211 let sort = playlist_sort.get();
212 match sort.sort_by {
213 PlaylistSortByColumns::Title => {
214 playlists.sort_by(|a, b| a.playlist_name.cmp(&b.playlist_name))
215 }
216 PlaylistSortByColumns::Provider => {
217 playlists.sort_by(|a, b| a.extension.cmp(&b.extension))
218 }
219 }
220 playlists
221 });
222
223 let playlist_item_context_menu = create_context_menu(PlaylistItemContextMenu {
224 playlist: None,
225 refresh_cb: refresh_playlist_items,
226 });
227
228 let i18n = use_i18n();
229 view! {
230 <div class="w-100 h-100">
231 <div
232 on:contextmenu=move |ev| {
233 ev.prevent_default();
234 playlist_context_menu.show(ev);

Callers

nothing calls this directly

Calls 9

get_playlists_by_optionFunction · 0.85
NewPlaylistModalFunction · 0.85
create_context_menuFunction · 0.85
cloneMethod · 0.80
set_active_modalMethod · 0.80
on_modal_closeMethod · 0.80
get_playlist_sort_byMethod · 0.80
getMethod · 0.80
cmpMethod · 0.80

Tested by

no test coverage detected