forked from noxious/client
Refractor socket store into game store
This commit is contained in:
@ -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')
|
||||
}
|
||||
|
Reference in New Issue
Block a user