調整結算通知與全站防選字

This commit is contained in:
2026-04-19 12:54:18 +08:00
parent 896c24547b
commit ab3647587e
4 changed files with 294 additions and 56 deletions

View File

@@ -255,8 +255,15 @@ function App() {
}
}, [])
const resetScoring = (nextState: ScoreState = initialScoreState) => {
if (liveRoomSession?.status === 'live') {
const resetScoring = (
nextState: ScoreState = initialScoreState,
options?: {
releaseLiveRoom?: boolean
},
) => {
const shouldReleaseLiveRoom = options?.releaseLiveRoom ?? true
if (shouldReleaseLiveRoom && liveRoomSession?.status === 'live') {
void releaseLiveRoom(liveRoomSession.roomId, liveRoomSession.hostToken).catch(() => {})
}
@@ -275,6 +282,47 @@ function App() {
lastSyncedRoomSignatureRef.current = ''
}
const finalizeLiveRoom = async () => {
if (!liveRoomSession || !leftTeam || !rightTeam) {
return
}
const winnerTeamName = getWinnerName(
getTeamDisplayName(leftTeam),
getTeamDisplayName(rightTeam),
scoreState,
)
const payload = buildLiveRoomPayload({
groupId: selectedGroup?.id ?? null,
leftTeam,
pointLog,
rightTeam,
scoreState,
targetDate,
})
try {
await updateLiveRoom(liveRoomSession.roomId, {
...payload,
hostToken: liveRoomSession.hostToken,
status: 'finished',
winnerTeamName,
})
setLiveRoomSession((current) =>
current
? {
...current,
status: 'finished',
}
: current,
)
} catch (error) {
console.error('finalize live room error:', error)
}
}
const selectGroup = (groupId: number, nextGroups = groups) => {
const nextGroup = nextGroups.find((group) => group.id === groupId)
const firstTeam = nextGroup?.teams[0] ?? null
@@ -709,12 +757,14 @@ function App() {
}
const skipUpload = () => {
setSettlement({
error: '',
open: false,
uploading: false,
void finalizeLiveRoom().finally(() => {
setSettlement({
error: '',
open: false,
uploading: false,
})
resetScoring(initialScoreState, { releaseLiveRoom: false })
})
resetScoring()
}
const uploadSettledMatch = async () => {
@@ -756,12 +806,13 @@ function App() {
}
setHistory((current) => [historyItem, ...current])
await finalizeLiveRoom()
setSettlement({
error: '',
open: false,
uploading: false,
})
resetScoring()
resetScoring(initialScoreState, { releaseLiveRoom: false })
} catch (error) {
setSettlement({
error: error instanceof Error ? error.message : '上傳戰績失敗。',