diff --git a/app/races/[race]/race-view.tsx b/app/races/[race]/race-view.tsx index 0abfa565..f18bae4a 100644 --- a/app/races/[race]/race-view.tsx +++ b/app/races/[race]/race-view.tsx @@ -44,10 +44,22 @@ export const RaceDetail = ({ race, user, messages }: RaceDetailProps) => { { content: race.raceId }, ]; + const hasManyParticipants = race.participants?.filter( + (participant) => !!participant.liveData, + ); + const participantHasManySplits = race.participants?.find( + (participant) => + participant.liveData && participant.liveData.totalSplits > 200, + ); + + const shouldSkipFetching = hasManyParticipants && participantHasManySplits; + useEffect(() => { const fetchRaceMessages = async () => { - const res = await getRaceMessages(race.raceId); - setMessagesState(res); + if (!shouldSkipFetching) { + const res = await getRaceMessages(race.raceId); + setMessagesState(res); + } }; fetchRaceMessages(); diff --git a/app/races/[race]/sort-race-participants.ts b/app/races/[race]/sort-race-participants.ts index 40630af2..b72d008f 100644 --- a/app/races/[race]/sort-race-participants.ts +++ b/app/races/[race]/sort-race-participants.ts @@ -33,6 +33,37 @@ export const sortRaceParticipants = ( if (a.liveData || b.liveData) { if (!a.liveData) return 1; if (!b.liveData) return -1; + + if (race.startTime) { + if ( + a.liveData.startedAt < + new Date(race.startTime).getTime() - 1000 * 60 + ) { + return 1; + } + if ( + b.liveData.startedAt < + new Date(race.startTime).getTime() - 1000 * 60 + ) { + return -1; + } + } + + if (race.category.includes("602")) { + if ( + a.liveData.totalSplits < 400 && + b.liveData.totalSplits < 400 + ) { + return a.user < b.user ? -1 : 1; + } + if (a.liveData.totalSplits < 400) { + return 1; + } + if (b.liveData.totalSplits < 400) { + return -1; + } + } + // Both have liveData, compare their percentages const aPercentage = ( a.liveData.runPercentageTime && diff --git a/src/components/use-speedrun-timer.tsx b/src/components/use-speedrun-timer.tsx index 25ff7069..95ce9ae2 100644 --- a/src/components/use-speedrun-timer.tsx +++ b/src/components/use-speedrun-timer.tsx @@ -9,10 +9,12 @@ export const useSpeedrunTimer = (initialOffset = 0, autoStart = false) => { stopwatchInitialOffset.getSeconds() + Math.abs(initialOffset), ); - const { hours, minutes, seconds, start, pause, reset } = useStopwatch({ - autoStart, - offsetTimestamp: stopwatchInitialOffset, - }); + const { days, hours, minutes, seconds, start, pause, reset } = useStopwatch( + { + autoStart, + offsetTimestamp: stopwatchInitialOffset, + }, + ); const formatHours = (value: number): string => { if (value === 0) return ""; @@ -48,7 +50,7 @@ export const useSpeedrunTimer = (initialOffset = 0, autoStart = false) => { const render = () => { return ( - {formatHours(hours)} + {formatHours(hours + days * 24)} {formatMinutes(minutes)} {formatSeconds(seconds)} diff --git a/src/lib/races.ts b/src/lib/races.ts index 1e0fc9f3..dcf3ec02 100644 --- a/src/lib/races.ts +++ b/src/lib/races.ts @@ -178,7 +178,7 @@ export const getRaceMessages = async ( let url = `${racesApiUrl}/${raceId}/messages`; if (initialCall) { - url += "?limit=20"; + url += "?limit=50"; } const messages = await fetch(url, { next: { revalidate: 0 } });