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.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
.catch(() => { } catch (err) {
this.$message({ this.$message({
message: this.$t('message.follow_error'), message: this.$t('message.follow_error'),
type: 'error' type: 'error'
}) })
}) } finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
unfollow (account) { unfollow (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
.catch(() => { } catch (err) {
this.$message({ this.$message({
message: this.$t('message.unfollow_error'), message: this.$t('message.unfollow_error'),
type: '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) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
.catch(() => { await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers)
} catch (err) {
this.$message({ this.$message({
message: this.$t('message.follow_error'), message: this.$t('message.follow_error'),
type: 'error' type: 'error'
}) })
}) } finally {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
async unfollowAccount (account) { async unfollowAccount (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
.catch(() => { await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers)
} catch (err) {
this.$message({ this.$message({
message: this.$t('message.unfollow_error'), message: this.$t('message.unfollow_error'),
type: 'error' type: 'error'
}) })
}) } finally {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchRelationships', this.followers) 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) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account) await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
.catch(() => { await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows)
} catch (err) {
this.$message({ this.$message({
message: this.$t('message.follow_error'), message: this.$t('message.follow_error'),
type: 'error' type: 'error'
}) })
}) } finally {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows) this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
}, },
async unfollowAccount (account) { async unfollowAccount (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account) await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
.catch(() => { await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows)
} catch (err) {
this.$message({ this.$message({
message: this.$t('message.unfollow_error'), message: this.$t('message.unfollow_error'),
type: 'error' type: 'error'
}) })
}) } finally {
await this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchRelationships', this.follows) 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)