Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/client/src/store/user.ts

53 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-01-21 03:36:18 +13:00
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
import { Member } from '~/client/types'
export const namespaced = true
interface Members {
[id: string]: Member
}
export const state = () => ({
id: '',
members: {} as Members,
})
export const getters = getterTree(state, {
member: state => state.members[state.id] || null,
admin: state => (state.members[state.id] ? state.members[state.id].admin : false),
})
export const mutations = mutationTree(state, {
setMembers(state, members: Member[]) {
const data: Members = {}
for (const member of members) {
data[member.id] = member
}
state.members = data
},
setMember(state, id: string) {
state.id = id
},
addMember(state, member: Member) {
state.members = {
...state.members,
[member.id]: member,
}
},
delMember(state, id: string) {
const data = { ...state.members }
delete data[id]
state.members = data
},
clearMembers(state) {
state.members = {}
},
})
export const actions = actionTree(
{ state, getters, mutations },
{
//
},
)