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,68 +26,97 @@ template $MusicusHomePage : Adw.NavigationPage {
} }
} }
Gtk.ScrolledWindow { Gtk.Stack stack {
hscrollbar-policy: never; Gtk.StackPage {
name: "results";
child: Gtk.ScrolledWindow {
hscrollbar-policy: never;
Adw.Clamp { Adw.Clamp {
maximum-size: 1000; maximum-size: 1000;
tightening-threshold: 600; tightening-threshold: 600;
Gtk.Box { Gtk.Box {
orientation: vertical; orientation: vertical;
margin-start: 12; margin-start: 12;
margin-end: 12; margin-end: 12;
margin-top: 24; margin-top: 24;
margin-bottom: 68; margin-bottom: 68;
Gtk.Label { Gtk.Label {
styles ["heading"] styles ["heading"]
visible: bind persons_flow_box.visible; visible: bind persons_flow_box.visible;
halign: start; halign: start;
label: _("Composers and performers"); 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; Gtk.StackPage {
margin-bottom: 24; name: "empty";
column-spacing: 12; child: Adw.StatusPage {
row-spacing: 12; icon-name: "system-search-symbolic";
homogeneous: true; title: _("Nothing Found");
selection-mode: none; description: _("Try a different search.");
} };
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;
}
}
} }
} }
} }

View file

@ -27,8 +27,12 @@ mod imp {
#[template_child] #[template_child]
pub search_entry: TemplateChild<MusicusSearchEntry>, pub search_entry: TemplateChild<MusicusSearchEntry>,
#[template_child] #[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub persons_flow_box: TemplateChild<gtk::FlowBox>, pub persons_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child] #[template_child]
pub ensembles_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child]
pub works_flow_box: TemplateChild<gtk::FlowBox>, pub works_flow_box: TemplateChild<gtk::FlowBox>,
#[template_child] #[template_child]
pub recordings_flow_box: TemplateChild<gtk::FlowBox>, pub recordings_flow_box: TemplateChild<gtk::FlowBox>,
@ -73,12 +77,6 @@ mod imp {
.build(); .build();
self.obj().query(&LibraryQuery::default()); 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) { fn query(&self, query: &LibraryQuery) {
let imp = self.imp();
let results = self.library().query(query); let results = self.library().query(query);
clear_flowbox(&self.imp().persons_flow_box); for flowbox in [
for person in results.persons { &imp.persons_flow_box,
self.imp() &imp.ensembles_flow_box,
.persons_flow_box &imp.works_flow_box,
.append(&MusicusTile::with_title(&person.name_fl())); &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: &gtk::FlowBox) {
while let Some(widget) = flowbox.first_child() {
flowbox.remove(&widget);
}
}