From 0772181bb3b7dc705e626677a6cdc51eb0bfa1f8 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Mon, 23 Nov 2026 09:38:59 +0800 Subject: [PATCH] fix: show events after they end --- src/components/EventList.astro | 4 ++-- src/lib/db.ts | 8 ++++++++ src/pages/e/index.astro | 18 ++++++++++++++++-- src/pages/index.astro | 10 ++++++---- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/components/EventList.astro b/src/components/EventList.astro index badb151..ca3dc51 100644 --- a/src/components/EventList.astro +++ b/src/components/EventList.astro @@ -1,6 +1,6 @@ --- import { passDesign } from "../cards/pass" -import { claimPhase, type Event } from "../lib/db" +import { checkInPhase, claimPhase, type Event } from "../lib/db" import { formatRange, formatShort } from "../lib/format" interface Props { @@ -8,7 +8,7 @@ interface Props { } const status = (e: Event) => - ({ + checkInPhase(e) === "ended" ? { tone: "", text: "已结束" } : ({ upcoming: { tone: "warn", text: `${formatShort(e.claim_from)} 开放领取` }, open: { tone: "ok", text: "正在领取" }, closed: { tone: "", text: "领取已截止" }, diff --git a/src/lib/db.ts b/src/lib/db.ts index 0b1bb90..6ea664c 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -93,6 +93,14 @@ export const upcomingEvents = async (limit = 50) => .all() ).results +export const pastEvents = async (limit = 50) => + ( + await db() + .prepare("SELECT * FROM events WHERE ends_at < ? ORDER BY starts_at DESC LIMIT ?") + .bind(new Date().toISOString(), limit) + .all() + ).results + export interface Stub extends Event { pass_id: string serial: number diff --git a/src/pages/e/index.astro b/src/pages/e/index.astro index 2571a98..20542b0 100644 --- a/src/pages/e/index.astro +++ b/src/pages/e/index.astro @@ -2,10 +2,10 @@ import EventList from "../../components/EventList.astro" import PassShelf from "../../components/PassShelf.astro" import Base from "../../layouts/Base.astro" -import { checkInPhase, passesOf, upcomingEvents } from "../../lib/db" +import { checkInPhase, passesOf, pastEvents, upcomingEvents } from "../../lib/db" const { user } = Astro.locals -const [events, passes] = await Promise.all([upcomingEvents(), user ? passesOf(user.email) : []]) +const [events, past, passes] = await Promise.all([upcomingEvents(), pastEvents(), user ? passesOf(user.email) : []]) const mine = passes.filter((p) => !p.redeemed_at && checkInPhase(p) !== "ended") --- @@ -24,6 +24,15 @@ const mine = passes.filter((p) => !p.redeemed_at && checkInPhase(p) !== "ended") {mine.length > 0 && } {events.length ? :

近期没有活动。

} + {past.length > 0 && ( +
+
+

Past

+

往期活动

+
+ +
+ )} @@ -40,6 +49,11 @@ const mine = passes.filter((p) => !p.redeemed_at && checkInPhase(p) !== "ended") gap: 0.75rem; } + section { + display: grid; + gap: 2.5rem; + } + header { display: grid; justify-items: start; diff --git a/src/pages/index.astro b/src/pages/index.astro index f9117bb..6704856 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -3,12 +3,14 @@ import { passDesign } from "../cards/pass" import MemberCard from "../cards/MemberCard.astro" import EventList from "../components/EventList.astro" import Base from "../layouts/Base.astro" -import { countMembers, upcomingEvents } from "../lib/db" +import { countMembers, pastEvents, upcomingEvents } from "../lib/db" import { showcaseEvent, showcaseMember } from "../lib/showcase" const { user } = Astro.locals const me = user?.member ?? null const [events, count] = await Promise.all([upcomingEvents(6), me ? countMembers() : null]) +const shown = events.length ? events : await pastEvents(3) +const past = !events.length && shown.length > 0 const featured = events[0] ?? showcaseEvent() const Featured = passDesign(featured.design) const layers = [ @@ -76,11 +78,11 @@ const layers = [
-

Upcoming

-

近期活动

+

{past ? "Recent" : "Upcoming"}

+

{past ? "最近的活动" : "近期活动"}

全部活动 →
- {events.length ? :

近期没有活动。

} + {shown.length ? :

近期没有活动。

}