Skip to content

Commit 79c8b39

Browse files
committed
refactor: clarify hackathon countdown fallback logic
1 parent 236fee5 commit 79c8b39

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

components/Activity/Hackathon/utility.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type TextLike = TableCellValue | NamedLike | null | undefined;
3838
type TextListLike = TextLike | TextLike[];
3939

4040
const textOf = (value: TextLike) => {
41-
if (!value) return '';
41+
if (value === null || value === undefined) return '';
4242

4343
if (typeof value === 'object' && !Array.isArray(value)) {
4444
const {
@@ -140,13 +140,15 @@ export const resolveCountdownState = <T extends CountdownWindow>(
140140
return Number.isFinite(started) && Number.isFinite(ended) && referenceTime <= ended;
141141
});
142142
const nextStartedAt = timeOf(nextItem?.startedAt);
143+
const nextCountdownTarget =
144+
Number.isFinite(nextStartedAt) && nextStartedAt > referenceTime
145+
? nextItem?.startedAt
146+
: nextItem?.endedAt;
147+
const fallbackCountdownTarget = timeOf(startTime) > referenceTime ? startTime : endTime;
143148
const countdownTo =
144-
(Number.isFinite(nextStartedAt) && nextStartedAt > referenceTime
145-
? (nextItem?.startedAt as string | undefined)
146-
: (nextItem?.endedAt as string | undefined)) ||
147-
(timeOf(startTime) > referenceTime
148-
? (startTime as string | undefined)
149-
: (endTime as string | undefined));
149+
firstTextOf(nextCountdownTarget as TextListLike) ||
150+
firstTextOf(fallbackCountdownTarget as TextListLike) ||
151+
undefined;
150152

151153
return { nextItem, countdownTo };
152154
};

0 commit comments

Comments
 (0)