Added sockets for notifications

This commit is contained in:
2026-06-30 20:49:36 +10:00
parent e551e202d5
commit 6cadd3d9e6
25 changed files with 1639 additions and 193 deletions
+33
View File
@@ -0,0 +1,33 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { Notification } from '@/Types/types';
import axios from 'axios';
export const useNotificationStore = defineStore('notifications', () => {
const toasts = ref<Notification[]>([]);
const unreadCount = ref(0);
const latestNotification = ref<Notification | null>(null);
const achievementSound = new Audio('/sounds/seatBelt.wav');
function push(notification: Notification) {
toasts.value.push(notification);
latestNotification.value = notification;
unreadCount.value++;
if (notification.is_achievement) {
achievementSound.play().catch(() => {});
}
}
async function dismiss(notification: Notification) {
toasts.value = toasts.value.filter(n => n.id !== notification.id);
await axios.patch(`/notifications/${notification.id}/read`);
unreadCount.value = Math.max(0, unreadCount.value - 1);
}
function setInitialUnreadCount(count: number) {
unreadCount.value = count;
}
return { toasts, unreadCount, latestNotification, push, dismiss, setInitialUnreadCount};
});