1
0
forked from noxious/client

Removed duplicate component, worked on receiving notifications from server

This commit is contained in:
Dennis Postma 2024-06-02 01:54:35 +02:00
parent 9f00af14ad
commit 348b84e08b
2 changed files with 27 additions and 12 deletions

View File

@ -1,5 +1,4 @@
<template> <template>
<Notifications />
<div class="game-container"> <div class="game-container">
<div class="top-ui"> <div class="top-ui">
<Hud /> <Hud />

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="notifications"> <div class="notifications">
<Modal v-for="notification in notifications.getNotifications" :key="notification.id" :isModalOpen="true" @modal:close="closeNotification(notification.id)"> <Modal v-for="notification in notifications.getNotifications" :key="notification.id" :isModalOpen="true"
@modal:close="closeNotification(notification.id)">
<template #modal-body> <template #modal-body>
<p>{{ notification.message }}</p> <p>{{ notification.message }}</p>
</template> </template>
@ -12,17 +13,32 @@
import { useNotificationStore } from '@/stores/notifications' import { useNotificationStore } from '@/stores/notifications'
import { useSocketStore } from '@/stores/socket' import { useSocketStore } from '@/stores/socket'
import Modal from '@/components/utilities/Modal.vue' import Modal from '@/components/utilities/Modal.vue'
import { onMounted, watch } from 'vue'
const notifications = useNotificationStore(); const notifications = useNotificationStore()
const socket = useSocketStore(); const socket = useSocketStore()
if (socket.getConnection) {
socket.getConnection.on('notification', (data: any) => {
notifications.addNotification(data);
});
}
function closeNotification(id: string) { function closeNotification(id: string) {
notifications.removeNotification(id); notifications.removeNotification(id)
} }
function setupNotificationListener(connection: any) {
connection.on('notification', (data: { message: string }) => {
console.log(data)
notifications.addNotification(data)
})
}
onMounted(() => {
const connection = socket.getConnection
if (connection) {
setupNotificationListener(connection)
} else {
// Watch for changes in the socket connection
watch(() => socket.getConnection, (newConnection) => {
if (newConnection) setupNotificationListener(newConnection)
}
)
}
})
</script> </script>