Skip to content

Commit

Permalink
Merge branch 'main' into feature/wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
therungg authored Jan 10, 2025
2 parents 7f67de6 + f267ad4 commit 4d6063e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
16 changes: 14 additions & 2 deletions app/races/[race]/race-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 31 additions & 0 deletions app/races/[race]/sort-race-participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
12 changes: 7 additions & 5 deletions src/components/use-speedrun-timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -48,7 +50,7 @@ export const useSpeedrunTimer = (initialOffset = 0, autoStart = false) => {
const render = () => {
return (
<span suppressHydrationWarning={true}>
{formatHours(hours)}
{formatHours(hours + days * 24)}
{formatMinutes(minutes)}
{formatSeconds(seconds)}
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/races.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand Down

0 comments on commit 4d6063e

Please sign in to comment.