refs #657 Fix loading when fetch follows/followers in follow/followers tab

This commit is contained in:
AkiraFukushima 2018-10-16 01:09:09 +09:00
parent 4bf25eb6de
commit 943ee7bee1
4 changed files with 64 additions and 50 deletions

View File

@ -165,22 +165,30 @@ export default {
} }
}, },
follow (account) { follow (account) {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
message: this.$t('message.follow_error'), } catch (err) {
type: 'error' this.$message({
}) message: this.$t('message.follow_error'),
type: 'error'
}) })
} finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
unfollow (account) { unfollow (account) {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
message: this.$t('message.unfollow_error'), } catch (err) {
type: 'error' this.$message({
}) message: this.$t('message.unfollow_error'),
type: 'error'
}) })
} finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
changeTab (index) { changeTab (index) {
this.activeTab = index this.activeTab = index

View File

@ -52,24 +52,32 @@ export default {
return this.relationships.find(r => r.id === id) return this.relationships.find(r => r.id === id)
}, },
async followAccount (account) { async followAccount (account) {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
message: this.$t('message.follow_error'), await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers)
type: 'error' } catch (err) {
}) this.$message({
message: this.$t('message.follow_error'),
type: 'error'
}) })
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers) } finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
async unfollowAccount (account) { async unfollowAccount (account) {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
message: this.$t('message.unfollow_error'), await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers)
type: 'error' } catch (err) {
}) this.$message({
message: this.$t('message.unfollow_error'),
type: 'error'
}) })
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers) } finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
} }
} }
} }

View File

@ -52,24 +52,32 @@ export default {
return this.relationships.find(r => r.id === id) return this.relationships.find(r => r.id === id)
}, },
async followAccount (account) { async followAccount (account) {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
message: this.$t('message.follow_error'), await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows)
type: 'error' } catch (err) {
}) this.$message({
message: this.$t('message.follow_error'),
type: 'error'
}) })
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows) } finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
async unfollowAccount (account) { async unfollowAccount (account) {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
.catch(() => { try {
this.$message({ await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
message: this.$t('message.unfollow_error'), await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows)
type: 'error' } catch (err) {
}) this.$message({
message: this.$t('message.unfollow_error'),
type: 'error'
}) })
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows) } finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
} }
} }
} }

View File

@ -63,24 +63,17 @@ const AccountProfile = {
}) })
}, },
follow ({ state, commit, rootState }, account) { follow ({ state, commit, rootState }, account) {
commit('changeLoading', true)
const client = new Mastodon( const client = new Mastodon(
rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1' rootState.TimelineSpace.account.baseURL + '/api/v1'
) )
return client.post(`/accounts/${account.id}/follow`) return client.post(`/accounts/${account.id}/follow`)
.then(res => { .then(res => {
commit('changeLoading', false)
commit('changeRelationship', res.data) commit('changeRelationship', res.data)
return res.data return res.data
}) })
.catch(err => {
commit('changeLoading', false)
throw err
})
}, },
unfollow ({ commit, rootState }, account) { unfollow ({ commit, rootState }, account) {
commit('changeLoading', true)
const client = new Mastodon( const client = new Mastodon(
rootState.TimelineSpace.account.accessToken, rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1' rootState.TimelineSpace.account.baseURL + '/api/v1'
@ -90,9 +83,6 @@ const AccountProfile = {
commit('changeRelationship', res.data) commit('changeRelationship', res.data)
return res.data return res.data
}) })
.finally(() => {
commit('changeLoading', false)
})
}, },
close ({ commit }) { close ({ commit }) {
commit('changeAccount', null) commit('changeAccount', null)