Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for scrolling up/down when album list is active
  • Loading branch information
echoSayonara committed Nov 3, 2019
commit d6831d39a2e45ae6c740d9d7c915025a05b51974
39 changes: 39 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,4 +862,43 @@ impl App {
};
};
}

pub fn get_current_user_saved_albums(&mut self, offset: Option<u32>) {
if let Some(spotify) = &self.spotify {
match spotify.current_user_saved_albums(self.large_search_limit, offset) {
Ok(saved_albums) => {
// not to show a blank page
if saved_albums.items.len() > 0 {
self.library.saved_albums.add_pages(saved_albums);
}
}
Err(e) => {
self.handle_error(e);
}
}
}
}

pub fn get_current_user_saved_albums_next(&mut self) {
match self
.library
.saved_albums
.get_results(Some(self.library.saved_albums.index + 1))
.cloned()
{
Some(_) => self.library.saved_albums.index += 1,
None => {
if let Some(saved_albums) = &self.library.saved_albums.get_results(None) {
let offset = Some(saved_albums.offset + saved_albums.limit);
self.get_current_user_saved_albums(offset);
}
}
}
}

pub fn get_current_user_saved_albums_previous(&mut self) {
if self.library.saved_albums.index > 0 {
self.library.saved_albums.index -= 1;
}
}
}
2 changes: 2 additions & 0 deletions src/handlers/album_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub fn handler(key: Key, app: &mut App) {
};
}
}
Key::Ctrl('d') => app.get_current_user_saved_albums_next(),
Key::Ctrl('u') => app.get_current_user_saved_albums_previous(),
_ => {}
};
}
Expand Down
13 changes: 2 additions & 11 deletions src/handlers/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,8 @@ pub fn handler(key: Key, app: &mut App) {
}
// Albums,
3 => {
if let Some(spotify) = &app.spotify {
match spotify.current_user_saved_albums(app.large_search_limit, 0) {
Ok(result) => {
app.library.saved_albums.add_pages(result);
app.push_navigation_stack(RouteId::AlbumList, ActiveBlock::AlbumList);
}
Err(e) => {
app.handle_error(e);
}
}
};
app.get_current_user_saved_albums(Some(0));
app.push_navigation_stack(RouteId::AlbumList, ActiveBlock::AlbumList);
}
// Artists,
4 => {
Expand Down