feat(web): notification bell with polling and dropdown

This commit is contained in:
2026-04-29 10:33:53 +08:00
parent b7b9532a5a
commit 04a19dbcef
2 changed files with 99 additions and 2 deletions
+31
View File
@@ -0,0 +1,31 @@
import { onMounted, onUnmounted, ref } from 'vue'
import { notificationsApi } from '@/api/notifications'
import { useNotificationsStore } from '@/stores/notifications'
const POLL_INTERVAL_MS = 30_000
export function useUnreadPoller() {
const store = useNotificationsStore()
let timer: ReturnType<typeof setInterval> | null = null
const error = ref<string | null>(null)
async function refresh() {
try {
const { count } = await notificationsApi.unreadCount()
store.setUnreadCount(count)
} catch (e) {
error.value = String(e)
}
}
onMounted(() => {
refresh()
timer = setInterval(refresh, POLL_INTERVAL_MS)
})
onUnmounted(() => {
if (timer) clearInterval(timer)
})
return { refresh, error }
}