MMMMMMMMMMMMMMMM types

This commit is contained in:
Zoe
2023-01-10 21:21:09 -06:00
parent 880d1bf375
commit cd76dfc147
21 changed files with 147 additions and 82 deletions

View File

@@ -1,21 +1,23 @@
import { IUser, IServer, IChannel } from "../types";
export const useGlobalStore = defineStore('global', {
state: () => ({
activeServer: {},
user: {}
activeServer: {} as IServer | Record<string, unknown>,
user: {} as IUser
}),
actions: {
setUser(user) {
setUser(user: IUser) {
this.user = user;
},
addServer(server) {
addServer(server: IServer) {
if (this.user.servers.find((e) => e.id === server.id)) return;
this.user.servers.push(server)
},
addDM(dmChannel) {
addDM(dmChannel: IChannel) {
if (this.user.channels.includes(dmChannel)) return;
this.user.channels.push(dmChannel)
},
setActive(type, serverId) {
setActive(type: string, serverId: string) {
if (serverId === '@me') {
this.activeServer = {}
return;
@@ -23,7 +25,10 @@ export const useGlobalStore = defineStore('global', {
type = (type === 'dm') ? 'channels' : 'servers'
this.activeServer = this["user"][type].find((e) => e.id === serverId)
if (type !== 'channels' && type !== 'servers') return;
const searchableArray: IChannel[] | IServer[] = this["user"][type]
this.activeServer = searchableArray.find((e: IServer | IChannel) => e.id === serverId)
},
},
})