feat: offline resilience and connection status

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 00:27:05 +00:00
co-authored by Claude Opus 4.6
parent 627a1a0d9e
commit 6e092ee7be
4 changed files with 131 additions and 1 deletions
+17 -1
View File
@@ -5,6 +5,7 @@ import FightViewer from '../components/FightViewer.vue'
import { useNostr } from '../composables/useNostr'
import { useFightPolling } from '../composables/useFightPolling'
import { useHumanChallenge } from '../composables/useHumanChallenge'
import { cacheFight, getCachedFight } from '../composables/useFightCache'
import { createFightScene, type FightSceneController } from '../game/FightScene'
import {
fanfareRound,
@@ -434,7 +435,22 @@ watch(liveFightData, async (val) => {
// --- Mount / Unmount ---
onMounted(async () => {
const status = await loadFight()
let status = await loadFight()
// If fetch failed (offline), try IndexedDB cache
if (status === null && fight.value === null) {
const cached = await getCachedFight(fightId.value)
if (cached) {
fight.value = cached
status = 'finished'
}
}
// Cache finished fights for offline replay
if (status === 'finished' && fight.value) {
cacheFight(fight.value).catch(() => {})
}
isLoading.value = false
if (status === null || status !== 'finished') {