Worked on commands, notifications

This commit is contained in:
2024-06-01 19:36:27 +02:00
parent b58df15ae0
commit ef12c61ea9
16 changed files with 136 additions and 76 deletions

View File

@ -0,0 +1,19 @@
import { defineStore, type StoreDefinition } from 'pinia'
import type { Notification } from '@/types'
export const useNotificationStore: StoreDefinition = defineStore('notifications', {
state: () => ({
notifications: [] as Notification[]
}),
getters: {
getNotifications: (state: any) => state.notifications
},
actions: {
addNotification(notification: Notification) {
this.notifications.push(notification);
},
removeNotification(index: number) {
this.notifications.splice(index, 1);
}
}
});

View File

@ -2,9 +2,10 @@ import { defineStore, type StoreDefinition } from 'pinia'
import { io, Socket } from 'socket.io-client';
import {useCookies} from '@vueuse/integrations/useCookies'
import config from '@/config';
import type { Character, User } from '../../env'
import type { Character, User } from '@/types'
import { useNotificationStore } from '@/stores/notifications'
export const useSocketStore: StoreDefinition<any> = defineStore('socket', {
export const useSocketStore: StoreDefinition = defineStore('socket', {
state: () => ({
connection: null as Socket | null,
user: null as User | null,
@ -36,12 +37,6 @@ export const useSocketStore: StoreDefinition<any> = defineStore('socket', {
console.log("Reconnect failed")
this.disconnectSocket();
})
this.connection.on('notification', (data: any) => {
if(data.error) console.error(data.error);
if (data.success) console.log(data.success);
if (data.message) console.log(data.message);
});
},
disconnectSocket() {
if (!this.connection) return;