Skip to content

Commit

Permalink
Adds a status page to Library.
Browse files Browse the repository at this point in the history
It is only shown when the user does not have any saved albums.
  • Loading branch information
Diegovsky committed Sep 21, 2021
1 parent f2bc8a5 commit 11a004e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/components/library/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::CompositeTemplate;
use std::rc::Rc;
use libadwaita::StatusPage;

use super::LibraryModel;
use crate::app::components::utils::wrap_flowbox_item;
Expand Down Expand Up @@ -91,6 +92,7 @@ impl LibraryWidget {

pub struct Library {
widget: LibraryWidget,
status_page_widget: libadwaita::StatusPage,
worker: Worker,
model: Rc<LibraryModel>,
}
Expand All @@ -107,6 +109,10 @@ impl Library {
widget,
worker,
model,
status_page_widget: libadwaita::StatusPageBuilder::new()
.title("You don't have any saved albums")
.description("Your saved albums will be shown here.")
.build(),
}
}

Expand Down Expand Up @@ -138,6 +144,12 @@ impl EventListener for Library {

impl Component for Library {
fn get_root_widget(&self) -> &gtk::Widget {
self.widget.as_ref()
if self.model.get_list_store().map(|store| store.len() == 0).unwrap_or(true) || true {
self.status_page_widget
.upcast_ref::<gtk::Widget>()
}
else {
self.widget.as_ref()
}
}
}

0 comments on commit 11a004e

Please sign in to comment.