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

Function TopBar

src/components/topbar.rs:412–549  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

410#[tracing::instrument(level = "debug", skip())]
411#[component]
412pub fn TopBar() -> impl IntoView {
413 let show_searchbar = RwSignal::new(false);
414 let input_value = RwSignal::new("".to_string());
415 let results = RwSignal::new(vec![]);
416 let handle_input_focus = move |focus: InputFocus| match focus {
417 InputFocus::Focus => {
418 show_searchbar.set(!results.get().is_empty());
419 }
420 InputFocus::Blur => show_searchbar.set(false),
421 };
422
423 Effect::new(move || {
424 let results = results.get();
425 if !results.is_empty() {
426 show_searchbar.set(true);
427 }
428 });
429
430 let navigate = leptos_router::hooks::use_navigate();
431 let handle_page_change = move |ev: SubmitEvent| {
432 ev.prevent_default();
433 let text = input_value.get();
434 navigate(
435 format!("/main/search?q={}", text).as_str(),
436 Default::default(),
437 );
438 };
439
440 let player_store = expect_context::<RwSignal<PlayerStore>>();
441 let play_now = create_write_slice(player_store, |p, val| p.play_now(val));
442
443 let handle_text_change = move |ev: Event| {
444 let text = event_target_value(&ev);
445 input_value.set(text.clone());
446 if text.is_empty() {
447 return;
448 }
449 let value = format!("%{}%", text);
450 let current_page = window().location().pathname().unwrap();
451 tracing::debug!("current page {}", current_page);
452
453 spawn_local(async move {
454 let search_res = get_search_res(value.clone(), current_page, play_now).await;
455 match search_res {
456 Ok(res) => {
457 results.set(res);
458 }
459 Err(e) => tracing::error!("Failed to search {}: {:?}", value, e),
460 }
461 });
462
463 //
464 };
465
466 let ui_store = expect_context::<RwSignal<UiStore>>();
467 let is_mobile = create_read_slice(ui_store, |u| u.get_is_mobile()).get();
468
469 let i18n = use_i18n();

Callers

nothing calls this directly

Calls 6

get_search_resFunction · 0.85
setMethod · 0.80
getMethod · 0.80
cloneMethod · 0.80
get_is_mobileMethod · 0.80
play_nowMethod · 0.45

Tested by

no test coverage detected