forked from Sub-Rosa-Issue/sub-rosa-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathround-status.ts
More file actions
41 lines (32 loc) · 1.02 KB
/
Copy pathround-status.ts
File metadata and controls
41 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2026 Sub Rosa contributors
export type BadgeState = "loading" | "empty" | "error" | "stale" | "found";
export interface RoundStatusInfo {
state: BadgeState;
tag: string | null;
message: string;
}
export interface RoundStatusInput {
live: unknown;
error: string | null;
configured: boolean;
stale: boolean;
}
export function getRoundStatusInfo(input: RoundStatusInput): RoundStatusInfo {
const { live, error, configured, stale } = input;
if (error) {
return { state: "error", tag: null, message: error };
}
if (configured && live === null) {
return { state: "loading", tag: null, message: "Fetching round status…" };
}
if (live === null) {
return { state: "empty", tag: null, message: "No live round data" };
}
const tag = (
live as { round?: { status?: { tag?: string } } } | null
)?.round?.status?.tag ?? null;
if (stale) {
return { state: "stale", tag, message: "Live data may be stale" };
}
return { state: "found", tag, message: tag ?? "Round exists" };
}