Skip to content

Commit

Permalink
Fix for bug caught when paginating after token expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
watsonbox committed Feb 26, 2021
1 parent 50bb69e commit 09f9c50
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/components/PlaylistTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,29 @@ class PlaylistTable extends React.Component {
this.playlistSearch.current.clear()
}

const playlists = await this.playlistsData.slice(
((this.state.currentPage - 1) * this.PAGE_SIZE),
((this.state.currentPage - 1) * this.PAGE_SIZE) + this.PAGE_SIZE
).catch(apiCallErrorHandler)

// FIXME: Handle unmounting
this.setState(
{
initialized: true,
searching: false,
playlists: playlists,
playlistCount: await this.playlistsData.total()
},
() => {
const min = ((this.state.currentPage - 1) * this.PAGE_SIZE) + 1
const max = Math.min(min + this.PAGE_SIZE - 1, this.state.playlistCount)
this.setSubtitle(`${min}-${max} of ${this.state.playlistCount} playlists for ${this.userId}`)
}
)
try {
const playlists = await this.playlistsData.slice(
((this.state.currentPage - 1) * this.PAGE_SIZE),
((this.state.currentPage - 1) * this.PAGE_SIZE) + this.PAGE_SIZE
)

// FIXME: Handle unmounting
this.setState(
{
initialized: true,
searching: false,
playlists: playlists,
playlistCount: await this.playlistsData.total()
},
() => {
const min = ((this.state.currentPage - 1) * this.PAGE_SIZE) + 1
const max = Math.min(min + this.PAGE_SIZE - 1, this.state.playlistCount)
this.setSubtitle(`${min}-${max} of ${this.state.playlistCount} playlists for ${this.userId}`)
}
)
} catch(error) {
apiCallErrorHandler(error)
}
}

handlePlaylistsLoadingStarted = () => {
Expand Down

0 comments on commit 09f9c50

Please sign in to comment.