refs #167 Fetch user's lists

This commit is contained in:
AkiraFukushima 2018-04-08 22:09:28 +09:00
parent c79f5a0c5c
commit 99eac1d958
2 changed files with 49 additions and 28 deletions

View File

@ -50,37 +50,36 @@ export default {
await this.clear()
this.$store.dispatch('TimelineSpace/watchShortcutEvents')
try {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id)
try {
await this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
} catch (err) {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
}
try {
await this.$store.dispatch('TimelineSpace/fetchNotifications', account)
} catch (err) {
this.$message({
message: 'Could not fetch notification',
type: 'error'
})
}
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: 'Failed to start streaming',
type: 'error'
})
})
} catch (err) {
const account = await this.$store.dispatch('TimelineSpace/localAccount', this.$route.params.id).catch(() => {
this.$message({
message: 'Could not find account',
type: 'error'
})
})
try {
await this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
} catch (err) {
this.$message({
message: 'Could not fetch timeline',
type: 'error'
})
}
try {
await this.$store.dispatch('TimelineSpace/fetchNotifications', account)
} catch (err) {
this.$message({
message: 'Could not fetch notification',
type: 'error'
})
}
this.$store.dispatch('TimelineSpace/SideMenu/fetchLists', account)
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
.catch(() => {
this.$message({
message: 'Failed to start streaming',
type: 'error'
})
})
}
}
}

View File

@ -1,8 +1,11 @@
import Mastodon from 'mastodon-api'
const SideMenu = {
namespaced: true,
state: {
unreadHomeTimeline: false,
unreadNotifications: false
unreadNotifications: false,
lists: []
},
mutations: {
changeUnreadHomeTimeline (state, value) {
@ -10,9 +13,28 @@ const SideMenu = {
},
changeUnreadNotifications (state, value) {
state.unreadNotifications = value
},
updateLists (state, lists) {
state.lists = lists
}
},
actions: {}
actions: {
fetchLists ({ commit }, account) {
return new Promise((resolve, reject) => {
const client = new Mastodon(
{
access_token: account.accessToken,
api_url: account.baseURL + '/api/v1'
}
)
client.get('/lists', {}, (err, data, res) => {
if (err) return reject(err)
commit('updateLists', data)
resolve(res)
})
})
}
}
}
export default SideMenu