Public birth chart: keep it across pages for the tab, login for the summary
CI / build (push) Successful in 5m52s
CI / deploy (push) Skipped
CI / test (push) Successful in 1m49s

The typed birth data and the calculated chart stay in sessionStorage (no
cookie, gone with the tab), so they are back after visiting another page;
'Adatok törlése' forgets them. User-input storage for the session needs
no consent; the privacy pages say so. Signing up in the same tab fills
the profile with them.

The offer next to the chart now says the short summary needs a login.
Logged-in users get 'Csillagjegyek' in the menu.

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-21 21:04:26 +00:00
co-authored by Claude Opus 5.5
parent 985b1e872d
commit b41dc31f3e
6 changed files with 109 additions and 14 deletions
@@ -1,7 +1,7 @@
"use client";
import Link from "next/link";
import { useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { CountrySelect, PlaceSearch } from "@/app/profil/BirthForm";
import { AspectGrid, AspectList, BigThree, PositionTables } from "@/components/ChartTables";
@@ -30,6 +30,18 @@ const ERRORS: Record<string, string> = {
const GRID_LEGEND = ["conjunction", "sextile", "square", "trine", "opposition"];
/**
* The calculated chart and the typed birth data, kept for this browser tab
* only (sessionStorage: not a cookie, gone when the tab is closed), so they
* are there again after visiting another page, and the profile can offer the
* birth data after signing up in the same tab. Storage that only keeps what
* the visitor typed, for the session, needs no consent. Nothing of this is
* stored on the server.
*/
const CHART_KEY = "sf_public_chart";
type Saved = { result: Result; birth: BirthData };
/** Links to the sign pages of the Sun, Moon and Ascendant. */
function SignLinks({ result }: { result: Result }) {
const links: [string, string | null, string, boolean][] = [
@@ -101,13 +113,13 @@ function ChartView({ result, birth }: { result: Result; birth: BirthData }) {
<BigThree chart={chart} />
<SignLinks result={result} />
<div className="card calc-save">
<strong>Mentsd el, és ingyen elemezzük</strong>
<strong>A rövid összefoglalóhoz lépj be</strong>
<p className="muted" style={{ margin: 0 }}>
Regisztráció után a képleted megmarad, és ingyen kapsz hozzá egy rövid, személyre szabott összefoglalót.
Innen kérhetsz részletes elemzést, éves előrejelzést vagy kapcsolati összevetést is.
A képletedhez ingyen írunk egy rövid, személyre szabott összefoglalót, ehhez azonban be kell jelentkezned.
Belépés után a képleted is megmarad: a most megadott születési adataidat áthozzuk.
</p>
<Link href="/belepes?mod=regisztracio&vissza=/profil" className="btn btn-primary">
Mentés és ingyenes összefoglaló
<Link href="/belepes?vissza=/profil" className="btn btn-primary">
Belépés és ingyenes összefoglaló
</Link>
</div>
</div>
@@ -158,11 +170,67 @@ export function PublicChart() {
const [ambiguity, setAmbiguity] = useState<"earlier" | "later">("earlier");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<{ result: Result; birth: BirthData } | null>(null);
const [result, setResult] = useState<Saved | null>(null);
const [stored, setStored] = useState(false);
const minuteRef = useRef<HTMLInputElement>(null);
const resultRef = useRef<HTMLDivElement>(null);
const today = useMemo(() => new Date().toISOString().slice(0, 10), []);
// Back on the page: the birth data typed earlier and, in this tab, the chart.
useEffect(() => {
let draft: BirthDraft | null = null;
let saved: Saved | null = null;
try {
draft = JSON.parse(sessionStorage.getItem(BIRTH_DRAFT_KEY) ?? "null");
saved = JSON.parse(sessionStorage.getItem(CHART_KEY) ?? "null");
} catch {
return;
}
if (draft && /^\d{4}-\d{2}-\d{2}$/.test(draft.date) && draft.geonames_id) {
setYear(draft.date.slice(0, 4));
setMonth(String(Number(draft.date.slice(5, 7))));
setDay(String(Number(draft.date.slice(8, 10))));
setHour(draft.time ? draft.time.slice(0, 2) : "");
setMinute(draft.time ? draft.time.slice(3, 5) : "");
setTimeUnknown(!draft.time);
setCountry(draft.country);
setPlace({
geonames_id: draft.geonames_id,
name: draft.placeName,
region: draft.region,
population: null,
country_code: draft.country,
});
setStored(true);
}
if (saved?.result?.chart && saved.birth?.date) {
setResult(saved);
setStored(true);
}
}, []);
/** Forgets the birth data and the chart in this browser. */
function clear() {
try {
sessionStorage.removeItem(BIRTH_DRAFT_KEY);
sessionStorage.removeItem(CHART_KEY);
} catch {
// storage blocked
}
setYear("");
setMonth("");
setDay("");
setHour("");
setMinute("");
setTimeUnknown(false);
setCountry("HU");
setPlace(null);
setAmbiguous(false);
setResult(null);
setError(null);
setStored(false);
}
async function submit(e: React.FormEvent) {
e.preventDefault();
setError(null);
@@ -185,12 +253,14 @@ export function PublicChart() {
body: { ...birth, ...(ambiguous ? { ambiguous_time: ambiguity } : {}) },
});
setResult({ result: r, birth });
// After sign-up the profile page offers these birth data.
// Kept in this browser only: for coming back to the page, and for the profile after sign-up.
const draft: BirthDraft = { ...birth, time: birth.time ?? null, placeName: place.name, region: place.region };
try {
localStorage.setItem(BIRTH_DRAFT_KEY, JSON.stringify(draft));
sessionStorage.setItem(BIRTH_DRAFT_KEY, JSON.stringify(draft));
sessionStorage.setItem(CHART_KEY, JSON.stringify({ result: r, birth }));
setStored(true);
} catch {
// storage blocked
// storage blocked or full: the chart is still shown
}
requestAnimationFrame(() =>
resultRef.current?.scrollIntoView({
@@ -353,8 +423,16 @@ export function PublicChart() {
<button type="submit" className="btn btn-primary" disabled={busy}>
{busy ? "Számolás…" : "Elkészítem a horoszkópom"}
</button>
<span className="hint">Ingyenes, belépés nélkül. Az adataidat nem mentjük el.</span>
{stored && (
<button type="button" className="btn btn-ghost btn-sm" onClick={clear}>
Adatok törlése
</button>
)}
</div>
<p className="hint" style={{ margin: 0 }}>
Ingyenes, belépés nélkül. Az adataidat a szerveren nem tároljuk: csak ebben a böngészőlapban maradnak meg,
hogy oldalváltáskor ne vesszenek el, és a lap bezárásakor törlődnek.
</p>
</form>
{result && (