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
Added pagnation to user playlists
  • Loading branch information
Peterwmoss committed Nov 14, 2019
commit cfe0587f09dfd94d0380085bdecadc248493912a
6 changes: 4 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub struct App {
pub liked_song_ids_set: HashSet<String>,
pub large_search_limit: u32,
pub library: Library,
pub playlist_offset: u32,
pub playback_params: PlaybackParams,
pub playlist_tracks: Vec<PlaylistTrack>,
pub playlists: Option<Page<SimplifiedPlaylist>>,
Expand Down Expand Up @@ -269,6 +270,7 @@ impl App {
input: vec![],
input_idx: 0,
input_cursor_position: 0,
playlist_offset: 0,
playlist_tracks: vec![],
playlists: None,
search_results: SearchResult {
Expand Down Expand Up @@ -584,8 +586,8 @@ impl App {
&playlist_id,
None,
Some(self.large_search_limit),
None,
None,
Some(self.playlist_offset),
None
) {
self.set_playlist_tracks_to_table(&playlist_tracks);

Expand Down
1 change: 1 addition & 0 deletions src/handlers/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn handler(key: Key, app: &mut App) {
(&app.playlists, &app.selected_playlist_index)
{
app.track_table.context = Some(TrackTableContext::MyPlaylists);
app.playlist_offset = 0;
if let Some(selected_playlist) =
playlists.items.get(selected_playlist_index.to_owned())
{
Expand Down
27 changes: 25 additions & 2 deletions src/handlers/track_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ pub fn handler(key: Key, app: &mut App) {
Key::Ctrl('d') => {
match &app.track_table.context {
Some(context) => match context {
TrackTableContext::MyPlaylists => {}
TrackTableContext::MyPlaylists => {
if let (Some(playlists), Some(selected_playlist_index)) =
(&app.playlists, &app.selected_playlist_index)
{
if let Some(selected_playlist) = playlists.items.get(selected_playlist_index.to_owned())
{
app.playlist_offset += 20;
Comment thread
Peterwmoss marked this conversation as resolved.
Outdated
let playlist_id = selected_playlist.id.to_owned();
app.get_playlist_tracks(playlist_id);
}
};
}
TrackTableContext::SavedTracks => {
app.get_current_user_saved_tracks_next();
}
Expand All @@ -119,7 +130,19 @@ pub fn handler(key: Key, app: &mut App) {
Key::Ctrl('u') => {
match &app.track_table.context {
Some(context) => match context {
TrackTableContext::MyPlaylists => {}
TrackTableContext::MyPlaylists => {
if let (Some(playlists), Some(selected_playlist_index)) =
(&app.playlists, &app.selected_playlist_index)
{
if app.playlist_offset >= 20 { app.playlist_offset -= 20; } ;
if let Some(selected_playlist) =
playlists.items.get(selected_playlist_index.to_owned())
{
let playlist_id = selected_playlist.id.to_owned();
app.get_playlist_tracks(playlist_id);
}
};
}
TrackTableContext::SavedTracks => {
app.get_current_user_saved_tracks_previous();
}
Expand Down