Skip to content

Commit 615153c

Browse files
committed
site: update countdown for live stream
1 parent f6cca20 commit 615153c

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

site/src/pages/index.tsx

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,32 @@ function getLastWednesdayOfMonth(date = new Date()) {
8282
return lastWednesday;
8383
}
8484

85-
function formatCountdown(ms) {
85+
function getNextMeeting(now = new Date()) {
86+
const currentMonthMeeting = getLastWednesdayOfMonth(now);
87+
const meetingEndTime = new Date(
88+
currentMonthMeeting.getTime() + 60 * 60 * 1000,
89+
); // 1 hour after start
90+
91+
// If we're past the current month's meeting end time, get next month's meeting
92+
if (now >= meetingEndTime) {
93+
const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
94+
return getLastWednesdayOfMonth(nextMonth);
95+
}
96+
97+
return currentMonthMeeting;
98+
}
99+
100+
function isLiveTime(now = new Date()) {
101+
const currentMonthMeeting = getLastWednesdayOfMonth(now);
102+
const meetingStartTime = currentMonthMeeting.getTime();
103+
const meetingEndTime = meetingStartTime + 60 * 60 * 1000; // 1 hour after start
104+
const currentTime = now.getTime();
105+
106+
return currentTime >= meetingStartTime && currentTime < meetingEndTime;
107+
}
108+
109+
function formatCountdown(ms, isLive = false) {
110+
if (isLive) return "Live Now!";
86111
if (ms <= 0) return "Starting soon";
87112
const totalSeconds = Math.floor(ms / 1000);
88113
const weeks = Math.floor(totalSeconds / (7 * 24 * 3600));
@@ -104,12 +129,18 @@ function formatCountdown(ms) {
104129
function MonthlyReviewsSection() {
105130
const [countdown, setCountdown] = useState("");
106131
const [nextDate, setNextDate] = useState("");
132+
const [isLive, setIsLive] = useState(false);
107133

108134
useEffect(() => {
109135
function updateCountdown() {
110136
const now = new Date();
111-
const target = getLastWednesdayOfMonth(now);
112-
setCountdown(formatCountdown(target.getTime() - now.getTime()));
137+
const live = isLiveTime(now);
138+
const target = getNextMeeting(now);
139+
140+
setIsLive(live);
141+
setCountdown(
142+
formatCountdown(target.getTime() - now.getTime(), live),
143+
);
113144
setNextDate(target.toLocaleString(undefined, {
114145
weekday: "short",
115146
year: "numeric",
@@ -168,31 +199,38 @@ function MonthlyReviewsSection() {
168199
minWidth: 180,
169200
}}
170201
>
171-
<span>Watch Live</span>
172-
<span
202+
<span>
203+
{isLive ? "Join Live" : "Watch Live"}
204+
</span>
205+
{!isLive && (
206+
<span
207+
style={{
208+
fontSize: "0.68em",
209+
fontWeight: 600,
210+
color:
211+
"var(--ifm-color-primary-contrast-background, #222)",
212+
marginTop: 2,
213+
lineHeight: 1.2,
214+
}}
215+
>
216+
{countdown}
217+
</span>
218+
)}
219+
</Link>
220+
{!isLive && (
221+
<div
173222
style={{
174-
fontSize: "0.68em",
175-
fontWeight: 600,
223+
fontSize: "1rem",
224+
marginTop: 10,
176225
color:
177-
"var(--ifm-color-primary-contrast-background, #222)",
178-
marginTop: 2,
179-
lineHeight: 1.2,
226+
"var(--ifm-color-emphasis-800)",
227+
textAlign: "center",
228+
fontWeight: 500,
180229
}}
181230
>
182-
{countdown}
183-
</span>
184-
</Link>
185-
<div
186-
style={{
187-
fontSize: "1rem",
188-
marginTop: 10,
189-
color: "var(--ifm-color-emphasis-800)",
190-
textAlign: "center",
191-
fontWeight: 500,
192-
}}
193-
>
194-
Next update: {nextDate}
195-
</div>
231+
Next update: {nextDate}
232+
</div>
233+
)}
196234
</div>
197235
<Link
198236
className={clsx(styles.underlineLink)}

0 commit comments

Comments
 (0)