app: the House of Prayer's screens, changelog and README (APP-1.0-PLAN §3)

The 24-hour clock on the Prayer tab (midnight at the top, the night half darker,
open slots dashed, your own in gold, a hand at now), live over the stream with
polling as the fallback; tap an hour for Cover it / Join, the open hours as
buttons; signed out, back from Accounts with that slot's sheet open. The booking
sheet (once, every week, every day; length, end, reminder and channel, a note),
Me → My prayer (skip, add back, reminder, end date, stop, renew, "I prayed"),
the renew and "I prayed" link pages, sharing a testimony, Home's small clock
with the next gap and your next slot, the campaign card. The admin's House of
Prayer: the week, who prays when (names, access-logged), booking for a member,
the rules, campaigns, testimonies.

Checked in a browser on a throwaway PostgreSQL: one member books through the
sheet and a visitor's clock updates live; no page errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 10:42:35 +02:00
co-authored by Claude Opus 5.5
parent 5213bb36c0
commit 1dd3aadb60
24 changed files with 1631 additions and 13 deletions
+2
View File
@@ -0,0 +1,2 @@
/** Where "Sign in" goes: Accounts, and back to that exact page (ROADMAP-v3 §3). `mfa` for the admin. Safe in client components. */
export const signInHref = (returnTo: string, mfa = false) => `/api/auth/signin?returnTo=${encodeURIComponent(returnTo)}${mfa ? "&mfa=1" : ""}`;
+1 -2
View File
@@ -93,8 +93,7 @@ export const loadMe = cache(async (): Promise<Me | null> => {
return null;
});
/** Where "Sign in" goes: Accounts, and back to that exact page (ROADMAP-v3 §3). `mfa` for the admin. */
export const signInHref = (returnTo: string, mfa = false) => `/api/auth/signin?returnTo=${encodeURIComponent(returnTo)}${mfa ? "&mfa=1" : ""}`;
export { signInHref } from "./links";
/** The first name for a greeting ("Good morning, Thandi"). */
export const firstName = (name: string) => name.trim().split(/\s+/)[0] ?? name;
+139
View File
@@ -0,0 +1,139 @@
/**
* The House of Prayer's shapes and formatting, for server and client components alike
* (backend/src/prayer/*). Times are shown in the church's timezone, never the phone's.
*/
export type Slot = { minute: number; start: string; end: string; count: number; covered: boolean; mine: boolean };
/** GET /api/v1/prayer/day */
export type Day = {
date: string;
slots: Slot[];
covered: number;
total: number;
timezone: string;
slotMinutes: number;
target: number;
today: string;
now: string;
};
/** GET /api/v1/prayer/campaign */
export type Campaign = {
id: string;
title: string;
description: string;
imageUrl: string | null;
goal: string | null;
startDate: string;
endDate: string;
targetPerSlot: number | null;
started: boolean;
daysLeft: number;
startsInDays: number;
coveragePercent: number;
hoursPrayed: number;
};
export type Testimony = { id: string; text: string; by: string; campaignId: string | null; createdAt: string };
export type Recurrence = "once" | "daily" | "weekly";
export type Reminder = "none" | "min15" | "hour1" | "evening";
export type Channel = "email" | "whatsapp" | "both";
/** GET /api/v1/me/prayer */
export type MyPrayer = {
timezone: string;
rules: { slotMinutes: number; cancelHours: number; bookAheadMonths: number; recurringMaxMonths: number };
coordinator: { name: string | null; contact: string | null };
commitments: {
id: string;
startDate: string;
startMinute: number;
durationMinutes: number;
recurrence: Recurrence;
endDate: string;
reminder: Reminder;
channel: Channel;
note: string | null;
active: boolean;
daysLeft: number;
canRenew: boolean;
upcoming: { date: string; start: string; end: string; skipped: boolean; locked: boolean }[];
toMark: string[];
}[];
prayedTotal: number;
};
export const REMINDER_NAMES: Record<Reminder, string> = {
none: "No reminder",
min15: "15 minutes before",
hour1: "1 hour before",
evening: "The evening before (20:00)",
};
export const CHANNEL_NAMES: Record<Channel, string> = { email: "Email", whatsapp: "WhatsApp", both: "Email and WhatsApp" };
/** "02:00" from minutes after midnight (wraps past midnight). */
export const hhmm = (minute: number) => {
const m = ((minute % 1440) + 1440) % 1440;
return `${String(Math.floor(m / 60)).padStart(2, "0")}:${String(m % 60).padStart(2, "0")}`;
};
/** "02:00–03:00" */
export const span = (minute: number, length: number) => `${hhmm(minute)}–${hhmm(minute + length)}`;
/** "2 hours", "30 minutes", "1 hour 30 minutes" */
export function duration(minutes: number): string {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return [h ? `${h} hour${h === 1 ? "" : "s"}` : "", m ? `${m} minutes` : ""].filter(Boolean).join(" ");
}
const midday = (date: string) => new Date(`${date}T12:00:00Z`);
/** "Wednesday 2 December" for a local date (the date itself, no timezone shift). */
export const dayName = (date: string, opts: Intl.DateTimeFormatOptions = { weekday: "long", day: "numeric", month: "long" }) =>
new Intl.DateTimeFormat("en-ZA", { ...opts, timeZone: "UTC" }).format(midday(date));
/** "Today", "Tomorrow" or "Wed 2 Dec". */
export function relativeDay(date: string, today: string): string {
if (date === today) return "Today";
if (date === addDays(today, 1)) return "Tomorrow";
if (date === addDays(today, -1)) return "Yesterday";
return dayName(date, { weekday: "short", day: "numeric", month: "short" });
}
export function addDays(date: string, n: number): string {
const d = midday(date);
d.setUTCDate(d.getUTCDate() + n);
return d.toISOString().slice(0, 10);
}
/** "Every Wednesday", "Every day" or "Once, Wed 2 Dec". */
export function repeats(c: { recurrence: Recurrence; startDate: string }): string {
if (c.recurrence === "daily") return "Every day";
if (c.recurrence === "weekly") return `Every ${dayName(c.startDate, { weekday: "long" })}`;
return `Once, ${dayName(c.startDate, { weekday: "short", day: "numeric", month: "short" })}`;
}
/** The local minute of an ISO instant in `tz` (the clock's hand). */
export function minuteIn(iso: string, tz: string): number {
const p = new Intl.DateTimeFormat("en-GB", { timeZone: tz, hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).formatToParts(new Date(iso));
const n = (t: string) => Number(p.find((x) => x.type === t)?.value ?? 0);
return n("hour") * 60 + n("minute");
}
/** An API error's message, or a fallback. */
export async function errorMessage(res: Response, fallback = "That didn't work. Please try again."): Promise<string> {
try {
const body = (await res.json()) as { error?: { message?: string } };
return body.error?.message ?? fallback;
} catch {
return fallback;
}
}
/** Today's local date in `tz`. */
export const localToday = (tz: string, at = new Date()) =>
new Intl.DateTimeFormat("en-CA", { timeZone: tz, year: "numeric", month: "2-digit", day: "2-digit" }).format(at);
+23
View File
@@ -0,0 +1,23 @@
import { cookies } from "next/headers";
import { api, SESSION_COOKIE } from "./load";
import type { Campaign, Day, MyPrayer, Testimony } from "./prayer";
/** A backend GET with the member's session (if any); null when it can't answer. */
export async function backendGet<T>(path: string): Promise<T | null> {
const session = (await cookies()).get(SESSION_COOKIE)?.value;
try {
const res = await fetch(`${api}${path}`, {
headers: session ? { Cookie: `${SESSION_COOKIE}=${encodeURIComponent(session)}` } : {},
cache: "no-store",
});
if (res.ok) return (await res.json()) as T;
} catch {
// The backend is starting or down.
}
return null;
}
export const loadDay = (date?: string | null) => backendGet<Day>(`/api/v1/prayer/day${date ? `?date=${encodeURIComponent(date)}` : ""}`);
export const loadCampaign = async () => (await backendGet<{ campaign: Campaign | null }>("/api/v1/prayer/campaign"))?.campaign ?? null;
export const loadTestimonies = async () => (await backendGet<{ testimonies: Testimony[] }>("/api/v1/prayer/testimonies"))?.testimonies ?? [];
export const loadMyPrayer = () => backendGet<MyPrayer>("/api/v1/me/prayer");