Skip to content

Commit

Permalink
fix nav + review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xou816 committed Feb 17, 2023
1 parent 0c423f6 commit 793ce99
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/app/components/navigation/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ impl Navigation {
self.leaflet.navigate(NavigationDirection::Back);
}

fn pop_to_home(&self) {
fn pop_to_home(&mut self) {
self.leaflet.navigate(NavigationDirection::Forward);
self.model.go_home();
self.pop_to(&ScreenName::Home);
}

fn push_screen(&mut self, name: &ScreenName) {
Expand Down
5 changes: 0 additions & 5 deletions src/app/components/navigation/navigation_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ impl NavigationModel {
}
}

pub fn go_home(&self) {
self.dispatcher
.dispatch(BrowserAction::NavigationPopTo(ScreenName::Home).into())
}

pub fn visible_child_name(&self) -> impl Deref<Target = ScreenName> + '_ {
self.app_model.map_state(|s| s.browser.current_screen())
}
Expand Down
21 changes: 12 additions & 9 deletions src/app/components/sidebar/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ impl SidebarModel {
}

fn navigate(&self, dest: SidebarDestination) {
let action = match dest {
let actions = match dest {
SidebarDestination::Library
| SidebarDestination::SavedTracks
| SidebarDestination::NowPlaying
| SidebarDestination::SavedPlaylists => {
BrowserAction::SetHomeVisiblePage(dest.id()).into()
vec![BrowserAction::SetHomeVisiblePage(dest.id()).into()]
}
SidebarDestination::Playlist(PlaylistSummary { id, .. }) => AppAction::ViewPlaylist(id),
SidebarDestination::Playlist(PlaylistSummary { id, .. }) => vec![
BrowserAction::SetHomeVisiblePage(SidebarDestination::SavedPlaylists.id()).into(),
AppAction::ViewPlaylist(id),
],
};
self.dispatcher.dispatch(action);
self.dispatcher.dispatch_many(actions);
}
}

Expand All @@ -88,16 +91,16 @@ impl Sidebar {

let list_store = gio::ListStore::new(SidebarItem::static_type());

list_store.append(&SidebarItem::for_destination(SidebarDestination::Library));
list_store.append(&SidebarItem::for_destination(
list_store.append(&SidebarItem::from_destination(SidebarDestination::Library));
list_store.append(&SidebarItem::from_destination(
SidebarDestination::SavedTracks,
));
list_store.append(&SidebarItem::for_destination(
list_store.append(&SidebarItem::from_destination(
SidebarDestination::NowPlaying,
));
list_store.append(&SidebarItem::playlists_section());
list_store.append(&SidebarItem::create_playlist_item());
list_store.append(&SidebarItem::for_destination(
list_store.append(&SidebarItem::from_destination(
SidebarDestination::SavedPlaylists,
));

Expand Down Expand Up @@ -169,7 +172,7 @@ impl Sidebar {
.model
.get_playlists()
.into_iter()
.map(SidebarItem::for_destination)
.map(SidebarItem::from_destination)
.collect();
self.list_store.splice(
NUM_FIXED_ENTRIES,
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/sidebar/sidebar_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl SidebarDestination {
}

impl SidebarItem {
pub fn for_destination(dest: SidebarDestination) -> Self {
pub fn from_destination(dest: SidebarDestination) -> Self {
let (id, data, title) = match dest {
SidebarDestination::Playlist(PlaylistSummary { id, title }) => {
(PLAYLIST, Some(id), title)
Expand Down
7 changes: 7 additions & 0 deletions src/app/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::AppAction;

pub trait ActionDispatcher {
fn dispatch(&self, action: AppAction);
fn dispatch_many(&self, actions: Vec<AppAction>);
fn dispatch_local_async(&self, action: LocalBoxFuture<'static, Option<AppAction>>);
fn dispatch_async(&self, action: BoxFuture<'static, Option<AppAction>>);
fn dispatch_many_async(&self, actions: BoxFuture<'static, Vec<AppAction>>);
Expand All @@ -31,6 +32,12 @@ impl ActionDispatcher for ActionDispatcherImpl {
self.sender.unbounded_send(action).unwrap();
}

fn dispatch_many(&self, actions: Vec<AppAction>) {
for action in actions.into_iter() {
self.sender.unbounded_send(action).unwrap();
}
}

fn dispatch_local_async(&self, action: LocalBoxFuture<'static, Option<AppAction>>) {
let clone = self.sender.clone();
self.worker.send_local_task(async move {
Expand Down
21 changes: 12 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ fn register_actions(app: &gtk::Application, sender: UnboundedSender<AppAction>)
AppAction::BrowserAction(BrowserAction::NavigationPush(ScreenName::Search)),
sender.clone(),
));
let action = SimpleAction::new("open_playlist", Option::from(glib::VariantTy::STRING));
action.set_enabled(true);
action.connect_activate(move |_, playlist_id| {
// TODO: clean up unwraps
let id = playlist_id.unwrap().str().unwrap();
sender
.unbounded_send(AppAction::ViewPlaylist(String::from(id)))
.unwrap();

app.add_action(&{
let action = SimpleAction::new("open_playlist", Some(glib::VariantTy::STRING));
action.set_enabled(true);
action.connect_activate(move |_, playlist_id| {
if let Some(id) = playlist_id.and_then(|s| s.str()) {
sender
.unbounded_send(AppAction::ViewPlaylist(id.to_owned()))
.unwrap();
}
});
action
});
app.add_action(&action);
}

fn make_action(
Expand Down

0 comments on commit 793ce99

Please sign in to comment.