Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #466 Catch raise when the response does not have link header of favourites #467

Merged
merged 1 commit into from
Jul 31, 2018
Merged
Changes from all commits
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
24 changes: 14 additions & 10 deletions src/renderer/store/TimelineSpace/Contents/Favourites.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,34 @@ const Favourites = {
}
},
actions: {
fetchFavourites ({ commit }, account) {
async fetchFavourites ({ commit }, account) {
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/favourites', { limit: 40 })
.then(res => {
commit('updateFavourites', res.data)
// Parse link header
const link = parse(res.headers.link)
commit('changeMaxId', link.next.max_id)
return res.data
})
const res = await client.get('/favourites', { limit: 40 })
commit('updateFavourites', res.data)
// Parse link header
try {
const link = parse(res.headers.link)
commit('changeMaxId', link.next.max_id)
} catch (err) {
console.error(err)
}
return res.data
},
lazyFetchFavourites ({ state, commit, rootState }) {
if (state.lazyLoading) {
return Promise.resolve(null)
}
if (!state.maxId) {
return null
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
console.log(state.maxId)
return client.get('/favourites', { max_id: state.maxId, limit: 40 })
.then(res => {
commit('changeLazyLoading', false)
Expand Down