From 9d4f37f6013a1b7e81ecb722ac2f0dfa99af26b0 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sat, 7 Oct 2023 23:13:32 +0200 Subject: [PATCH] Display all search results on home page --- data/ui/home_page.blp | 145 +++++++++++++++++++++++++----------------- src/home_page.rs | 65 ++++++++++++++----- 2 files changed, 135 insertions(+), 75 deletions(-) diff --git a/data/ui/home_page.blp b/data/ui/home_page.blp index 48aafe0..1c19312 100644 --- a/data/ui/home_page.blp +++ b/data/ui/home_page.blp @@ -26,68 +26,97 @@ template $MusicusHomePage : Adw.NavigationPage { } } - Gtk.ScrolledWindow { - hscrollbar-policy: never; + Gtk.Stack stack { + Gtk.StackPage { + name: "results"; + child: Gtk.ScrolledWindow { + hscrollbar-policy: never; - Adw.Clamp { - maximum-size: 1000; - tightening-threshold: 600; + Adw.Clamp { + maximum-size: 1000; + tightening-threshold: 600; - Gtk.Box { - orientation: vertical; - margin-start: 12; - margin-end: 12; - margin-top: 24; - margin-bottom: 68; + Gtk.Box { + orientation: vertical; + margin-start: 12; + margin-end: 12; + margin-top: 24; + margin-bottom: 68; - Gtk.Label { - styles ["heading"] - visible: bind persons_flow_box.visible; - halign: start; - label: _("Composers and performers"); + Gtk.Label { + styles ["heading"] + visible: bind persons_flow_box.visible; + halign: start; + label: _("Composers and performers"); + } + + Gtk.FlowBox persons_flow_box { + margin-top: 12; + margin-bottom: 24; + column-spacing: 12; + row-spacing: 12; + homogeneous: true; + selection-mode: none; + } + + Gtk.Label { + styles ["heading"] + visible: bind ensembles_flow_box.visible; + halign: start; + label: _("Ensembles"); + } + + Gtk.FlowBox ensembles_flow_box { + margin-top: 12; + margin-bottom: 24; + column-spacing: 12; + row-spacing: 12; + homogeneous: true; + selection-mode: none; + } + + Gtk.Label { + styles ["heading"] + visible: bind works_flow_box.visible; + halign: start; + label: _("Works"); + } + + Gtk.FlowBox works_flow_box { + margin-top: 12; + margin-bottom: 24; + column-spacing: 12; + row-spacing: 12; + homogeneous: true; + selection-mode: none; + } + + Gtk.Label { + styles ["heading"] + visible: bind recordings_flow_box.visible; + halign: start; + label: _("Recordings"); + } + + Gtk.FlowBox recordings_flow_box { + margin-top: 12; + margin-bottom: 24; + column-spacing: 12; + row-spacing: 12; + homogeneous: true; + selection-mode: none; + } + } } - - Gtk.FlowBox persons_flow_box { - margin-top: 12; - margin-bottom: 24; - column-spacing: 12; - row-spacing: 12; - homogeneous: true; - selection-mode: none; - } - - Gtk.Label { - styles ["heading"] - visible: bind works_flow_box.visible; - halign: start; - label: _("Works"); - } - - Gtk.FlowBox works_flow_box { - margin-top: 12; - margin-bottom: 24; - column-spacing: 12; - row-spacing: 12; - homogeneous: true; - selection-mode: none; - } - - Gtk.Label { - styles ["heading"] - visible: bind recordings_flow_box.visible; - halign: start; - label: _("Recordings"); - } - - Gtk.FlowBox recordings_flow_box { - margin-top: 12; - margin-bottom: 24; - column-spacing: 12; - row-spacing: 12; - homogeneous: true; - selection-mode: none; - } - } + }; + } + Gtk.StackPage { + name: "empty"; + child: Adw.StatusPage { + icon-name: "system-search-symbolic"; + title: _("Nothing Found"); + description: _("Try a different search."); + }; } } } diff --git a/src/home_page.rs b/src/home_page.rs index fde4273..02d05d2 100644 --- a/src/home_page.rs +++ b/src/home_page.rs @@ -27,8 +27,12 @@ mod imp { #[template_child] pub search_entry: TemplateChild, #[template_child] + pub stack: TemplateChild, + #[template_child] pub persons_flow_box: TemplateChild, #[template_child] + pub ensembles_flow_box: TemplateChild, + #[template_child] pub works_flow_box: TemplateChild, #[template_child] pub recordings_flow_box: TemplateChild, @@ -73,12 +77,6 @@ mod imp { .build(); self.obj().query(&LibraryQuery::default()); - - for _ in 0..9 { - self.works_flow_box.append(&MusicusTile::with_title("Test")); - self.recordings_flow_box - .append(&MusicusTile::with_title("Test")); - } } } @@ -112,19 +110,52 @@ impl MusicusHomePage { } fn query(&self, query: &LibraryQuery) { + let imp = self.imp(); let results = self.library().query(query); - clear_flowbox(&self.imp().persons_flow_box); - for person in results.persons { - self.imp() - .persons_flow_box - .append(&MusicusTile::with_title(&person.name_fl())); + for flowbox in [ + &imp.persons_flow_box, + &imp.ensembles_flow_box, + &imp.works_flow_box, + &imp.recordings_flow_box, + ] { + while let Some(widget) = flowbox.first_child() { + flowbox.remove(&widget); + } + } + + if results.is_empty() { + imp.stack.set_visible_child_name("empty"); + } else { + imp.stack.set_visible_child_name("results"); + + imp.persons_flow_box + .set_visible(!results.persons.is_empty()); + imp.ensembles_flow_box + .set_visible(!results.ensembles.is_empty()); + imp.works_flow_box.set_visible(!results.works.is_empty()); + imp.recordings_flow_box + .set_visible(!results.recordings.is_empty()); + + for person in results.persons { + imp.persons_flow_box + .append(&MusicusTile::with_title(&person.name_fl())); + } + + for ensemble in results.ensembles { + imp.ensembles_flow_box + .append(&MusicusTile::with_title(&ensemble.name)); + } + + for work in results.works { + imp.works_flow_box + .append(&MusicusTile::with_subtitle(&work.title, &work.composer.name_fl())); + } + + for _recording in results.recordings { + imp.recordings_flow_box + .append(&MusicusTile::with_title("TODO")); + } } } } - -fn clear_flowbox(flowbox: >k::FlowBox) { - while let Some(widget) = flowbox.first_child() { - flowbox.remove(&widget); - } -}