Files
hnh-map/frontend-nuxt/composables/useRebuildZoomsInvalidation.ts
Nikolay Tatarinov 225aaa36e7 Enhance map functionality and API documentation
- Updated API documentation for the `rebuildZooms` endpoint to clarify its long execution time and response behavior.
- Modified MapView component to manage tile cache invalidation after rebuilding zoom levels, ensuring fresh tile display.
- Introduced a new composable for handling tile cache invalidation state after admin actions.
- Enhanced character icon creation to reflect ownership status with distinct colors.
- Improved loading state handling in various components for better user experience during data fetching.
2026-03-01 19:09:46 +03:00

31 lines
907 B
TypeScript

/**
* Shared state for tile cache invalidation after admin "Rebuild zooms".
* Admin sets the timestamp on success; MapView on mount clears tile caches
* when a rebuild was done recently, so the map shows fresh tiles even if
* SSE was missed (e.g. admin in another tab).
*/
const REBUILD_DONE_TTL_MS = 5 * 60 * 1000 // 5 minutes
export function useRebuildZoomsInvalidation() {
const rebuildZoomsDoneAt = useState('rebuildZoomsDoneAt', () => 0)
function markRebuildDone() {
rebuildZoomsDoneAt.value = Date.now()
}
function shouldInvalidateTileCache(): boolean {
if (rebuildZoomsDoneAt.value <= 0) return false
return Date.now() - rebuildZoomsDoneAt.value < REBUILD_DONE_TTL_MS
}
function clearRebuildDoneFlag() {
rebuildZoomsDoneAt.value = 0
}
return {
markRebuildDone,
shouldInvalidateTileCache,
clearRebuildDoneFlag,
}
}