Weekly horoscope landing page, link previews for the forum, and fixes from the review
- /heti-horoszkop for visitors: what it is, a real example written for the example chart, login and sign-up buttons; its own link preview image. - Forum: link previews (image, title; a public thread's opening words) for every forum page; none of a members-only thread's content. - Review fixes: a removed thread's photos are no longer served; public photos are cached for an hour, not a year (removals take effect); photos of threads removed a year ago are cleaned up; deleting one forum question no longer revokes the chart link another question still shows; the daily digest leaves out closed topics the member is no longer in; typing notices at most one a second per connection; the weekly page asks for the text once and then only reads it (no repeated paid runs after a failure); turning the Monday e-mail back on from the e-mail page waits for next Monday, like the site's switch; the week's last day is right in the week the clocks go back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { MONTHS, WeekCard, WeeklyEmailSwitch } from "@/components/WeeklyHoroscope";
|
||||
import { WeekCard, WeeklyEmailSwitch } from "@/components/WeeklyHoroscope";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import type { Analysis } from "@/lib/types";
|
||||
import { MONTHS } from "@/lib/weekly";
|
||||
|
||||
const POLL_MS = 3000;
|
||||
const MAX_POLLS = 60;
|
||||
@@ -34,8 +35,9 @@ function monthName(key: string): string {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* week's horoscope is asked for first (queued if new), then read until the
|
||||
* worker has written it (or given up); meanwhile its card shows the waiting
|
||||
* animation.
|
||||
*/
|
||||
export function WeeklyPage({ month, isAdmin }: { month: string | null; isAdmin: boolean }) {
|
||||
const [data, setData] = useState<Month | null>(null);
|
||||
@@ -52,25 +54,45 @@ export function WeeklyPage({ month, isAdmin }: { month: string | null; isAdmin:
|
||||
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
|
||||
const wait = () => new Promise((resolve) => (timer = setTimeout(resolve, POLL_MS)));
|
||||
/**
|
||||
* This week's text: asked for once (queued if new, or written again if
|
||||
* the last attempt failed), then only read until the worker is done.
|
||||
*/
|
||||
const follow = async () => {
|
||||
let week: Week | null = null;
|
||||
for (let tries = 0; !week && tries < 5 && !stopped; tries++) {
|
||||
try {
|
||||
const got = await api<Week & { email: boolean }>("/weekly", { method: "POST" });
|
||||
week = { week_start: got.week_start, week_end: got.week_end, analysis: got.analysis };
|
||||
} catch {
|
||||
await wait();
|
||||
}
|
||||
}
|
||||
if (!week || stopped) return setGaveUp(!stopped);
|
||||
putWeek(week);
|
||||
for (let polls = 0; !stopped; polls++) {
|
||||
const { status } = week.analysis;
|
||||
if (status === "done" || status === "failed") return;
|
||||
if (polls >= MAX_POLLS) return setGaveUp(true);
|
||||
await wait();
|
||||
try {
|
||||
const id: string = week.analysis.id;
|
||||
const analysis: Analysis = await api<Analysis>(`/analyses/${id}`);
|
||||
if (stopped) return;
|
||||
week = { ...week, analysis };
|
||||
putWeek(week);
|
||||
} 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();
|
||||
if (page.month === page.current_month) await follow();
|
||||
} catch (e) {
|
||||
if (!stopped) setError(errorText(e));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user