Added GUI components

This commit is contained in:
2024-05-12 21:24:29 +02:00
parent 70d7371351
commit 36f38b4c94
8 changed files with 129 additions and 65 deletions

View File

@ -4,20 +4,18 @@
* https://runthatline.com/pinia-watch-state-getters-inside-vue-components/
* https://pinia.vuejs.org/
*/
import { defineStore } from 'pinia';
import {useZoneStore} from '@/stores/zone'
import { defineStore, type StoreDefinition } from 'pinia'
import { io, Socket } from 'socket.io-client';
import config from '@/config';
import axios from 'axios';
export const useSocketStore = defineStore('socket', {
export const useSocketStore: StoreDefinition<any> = defineStore('socket', {
state: () => ({
isAuthenticated: false,
socket: null as Socket | null,
}),
getters: {
auth: (state) => state.isAuthenticated,
sockett: (state) => state.socket,
auth: (state: any) => state.isAuthenticated,
},
actions: {
async register(username: string, password: string) {
@ -55,10 +53,6 @@ export const useSocketStore = defineStore('socket', {
transports: ['websocket']
});
this.socket.on('connect', () => {
console.log('Socket connected!');
});
this.socket.on('message', (message) => {
console.log('Received message:', message);
});
@ -69,6 +63,7 @@ export const useSocketStore = defineStore('socket', {
if (this.socket) {
this.socket.disconnect();
this.socket = null;
this.isAuthenticated = false;
}
},
}