Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import clsx from "clsx";
import { ReactNode } from "react";

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
color: "rose" | "red" | "white";
invert?: boolean;
href?: string;
disable?: boolean;
children: React.ReactNode;
children: ReactNode;
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent React type import usage. Line 4 uses React.ButtonHTMLAttributes (namespace import), but line 9 now uses ReactNode (named import). For consistency, either use React.ReactNode without the import on line 2, or change line 4 to use a named import like ButtonHTMLAttributes from 'react'. The current mixed approach is valid but inconsistent.

Copilot uses AI. Check for mistakes.
}

const baseClasses =
Expand Down
43 changes: 30 additions & 13 deletions src/pages/api/rsvp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// src/pages/api/rsvp.ts
import { NextApiRequest, NextApiResponse } from "next";

async function getCount() {
Expand Down Expand Up @@ -32,17 +33,33 @@ let cached = { value: -1, updated: 0 };
// Cache duration in milliseconds
const CACHE_DURATION = 30000;

export default async function handler(_req: NextApiRequest, res: NextApiResponse) {
const now = Date.now();
if (now - cached.updated > CACHE_DURATION) {
try {
const count = await getCount();
cached = { value: count, updated: now };
console.log("cached value", cached.value, "updatedAt", new Date(cached.updated).toISOString());
} catch (err: unknown) {
console.error("getCount failed:", err);
res.status(500).json({ error: "couldnt get count" });
}
// Extend global to hold a single timer across module reloads (avoid duplicate timers in dev)
declare global {
var __RSVP_CACHE_TIMER__: NodeJS.Timeout | undefined;
}

async function updateCache() {
try {
const count = await getCount();
cached = { value: count, updated: Date.now() };
console.log("cached value", cached.value, "updatedAt", new Date(cached.updated).toISOString());
} catch (err: unknown) {
console.error("updateCache failed:", err);
// keep previous cached value
}
res.status(200).json({ count: cached.value });
}
}

// Start background updater once per server instance
if (!global.__RSVP_CACHE_TIMER__) {
// initial immediate update (fire-and-forget)
updateCache().catch((e) => console.error("initial update failed:", e));

// schedule periodic updates
global.__RSVP_CACHE_TIMER__ = setInterval(() => {
updateCache().catch((e) => console.error("scheduled update failed:", e));
}, CACHE_DURATION);
}

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ count: cached.value, updatedAt: cached.updated });
}
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function Home() {

let currRef = rawRef ? (rawRef as string) : null;

if (currRef && !/^\d+$/.test(currRef)) {
if (currRef && /^\d+$/.test(currRef)) {
currRef = null;
}

Expand Down