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) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/follow', account)
.catch(() => {
} catch (err) {
this.$message({
message: this.$t('message.follow_error'),
type: 'error'
})
})
} finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
},
unfollow (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
this.$store.dispatch('TimelineSpace/Contents/SideBar/AccountProfile/unfollow', account)
.catch(() => {
} catch (err) {
this.$message({
message: this.$t('message.unfollow_error'),
type: 'error'
})
})
} finally {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', false)
}
},
changeTab (index) {
this.activeTab = index

View File

@ -52,24 +52,32 @@ export default {
return this.relationships.find(r => r.id === id)
},
async followAccount (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
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({
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) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
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({
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)
},
async followAccount (account) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
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({
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) {
this.$store.commit('TimelineSpace/Contents/SideBar/AccountProfile/changeLoading', true)
try {
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({
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) {
commit('changeLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/follow`)
.then(res => {
commit('changeLoading', false)
commit('changeRelationship', res.data)
return res.data
})
.catch(err => {
commit('changeLoading', false)
throw err
})
},
unfollow ({ commit, rootState }, account) {
commit('changeLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
@ -90,9 +83,6 @@ const AccountProfile = {
commit('changeRelationship', res.data)
return res.data
})
.finally(() => {
commit('changeLoading', false)
})
},
close ({ commit }) {
commit('changeAccount', null)