調整結算通知與全站防選字
This commit is contained in:
67
src/App.tsx
67
src/App.tsx
@@ -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 : '上傳戰績失敗。',
|
||||
|
||||
Reference in New Issue
Block a user