Fixed characters not showing after logging in, added loading screen before showing characters, worked on GM tools

This commit is contained in:
2024-06-10 02:39:00 +02:00
parent 2f7153fbfe
commit 3e003962dc
10 changed files with 85 additions and 26 deletions

View File

@ -6,17 +6,19 @@ import type { Character, User } from '@/types'
export const useSocketStore: StoreDefinition = defineStore('socket', {
state: () => ({
token: '' as string | null,
connection: null as Socket | null,
user: null as User | null,
character: null as Character | null
}),
getters: {
getToken: (state: any) => state.token as string,
getConnection: (state: any) => state.connection as Socket,
getUser: (state: any) => state.user as User,
getCharacter: (state: any) => state.character as Character
},
actions: {
setupSocketConnection() {
initConnection() {
this.connection = io(config.server_endpoint, {
withCredentials: true,
transports: ['websocket'],
@ -27,7 +29,7 @@ export const useSocketStore: StoreDefinition = defineStore('socket', {
this.connection.emit('login')
// set user
this.connection.on('login', (user: User) => {
this.connection.on('logged_in', (user: User) => {
this.setUser(user)
})
@ -43,11 +45,15 @@ export const useSocketStore: StoreDefinition = defineStore('socket', {
this.connection.disconnect()
this.connection = null
this.token = null
this.user = null
this.character = null
useCookies().remove('token')
},
setToken(token: string) {
this.token = token
},
setUser(user: User | null) {
this.user = user
},