feat(front+back): pwa added, register parkour update with it, and jeux added in coming soon
Some checks failed
Deploy to Development / build-and-deploy (push) Failing after 20s
Some checks failed
Deploy to Development / build-and-deploy (push) Failing after 20s
This commit is contained in:
@@ -68,8 +68,15 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
async function logout() {
|
||||
token.value = null
|
||||
user.value = null
|
||||
notifications.value = []
|
||||
unreadCount.value = 0
|
||||
localStorage.removeItem('token')
|
||||
delete axios.defaults.headers.common['Authorization']
|
||||
|
||||
// Arrêter le polling des notifications
|
||||
const notificationService = (await import('@/services/notificationService')).default
|
||||
notificationService.stopPolling()
|
||||
|
||||
router.push('/login')
|
||||
toast.info('Déconnexion réussie')
|
||||
}
|
||||
@@ -130,10 +137,36 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
try {
|
||||
const response = await axios.get('/api/notifications?limit=50')
|
||||
notifications.value = response.data
|
||||
unreadCount.value = notifications.value.filter(n => !n.is_read).length
|
||||
const newNotifications = response.data
|
||||
|
||||
// Détecter les nouvelles notifications non lues
|
||||
const previousIds = new Set(notifications.value.map(n => n.id))
|
||||
const previousUnreadIds = new Set(
|
||||
notifications.value.filter(n => !n.is_read).map(n => n.id)
|
||||
)
|
||||
|
||||
// Nouvelles notifications = celles qui n'existaient pas avant
|
||||
const hasNewNotifications = newNotifications.some(n => !previousIds.has(n.id))
|
||||
|
||||
// Nouvelles notifications non lues = nouvelles ET non lues
|
||||
const newUnreadNotifications = newNotifications.filter(
|
||||
n => !previousIds.has(n.id) && !n.is_read
|
||||
)
|
||||
|
||||
notifications.value = newNotifications
|
||||
const newUnreadCount = notifications.value.filter(n => !n.is_read).length
|
||||
const previousUnreadCount = unreadCount.value
|
||||
unreadCount.value = newUnreadCount
|
||||
|
||||
// Retourner si de nouvelles notifications non lues ont été détectées
|
||||
return {
|
||||
hasNewNotifications: newUnreadNotifications.length > 0,
|
||||
newCount: newUnreadCount,
|
||||
previousCount: previousUnreadCount
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching notifications:', error)
|
||||
return { hasNewNotifications: false, newCount: unreadCount.value, previousCount: unreadCount.value }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user