Fix voting start time race condition
Set votingStartAt to 1 minute in the past when opening/reopening rounds or awards. This ensures voting is immediately available without the "opens in less than a minute" message appearing due to timing differences between when the date is set and when the page renders. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -268,7 +268,9 @@ export const roundRouter = router({
|
||||
|
||||
if (input.status === 'ACTIVE' && previousRound.status !== 'ACTIVE') {
|
||||
if (previousRound.votingStartAt && previousRound.votingStartAt > now) {
|
||||
updateData.votingStartAt = now
|
||||
// Set to 1 minute in the past to ensure voting is immediately open
|
||||
const oneMinuteAgo = new Date(now.getTime() - 60 * 1000)
|
||||
updateData.votingStartAt = oneMinuteAgo
|
||||
votingStartAtUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +207,11 @@ export const specialAwardRouter = router({
|
||||
}
|
||||
|
||||
if (input.status === 'VOTING_OPEN' && current.status !== 'VOTING_OPEN') {
|
||||
// If no voting start date, or if it's in the future, set it to now
|
||||
// If no voting start date, or if it's in the future, set it to 1 minute ago
|
||||
// to ensure voting is immediately open (avoids race condition with page render)
|
||||
if (!current.votingStartAt || current.votingStartAt > now) {
|
||||
updateData.votingStartAt = now
|
||||
const oneMinuteAgo = new Date(now.getTime() - 60 * 1000)
|
||||
updateData.votingStartAt = oneMinuteAgo
|
||||
votingStartAtUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user