Weekly horoscope: its own page, a Monday e-mail, and one page for every e-mail setting
CI / test (push) Successful in 3m17s
CI / build (push) Skipped
CI / deploy (push) Skipped

- The week's sky on the member's own chart (horoscope-api POST /v1/week,
  astro_engine::week): the planets' aspects to the natal points with the day
  each is exact, positions, the Moon's signs, lunar phases, stations and sign
  changes; stored once per chart and week (weekly_skies, migration 0047).
- Its text is a 'weekly' analysis written by the summary's (cheap) model when
  the member opens /heti-horoszkop: one month per page, the newest week
  first, the waiting animation while it is written. In the menu, and linked
  from the chart page.
- Monday 7:00 e-mail (worker task 'weekly'): only that it is there; on by
  default for everyone with a chart, members of today too. Its footer opens
  /ertesitesek?token=…, where the weekly e-mail and every forum e-mail can
  be set without logging in; the mail client's one-click unsubscribe turns
  off the weekly one. Also a switch on the page and on the Profile page.
- Privacy notice (HU/EN) describes it; ratings, admin labels and the model
  page know the new kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-27 09:40:09 +00:00
co-authored by Claude Opus 5.5
parent 50c29e4595
commit 0358e137f1
46 changed files with 2368 additions and 70 deletions
@@ -0,0 +1,151 @@
"use client";
import Link from "next/link";
import { useEffect, useState } from "react";
import { MONTHS, WeekCard, WeeklyEmailSwitch } from "@/components/WeeklyHoroscope";
import { api, errorText } from "@/lib/api";
import type { Analysis } from "@/lib/types";
const POLL_MS = 3000;
const MAX_POLLS = 60;
interface Week {
week_start: string;
week_end: string;
analysis: Analysis;
}
interface Month {
month: string;
current_month: string;
this_week: string;
weeks: Week[];
older: string | null;
newer: string | null;
email: boolean;
}
/** "2026. november". */
function monthName(key: string): string {
const [y, m] = key.split("-").map(Number);
return `${y}. ${MONTHS[m - 1]}`;
}
/**
* One month of weekly horoscopes, the newest week first. In this month the
* week's horoscope is asked for first (queued if new), and polled until the
* worker has written it; meanwhile its card shows the waiting animation.
*/
export function WeeklyPage({ month, isAdmin }: { month: string | null; isAdmin: boolean }) {
const [data, setData] = useState<Month | null>(null);
const [error, setError] = useState<string | null>(null);
const [gaveUp, setGaveUp] = useState(false);
// Bumped when an admin has this week's text written again: polls anew.
const [round, setRound] = useState(0);
const query = month ? `?month=${month}` : "";
/** This week's horoscope into the list (it may not be there yet). */
const putWeek = (week: Week) =>
setData((d) => (d ? { ...d, weeks: [week, ...d.weeks.filter((w) => w.week_start !== week.week_start)] } : d));
useEffect(() => {
let stopped = false;
let timer: ReturnType<typeof setTimeout> | undefined;
let polls = 0;
const poll = async () => {
try {
const week = await api<Week & { email: boolean }>("/weekly", { method: "POST" });
if (stopped) return;
putWeek({ week_start: week.week_start, week_end: week.week_end, analysis: week.analysis });
if (week.analysis.status === "done") return;
} catch {
// try again on the next tick
}
if (++polls >= MAX_POLLS) return setGaveUp(true);
timer = setTimeout(poll, POLL_MS);
};
(async () => {
try {
const page = await api<Month>(`/weekly/history${query}`);
if (stopped) return;
setData(page);
if (page.month === page.current_month) await poll();
} catch (e) {
if (!stopped) setError(errorText(e));
}
})();
return () => {
stopped = true;
clearTimeout(timer);
};
}, [query, round]);
if (error) {
return (
<p className="msg msg-error" role="alert">
{error}
</p>
);
}
if (!data) {
return <p className="muted">Betöltés…</p>;
}
const restarted = (week: Week) => (a: Analysis) => {
setGaveUp(false);
setData((d) =>
d ? { ...d, weeks: d.weeks.map((w) => (w.week_start === week.week_start ? { ...w, analysis: a } : w)) } : d,
);
if (week.week_start === data.this_week) setRound((r) => r + 1);
};
const pager = (
<nav className="weekly-pager" aria-label="Hónapok">
{data.older ? (
<Link href={`/heti-horoszkop?honap=${data.older}`} className="btn btn-sm">
← Korábbi hónap
</Link>
) : (
<span />
)}
<strong>{monthName(data.month)}</strong>
{data.newer ? (
<Link
href={data.newer === data.current_month ? "/heti-horoszkop" : `/heti-horoszkop?honap=${data.newer}`}
className="btn btn-sm"
>
Újabb hónap →
</Link>
) : (
<span />
)}
</nav>
);
return (
<div className="field" style={{ gap: 18 }}>
{pager}
{data.weeks.length === 0 ? (
<p className="muted">Ebben a hónapban nem nézted meg a heti horoszkópodat.</p>
) : (
data.weeks.map((w) => (
<WeekCard
key={w.week_start}
start={w.week_start}
end={w.week_end}
analysis={w.analysis}
current={w.week_start === data.this_week}
gaveUp={w.week_start === data.this_week && gaveUp}
isAdmin={isAdmin}
onRestarted={restarted(w)}
/>
))
)}
{(data.older || data.newer) && data.weeks.length > 1 && pager}
<div className="card">
<WeeklyEmailSwitch initial={data.email} label="Hétfőnként szóljatok e-mailben, ha itt az új heti horoszkópom" />
</div>
</div>
);
}
@@ -0,0 +1,46 @@
import type { Metadata } from "next";
import Link from "next/link";
import { requireMe } from "@/lib/server";
import { WeeklyPage } from "./WeeklyPage";
export const metadata: Metadata = { title: "Heti horoszkóp" };
/**
* The member's weekly horoscopes, one month at a time, the newest first
* (`?honap=2026-11` pages back). This week's is written when the page opens.
*/
export default async function WeeklyHoroscopePage({
searchParams,
}: {
searchParams: Promise<Record<string, string | string[]>>;
}) {
const me = await requireMe("/heti-horoszkop");
const raw = (await searchParams).honap;
const month = (Array.isArray(raw) ? raw[0] : raw) ?? null;
return (
<main className="page" style={{ maxWidth: 760 }}>
<div className="page-head">
<h1>Heti horoszkóp</h1>
<p className="muted">Hétfőnként új, a saját képletedből és a hét égboltjából.</p>
</div>
{me.primary_chart_id ? (
<WeeklyPage
key={month ?? "now"}
month={month && /^\d{4}-\d{2}$/.test(month) ? month : null}
isAdmin={me.user.roles.includes("admin")}
/>
) : (
<div className="card field" style={{ gap: 12 }}>
<p style={{ margin: 0 }}>A heti horoszkóphoz előbb add meg a születési adataidat.</p>
<div>
<Link href="/profil#birth" className="btn btn-primary">
Születési adatok megadása
</Link>
</div>
</div>
)}
</main>
);
}