Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/programs/ProgramsPageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { BtnArrowSvg } from "../../components/landing/btn-arrow";
function ProgramCard({ program }: { program: AirtableProgram }) {
const wrapperRef = useRef<HTMLDivElement>(null);
const now = new Date();
const isEnded = parseLocalDate(program.endDate) < now;
// If no end date, program runs indefinitely (never ends)
const isEnded = program.endDate ? parseLocalDate(program.endDate) < now : false;
const isDraft = parseLocalDate(program.startDate) > now;

const s = program.site;
Expand Down Expand Up @@ -41,7 +42,9 @@ function ProgramCard({ program }: { program: AirtableProgram }) {
? "Coming soon"
: isEnded
? "Ended"
: `Ends ${parseLocalDate(program.endDate).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}`;
: program.endDate
? `Ends ${parseLocalDate(program.endDate).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}`
: "Ongoing";
const badgeEnded = isEnded || isDraft;

// Italic metadata lines
Expand Down Expand Up @@ -709,10 +712,13 @@ export default function ProgramsPage({
const bPinned = Number(Boolean(b.site?.pinned));
if (aPinned !== bPinned) return bPinned - aPinned;

if (sort === "deadline-asc")
return parseLocalDate(a.endDate).getTime() - parseLocalDate(b.endDate).getTime();
if (sort === "deadline-desc")
return parseLocalDate(b.endDate).getTime() - parseLocalDate(a.endDate).getTime();
// For deadline sorting, treat null endDate as far future (never ends)
const FAR_FUTURE = new Date(9999, 11, 31).getTime();
const aEndTime = a.endDate ? parseLocalDate(a.endDate).getTime() : FAR_FUTURE;
const bEndTime = b.endDate ? parseLocalDate(b.endDate).getTime() : FAR_FUTURE;
Comment thread
3kh0 marked this conversation as resolved.

if (sort === "deadline-asc") return aEndTime - bEndTime;
if (sort === "deadline-desc") return bEndTime - aEndTime;
if (sort === "az") return a.name.localeCompare(b.name);
return b.name.localeCompare(a.name);
});
Expand Down
27 changes: 14 additions & 13 deletions app/programs/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useState, useEffect, useRef } from "react";
import { Navbar } from "../../../components/Navbar";
import type { AirtableProgram } from "../../../lib/programs";
import { parseLocalDate, type AirtableProgram } from "../../../lib/programs";
import type { SiteProgram, ProjectType, ProgramFormat } from "../../../lib/site-programs";
import { PROJECT_TYPE_OPTIONS, formatInPersonDate } from "../../../lib/site-programs";
import { BtnArrowSvg } from "../../../components/landing/btn-arrow";
Expand Down Expand Up @@ -38,17 +38,16 @@ function CardPreview({ prog }: { prog: EditorProgram }) {
const logoUrl = site?.logoUrl ?? null;
const bgImageUrl = draft.bgType === "image" ? (site?.bgImageUrl ?? null) : null;
const now = new Date();
function parseLocalDate(iso: string) {
const [y, m, d] = iso.split("-").map(Number);
return new Date(y, m - 1, d);
}
const isEnded = parseLocalDate(ysws.endDate) < now;
// If no end date, program runs indefinitely (never ends)
const isEnded = ysws.endDate ? parseLocalDate(ysws.endDate) < now : false;
const isDraft = parseLocalDate(ysws.startDate) > now;
const badgeLabel = isDraft
? "Coming soon"
: isEnded
? "Ended"
: `Ends ${parseLocalDate(ysws.endDate).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}`;
: ysws.endDate
? `Ends ${parseLocalDate(ysws.endDate).toLocaleDateString("en-GB", { day: "numeric", month: "short" })}`
: "Ongoing";
const badgeEnded = isEnded || isDraft;
const buttonText = isEnded ? "See the site" : "Start now";
const buttonColor = draft.buttonColor || "#ec3750";
Expand Down Expand Up @@ -1716,17 +1715,19 @@ export default function EditPage() {
color: "var(--muted)",
}}
>
{new Date(prog.ysws.startDate).toLocaleDateString("en-GB", {
{parseLocalDate(prog.ysws.startDate).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
})}{" "}
–{" "}
{new Date(prog.ysws.endDate).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
})}
{prog.ysws.endDate
? parseLocalDate(prog.ysws.endDate).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
})
: "Ongoing"}
</span>
<span style={{ color: "var(--red)", fontSize: 14, marginLeft: 8 }}>
{expanded === prog.ysws.name ? "▲" : "▼"}
Expand Down
7 changes: 5 additions & 2 deletions components/landing/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function SkeletonCard() {
// ── Dynamic event card ───────────────────────────────────────────────────────
function EventCard({ program }: { program: AirtableProgram }) {
const wrapperRef = useRef<HTMLDivElement>(null);
const endDate = parseLocalDate(program.endDate);
// endDate may be null for indefinite programs
const endDate = program.endDate ? parseLocalDate(program.endDate) : null;

const s = program.site;
const bgColor = s?.bgColor ?? "var(--surface)";
Expand Down Expand Up @@ -60,8 +61,10 @@ function EventCard({ program }: { program: AirtableProgram }) {
} else {
badgeLabel = `${start.getDate()} ${start.toLocaleDateString("en-GB", { month: "short" })} – ${end.getDate()} ${end.toLocaleDateString("en-GB", { month: "short" })} ${end.getFullYear()}`;
}
} else {
} else if (endDate) {
badgeLabel = `Ends ${endDate.toLocaleDateString("en-GB", { day: "numeric", month: "short" })}`;
} else {
badgeLabel = "Ongoing";
}

return (
Expand Down
4 changes: 2 additions & 2 deletions lib/programs-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function readPrograms({ fresh = false }: FetchProgramsOptions = {}): Promi
}

const params = new URLSearchParams();
params.set("filterByFormula", "AND(NOT({Start Date}=''), NOT({End Date}=''))");
params.set("filterByFormula", "NOT({Start Date}='')");
params.append("fields[]", "Name");
params.append("fields[]", "Start Date");
params.append("fields[]", "End Date");
Expand Down Expand Up @@ -73,7 +73,7 @@ async function readPrograms({ fresh = false }: FetchProgramsOptions = {}): Promi
id: record.id,
name,
startDate: record.fields["Start Date"],
endDate: record.fields["End Date"],
endDate: record.fields["End Date"] || null,
websiteUrl: record.fields["Website URL"] ?? null,
site: siteMap.get(name) ?? null,
};
Comment thread
3kh0 marked this conversation as resolved.
Expand Down
5 changes: 3 additions & 2 deletions lib/programs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface AirtableProgram {
id: string;
name: string;
startDate: string;
endDate: string;
endDate: string | null;
websiteUrl: string | null;
site: SiteProgram | null;
}
Expand All @@ -21,7 +21,8 @@ export function getProgramStatus(
now = new Date(),
): ProgramStatus {
const started = parseLocalDate(program.startDate) <= now;
const ended = parseLocalDate(program.endDate) < now;
// If no end date, program runs indefinitely (never ends)
const ended = program.endDate ? parseLocalDate(program.endDate) < now : false;
return !started ? "draft" : ended ? "ended" : "ongoing";
}

Expand Down