Worked on commands, notifications
This commit is contained in:
19
src/stores/notifications.ts
Normal file
19
src/stores/notifications.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
});
|
@ -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;
|
||||
|
Reference in New Issue
Block a user