fix pargar mande

This commit is contained in:
2026-07-25 12:13:30 +03:30
parent 9319906737
commit 7cd3fac28b
20 changed files with 608 additions and 41 deletions
@@ -0,0 +1,61 @@
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { getAppNotificationsUnreadCount } from '@/api/appNotifications'
import { useSettingsStore } from '@/store/settingsStore'
import { isToken } from '@/utils'
const unreadCount = ref(0)
let pollTimer: ReturnType<typeof setInterval> | null = null
let started = false
async function refreshUnreadCount() {
const settingsStore = useSettingsStore()
if (!isToken() || !settingsStore.isSettingTruthy('has_page_notification')) {
unreadCount.value = 0
return
}
try {
const data = await getAppNotificationsUnreadCount()
unreadCount.value = Number(data?.unread_count ?? 0) || 0
} catch {
// silent — badge optional
}
}
function clearUnreadLocally() {
unreadCount.value = 0
}
export function useAppNotificationBadge() {
const settingsStore = useSettingsStore()
const enabled = computed(() => settingsStore.isSettingTruthy('has_page_notification'))
onMounted(() => {
if (started) {
void refreshUnreadCount()
return
}
started = true
void refreshUnreadCount()
pollTimer = setInterval(() => {
void refreshUnreadCount()
}, 60000)
})
onUnmounted(() => {
// keep poll for other mounted headers; only clear if needed later
})
watch(enabled, (on) => {
if (!on) unreadCount.value = 0
else void refreshUnreadCount()
})
return {
enabled,
unreadCount,
refreshUnreadCount,
clearUnreadLocally,
}
}
export { refreshUnreadCount, clearUnreadLocally }