1
0
forked from noxious/client

Refractor socket store into game store

This commit is contained in:
2024-07-12 11:58:06 +02:00
parent 6a1b2dd107
commit 79bef033f3
22 changed files with 161 additions and 170 deletions

View File

@ -11,12 +11,12 @@
<script setup lang="ts">
import { useNotificationStore } from '@/stores/notifications'
import { useSocketStore } from '@/stores/socket'
import { useGameStore } from '@/stores/game'
import Modal from '@/components/utilities/Modal.vue'
import { onBeforeMount, onBeforeUnmount, watch } from 'vue'
const notifications = useNotificationStore()
const socket = useSocketStore()
const gameStore = useGameStore()
function closeNotification(id: string) {
notifications.removeNotification(id)
@ -31,13 +31,13 @@ function setupNotificationListener(connection: any) {
}
onBeforeMount(() => {
const connection = socket.connection
const connection = gameStore.connection
if (connection) {
setupNotificationListener(connection)
} else {
// Watch for changes in the socket connection
watch(
() => socket.connection,
() => gameStore.connection,
(newConnection) => {
if (newConnection) setupNotificationListener(newConnection)
}
@ -46,7 +46,7 @@ onBeforeMount(() => {
})
onBeforeUnmount(() => {
const connection = socket.connection
const connection = gameStore.connection
if (connection) {
connection.off('notification')
}