2019-04-11 16:38:46 +02:00
|
|
|
import AccountProfile, { AccountProfileModuleState } from './SideBar/AccountProfile'
|
2019-04-11 16:14:42 +02:00
|
|
|
import TootDetail, { TootDetailState } from './SideBar/TootDetail'
|
2019-04-11 15:54:23 +02:00
|
|
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
|
|
|
import { RootState } from '@/store'
|
|
|
|
|
2019-09-15 15:46:48 +02:00
|
|
|
enum Component {
|
|
|
|
Blank,
|
|
|
|
AccountProfile,
|
|
|
|
TootDetail
|
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type SideBarState = {
|
|
|
|
openSideBar: boolean
|
2019-09-15 15:46:48 +02:00
|
|
|
component: Component
|
2019-04-11 15:54:23 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
type SideBarModule = {
|
|
|
|
TootDetail: TootDetailState
|
2019-04-11 16:38:46 +02:00
|
|
|
AccountProfile: AccountProfileModuleState
|
2019-04-11 15:54:23 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type SideBarModuleState = SideBarModule & SideBarState
|
|
|
|
|
2019-04-11 15:54:23 +02:00
|
|
|
const state = (): SideBarState => ({
|
|
|
|
openSideBar: false,
|
2019-09-15 15:46:48 +02:00
|
|
|
component: Component.Blank
|
2019-04-11 15:54:23 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
CHANGE_OPEN_SIDEBAR: 'changeOpenSideBar',
|
|
|
|
CHANGE_COMPONENT: 'changeComponent'
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<SideBarState> = {
|
|
|
|
[MUTATION_TYPES.CHANGE_OPEN_SIDEBAR]: (state, value: boolean) => {
|
|
|
|
state.openSideBar = value
|
|
|
|
},
|
2019-09-15 15:46:48 +02:00
|
|
|
[MUTATION_TYPES.CHANGE_COMPONENT]: (state, value: Component) => {
|
2019-04-11 15:54:23 +02:00
|
|
|
state.component = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions: ActionTree<SideBarState, RootState> = {
|
|
|
|
close: ({ dispatch, commit }) => {
|
|
|
|
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/close', {}, { root: true })
|
|
|
|
commit(MUTATION_TYPES.CHANGE_OPEN_SIDEBAR, false)
|
2019-09-15 15:46:48 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_COMPONENT, Component.Blank)
|
2019-04-11 15:54:23 +02:00
|
|
|
},
|
2019-09-15 16:12:49 +02:00
|
|
|
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 })
|
|
|
|
}
|
|
|
|
},
|
2019-04-11 15:54:23 +02:00
|
|
|
openAccountComponent: ({ commit }) => {
|
2019-09-15 15:46:48 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_COMPONENT, Component.AccountProfile)
|
2019-04-11 15:54:23 +02:00
|
|
|
},
|
|
|
|
openTootComponent: ({ commit }) => {
|
2019-09-15 15:46:48 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_COMPONENT, Component.TootDetail)
|
2019-04-11 15:54:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SideBar: Module<SideBarState, RootState> = {
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
AccountProfile,
|
|
|
|
TootDetail
|
|
|
|
},
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
actions: actions
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SideBar
|