refactor: extract shared FightData interface to fight/types.ts
Move FightData, FightRound, FightBot, FightArenaInfo types from local definitions in FightViewer.vue to shared fight/types.ts. Replace `any` typing in HumanFightPage, FightPage, useFightPolling, and useFightCache with proper typed interfaces. Fix null-safety guards exposed by typing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
2f7c10e4b8
commit
945a776a5a
@@ -1,3 +1,5 @@
|
||||
import type { FightData } from '../game/fight/types'
|
||||
|
||||
const DB_NAME = 'botfights_cache'
|
||||
const STORE_NAME = 'fights'
|
||||
const MAX_CACHED = 5
|
||||
@@ -17,7 +19,7 @@ function openDB(): Promise<IDBDatabase> {
|
||||
}
|
||||
|
||||
/** Cache a fight replay for offline viewing */
|
||||
export async function cacheFight(fightData: { id: string; [key: string]: any }): Promise<void> {
|
||||
export async function cacheFight(fightData: FightData): Promise<void> {
|
||||
try {
|
||||
const db = await openDB()
|
||||
const tx = db.transaction(STORE_NAME, 'readwrite')
|
||||
@@ -50,7 +52,7 @@ export async function cacheFight(fightData: { id: string; [key: string]: any }):
|
||||
}
|
||||
|
||||
/** Get a cached fight by ID */
|
||||
export async function getCachedFight(id: string): Promise<any | null> {
|
||||
export async function getCachedFight(id: string): Promise<FightData | null> {
|
||||
try {
|
||||
const db = await openDB()
|
||||
return new Promise((resolve) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ref, type Ref } from 'vue'
|
||||
import type { FightData, FightBot, FightArenaInfo } from '../game/fight/types'
|
||||
|
||||
export interface LiveLogItem {
|
||||
type: string
|
||||
@@ -8,11 +9,12 @@ export interface LiveLogItem {
|
||||
}
|
||||
|
||||
export interface LiveFightData {
|
||||
botA: any
|
||||
botB: any
|
||||
botA: FightBot | null
|
||||
botB: FightBot | null
|
||||
arena: string
|
||||
arenaInfo?: { name: string }
|
||||
[key: string]: any
|
||||
arenaInfo?: FightArenaInfo | null
|
||||
mode?: string
|
||||
potSats?: number
|
||||
}
|
||||
|
||||
interface SSEListenerEntry {
|
||||
@@ -25,7 +27,7 @@ export function useFightPolling(fightId: Ref<string>) {
|
||||
const isLoading = ref(true)
|
||||
const liveRounds = ref(0)
|
||||
const fightError = ref('')
|
||||
const fight = ref<any>(null)
|
||||
const fight = ref<FightData | null>(null)
|
||||
const liveFightData = ref<LiveFightData | null>(null)
|
||||
const spectatorCount = ref(0)
|
||||
const currentChallengeInfo = ref<{ type: string; label: string } | null>(null)
|
||||
|
||||
Reference in New Issue
Block a user