Display all search results on home page

This commit is contained in:
Elias Projahn 2023-10-07 23:13:32 +02:00
parent ff3c3728ad
commit 9d4f37f601
2 changed files with 135 additions and 75 deletions

View file

@ -26,7 +26,10 @@ template $MusicusHomePage : Adw.NavigationPage {
}
}
Gtk.ScrolledWindow {
Gtk.Stack stack {
Gtk.StackPage {
name: "results";
child: Gtk.ScrolledWindow {
hscrollbar-policy: never;
Adw.Clamp {
@ -56,6 +59,22 @@ template $MusicusHomePage : Adw.NavigationPage {
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;
@ -89,6 +108,16 @@ template $MusicusHomePage : Adw.NavigationPage {
}
}
}
};
}
Gtk.StackPage {
name: "empty";
child: Adw.StatusPage {
icon-name: "system-search-symbolic";
title: _("Nothing Found");
description: _("Try a different search.");
};
}
}
}

View file

@ -27,8 +27,12 @@ mod imp {
#[template_child]
pub search_entry: TemplateChild<MusicusSearchEntry>,
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub persons_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub ensembles_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub works_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub recordings_flow_box: TemplateChild<gtk::FlowBox>,
@ -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()));
}
}
}
fn clear_flowbox(flowbox: &gtk::FlowBox) {
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"));
}
}
}
}