refs #1035 Add reload method for account profile in sidebar

This commit is contained in:
AkiraFukushima 2019-09-15 23:12:49 +09:00
parent ac94f69ba0
commit ad7e93c72a
3 changed files with 22 additions and 2 deletions

View File

@ -3,7 +3,7 @@
<div id="side_bar" v-if="openSideBar" v-shortkey="shortcutEnabled ? { close: ['esc'] } : {}" @shortkey="handleKey">
<div class="header">
<i class="el-icon-loading" v-show="loading"></i>
<i class="el-icon-refresh" @click="refresh"></i>
<i class="el-icon-refresh" @click="reload"></i>
<i class="el-icon-close" @click="close"></i>
</div>
<div id="sidebar_scrollable">
@ -64,7 +64,9 @@ export default {
changeLoading(value) {
this.loading = value
},
refresh() {},
reload() {
this.$store.dispatch('TimelineSpace/Contents/SideBar/reload')
},
handleKey(event) {
switch (event.srcKey) {
case 'close':

View File

@ -46,6 +46,13 @@ const actions: ActionTree<SideBarState, RootState> = {
commit(MUTATION_TYPES.CHANGE_OPEN_SIDEBAR, false)
commit(MUTATION_TYPES.CHANGE_COMPONENT, Component.Blank)
},
reload: ({ state, dispatch }) => {
if (state.component === Component.AccountProfile) {
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/reload', {}, { root: true })
} else if (state.component === Component.TootDetail) {
dispatch('TimelineSpace/Contents/SideBar/TootDetail/reload', {}, { root: true })
}
},
openAccountComponent: ({ commit }) => {
commit(MUTATION_TYPES.CHANGE_COMPONENT, Component.AccountProfile)
},

View File

@ -74,6 +74,17 @@ const actions: ActionTree<AccountProfileState, RootState> = {
commit(MUTATION_TYPES.CHANGE_RELATIONSHIP, res.data[0])
return res.data
},
reload: async ({ dispatch, state, commit }) => {
commit(MUTATION_TYPES.CHANGE_LOADING, true)
Promise.all([
dispatch('fetchRelationship', state.account),
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Timeline/fetchTimeline', state.account, { root: true }),
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Followers/fetchFollowers', state.account, { root: true }),
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/Follows/fetchFollows', state.account, { root: true })
]).finally(() => {
commit(MUTATION_TYPES.CHANGE_LOADING, false)
})
},
follow: async ({ commit, rootState, dispatch }, account: Account) => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${account.id}/follow`)