Free birth chart instead of the sign calculator; free tools in the header
/szuletesi-horoszkop (was /aszcendens-kalkulator) shows the whole natal chart without an account: the wheel, Sun/Moon/Ascendant with links to the sign pages, the positions, houses, aspect grid and aspect list, the same views as the chart pages but without the AI parts. A calculation only, nothing saved, still 30 an hour per address (POST /v1/public/chart). The typed birth data are offered on the profile after sign-up. The visitors' header gets a separate 'Ingyenes' group (birth chart, signs) next to the paid sections, on phones in its own row; the home page links them under the hero buttons and in an 'Ingyenes' band. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,367 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
|
||||
import { CountrySelect, PlaceSearch } from "@/app/profil/BirthForm";
|
||||
import { AspectGrid, AspectList, BigThree, PositionTables } from "@/components/ChartTables";
|
||||
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
|
||||
import { Tabs } from "@/components/Tabs";
|
||||
import { ZODIAC_BY_ID } from "@/content/zodiac";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
import { ASPECTS, countryName, formatBirthDate } from "@/lib/astro";
|
||||
import { BIRTH_DRAFT_KEY, MONTHS, type BirthDraft, composeDate, composeTime, daysIn } from "@/lib/birth";
|
||||
import type { BirthData, Chart, ChartResult, Place } from "@/lib/types";
|
||||
|
||||
interface Result {
|
||||
highlights: Chart["highlights"];
|
||||
/** Without a birth time: the sign may have been the neighbouring one at the start or end of the day. */
|
||||
uncertain: { sun: boolean; moon: boolean };
|
||||
chart: ChartResult;
|
||||
}
|
||||
|
||||
const ERRORS: Record<string, string> = {
|
||||
place_not_found: "Nem találjuk ezt a települést. Válassz a listából.",
|
||||
nonexistent_local_time:
|
||||
"Ez az időpont az óraátállítás miatt nem létezett ezen a napon (az órát előreállították). Ellenőrizd a születési időt.",
|
||||
invalid_date: "Érvénytelen dátum.",
|
||||
too_many_requests: "Erről a címről most túl sok számítás érkezett. Próbáld újra egy óra múlva.",
|
||||
};
|
||||
|
||||
const GRID_LEGEND = ["conjunction", "sextile", "square", "trine", "opposition"];
|
||||
|
||||
/** Links to the sign pages of the Sun, Moon and Ascendant. */
|
||||
function SignLinks({ result }: { result: Result }) {
|
||||
const links: [string, string | null, string, boolean][] = [
|
||||
["Napjegy", result.highlights.sun, "nap", result.uncertain.sun],
|
||||
["Holdjegy", result.highlights.moon, "hold", result.uncertain.moon],
|
||||
["Aszcendens", result.highlights.time_known ? result.highlights.ascendant : null, "aszcendens", false],
|
||||
];
|
||||
return (
|
||||
<div className="card calc-links">
|
||||
<span className="eyebrow">Mit jelentenek?</span>
|
||||
<ul>
|
||||
{links.map(([label, sign, anchor, uncertain]) => {
|
||||
const z = sign ? ZODIAC_BY_ID.get(sign) : undefined;
|
||||
return (
|
||||
<li key={anchor}>
|
||||
{z ? (
|
||||
<Link href={`/csillagjegyek/${z.slug}#${anchor}`}>
|
||||
{label}: {z.name} →
|
||||
</Link>
|
||||
) : (
|
||||
<span className="muted">{label}: pontos születési idő kell hozzá</span>
|
||||
)}
|
||||
{uncertain && <span className="hint"> (a születési idő nélkül a szomszédos jegy is lehet)</span>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The calculated chart: the wheel and the tables of the chart pages, without the AI parts. */
|
||||
function ChartView({ result, birth }: { result: Result; birth: BirthData }) {
|
||||
const r = result.chart;
|
||||
const timeKnown = result.highlights.time_known;
|
||||
const chart: Chart = {
|
||||
id: "",
|
||||
label: "Születési horoszkóp",
|
||||
is_primary: false,
|
||||
kind: "person",
|
||||
editable_until: null,
|
||||
birth_data: birth,
|
||||
highlights: result.highlights,
|
||||
chart: r,
|
||||
created_at: "",
|
||||
};
|
||||
const place = r.location.place;
|
||||
const country = place?.country_code ?? birth.country;
|
||||
return (
|
||||
<>
|
||||
<div className="page-head calc-result-head">
|
||||
<h2>A születési horoszkópod</h2>
|
||||
<p className="muted">
|
||||
{formatBirthDate(birth.date)}
|
||||
{timeKnown
|
||||
? `, ${r.time.local.slice(11, 16)} (UTC${r.time.utc_offset}${r.time.dst ? ", nyári idő" : ""})`
|
||||
: ", ismeretlen időpont"}
|
||||
{" · "}
|
||||
{place?.name ?? "–"}
|
||||
{country ? `, ${countryName(country)}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
<section className="chart-layout" aria-label="Képletrajz">
|
||||
<div className="card chart-wheel-card">
|
||||
<ChartWheel chart={r} timeKnown={timeKnown} />
|
||||
<WheelLegend />
|
||||
</div>
|
||||
<div className="field chart-side">
|
||||
<BigThree chart={chart} />
|
||||
<SignLinks result={result} />
|
||||
<div className="card calc-save">
|
||||
<strong>Mentsd el, és ingyen elemezzük</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.
|
||||
</p>
|
||||
<Link href="/belepes?mod=regisztracio&vissza=/profil" className="btn btn-primary">
|
||||
Mentés és ingyenes összefoglaló
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section className="card chart-tabs" aria-label="A képlet részletei">
|
||||
<Tabs
|
||||
label="A képlet részletei"
|
||||
tabs={[
|
||||
{ id: "bolygok", label: "Bolygók", content: <PositionTables chart={chart} /> },
|
||||
{
|
||||
id: "matrix",
|
||||
label: "Mátrix",
|
||||
content: (
|
||||
<div className="field" style={{ gap: 16 }}>
|
||||
<AspectGrid chart={chart} />
|
||||
<ul className="grid-legend" aria-label="Jelmagyarázat">
|
||||
{GRID_LEGEND.map((k) => (
|
||||
<li key={k}>
|
||||
<span className={`sym asp asp-${k}`} aria-hidden="true">
|
||||
{ASPECTS[k]?.glyph}
|
||||
</span>{" "}
|
||||
{ASPECTS[k]?.hu}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{ id: "reszletek", label: "Fényszögek", content: <AspectList chart={chart} /> },
|
||||
]}
|
||||
/>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** The public birth chart: a calculation only, nothing is saved and no AI is used. */
|
||||
export function PublicChart() {
|
||||
const [year, setYear] = useState("");
|
||||
const [month, setMonth] = useState("");
|
||||
const [day, setDay] = useState("");
|
||||
const [hour, setHour] = useState("");
|
||||
const [minute, setMinute] = useState("");
|
||||
const [timeUnknown, setTimeUnknown] = useState(false);
|
||||
const [country, setCountry] = useState("HU");
|
||||
const [place, setPlace] = useState<Place | null>(null);
|
||||
const [ambiguous, setAmbiguous] = useState(false);
|
||||
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 minuteRef = useRef<HTMLInputElement>(null);
|
||||
const resultRef = useRef<HTMLDivElement>(null);
|
||||
const today = useMemo(() => new Date().toISOString().slice(0, 10), []);
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
const date = composeDate(year, month, day);
|
||||
const time = composeTime(hour, minute);
|
||||
if (!date) return setError("Ellenőrizd a dátumot: az év négy számjegy, és a nap legyen az adott hónapban.");
|
||||
if (date > today) return setError("A születési dátum nem lehet a jövőben.");
|
||||
if (!timeUnknown && !time)
|
||||
return setError("Add meg a születési időt (óra 0–23, perc 0–59), vagy jelöld, hogy nem tudod.");
|
||||
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
||||
setBusy(true);
|
||||
try {
|
||||
const birth = {
|
||||
date,
|
||||
...(timeUnknown ? {} : { time }),
|
||||
country,
|
||||
geonames_id: place.geonames_id,
|
||||
};
|
||||
const r = await api<Result>("/public/chart", {
|
||||
body: { ...birth, ...(ambiguous ? { ambiguous_time: ambiguity } : {}) },
|
||||
});
|
||||
setResult({ result: r, birth });
|
||||
// After sign-up the profile page offers these birth data.
|
||||
const draft: BirthDraft = { ...birth, time: birth.time ?? null, placeName: place.name, region: place.region };
|
||||
try {
|
||||
localStorage.setItem(BIRTH_DRAFT_KEY, JSON.stringify(draft));
|
||||
} catch {
|
||||
// storage blocked
|
||||
}
|
||||
requestAnimationFrame(() =>
|
||||
resultRef.current?.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "start",
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.code === "ambiguous_local_time") {
|
||||
setAmbiguous(true);
|
||||
setError(
|
||||
"Ez az időpont az óraátállítás miatt kétszer is előfordult ezen a napon. Válaszd ki, melyikben születtél.",
|
||||
);
|
||||
} else {
|
||||
setError(err instanceof ApiError ? (ERRORS[err.code] ?? errorText(err)) : errorText(err));
|
||||
}
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<form onSubmit={submit} className="card field calc-form" style={{ gap: 18 }} noValidate>
|
||||
<div className="grid-2">
|
||||
<fieldset className="field birth-fields">
|
||||
<legend className="label">Születési dátum</legend>
|
||||
<div className="birth-row">
|
||||
<label className="sr-only" htmlFor="calc-year">
|
||||
Év
|
||||
</label>
|
||||
<input
|
||||
id="calc-year"
|
||||
className="inp birth-year"
|
||||
inputMode="numeric"
|
||||
placeholder="év"
|
||||
maxLength={4}
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value.replace(/\D/g, ""))}
|
||||
/>
|
||||
<label className="sr-only" htmlFor="calc-month">
|
||||
Hónap
|
||||
</label>
|
||||
<select
|
||||
id="calc-month"
|
||||
className="inp birth-month"
|
||||
value={month}
|
||||
onChange={(e) => setMonth(e.target.value)}
|
||||
>
|
||||
<option value="">hónap</option>
|
||||
{MONTHS.map((m, i) => (
|
||||
<option key={m} value={i + 1}>
|
||||
{m}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<label className="sr-only" htmlFor="calc-day">
|
||||
Nap
|
||||
</label>
|
||||
<select id="calc-day" className="inp birth-day" value={day} onChange={(e) => setDay(e.target.value)}>
|
||||
<option value="">nap</option>
|
||||
{Array.from({ length: month ? daysIn(Number(year), Number(month)) : 31 }, (_, i) => (
|
||||
<option key={i + 1} value={i + 1}>
|
||||
{i + 1}.
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset className="field birth-fields">
|
||||
<legend className="label">Születési idő (helyi idő)</legend>
|
||||
<div className="birth-row">
|
||||
<label className="sr-only" htmlFor="calc-hour">
|
||||
Óra
|
||||
</label>
|
||||
<input
|
||||
id="calc-hour"
|
||||
className="inp birth-time"
|
||||
inputMode="numeric"
|
||||
placeholder="óra"
|
||||
maxLength={2}
|
||||
value={timeUnknown ? "" : hour}
|
||||
disabled={timeUnknown}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value.replace(/\D/g, "");
|
||||
setHour(v);
|
||||
setAmbiguous(false);
|
||||
if (v.length === 2 || (v.length === 1 && Number(v) > 2)) minuteRef.current?.focus();
|
||||
}}
|
||||
/>
|
||||
<span className="birth-colon" aria-hidden="true">
|
||||
:
|
||||
</span>
|
||||
<label className="sr-only" htmlFor="calc-minute">
|
||||
Perc
|
||||
</label>
|
||||
<input
|
||||
id="calc-minute"
|
||||
ref={minuteRef}
|
||||
className="inp birth-time"
|
||||
inputMode="numeric"
|
||||
placeholder="perc"
|
||||
maxLength={2}
|
||||
value={timeUnknown ? "" : minute}
|
||||
disabled={timeUnknown}
|
||||
onChange={(e) => {
|
||||
setMinute(e.target.value.replace(/\D/g, ""));
|
||||
setAmbiguous(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" checked={timeUnknown} onChange={(e) => setTimeUnknown(e.target.checked)} />
|
||||
Nem tudom a születési időt
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div className="grid-2">
|
||||
<CountrySelect
|
||||
value={country}
|
||||
geoBase="/api/v1/public/geo"
|
||||
onChange={(c) => {
|
||||
setCountry(c);
|
||||
setPlace(null);
|
||||
}}
|
||||
/>
|
||||
<PlaceSearch country={country} value={place} onChange={setPlace} geoBase="/api/v1/public/geo" />
|
||||
</div>
|
||||
{ambiguous && (
|
||||
<fieldset className="field" style={{ border: 0, padding: 0, margin: 0 }}>
|
||||
<legend className="label" style={{ marginBottom: 8 }}>
|
||||
Melyik időpontban születtél?
|
||||
</legend>
|
||||
<label className="check">
|
||||
<input
|
||||
type="radio"
|
||||
name="calc-ambiguity"
|
||||
checked={ambiguity === "earlier"}
|
||||
onChange={() => setAmbiguity("earlier")}
|
||||
/>
|
||||
Az elsőben, még nyári időszámítás szerint
|
||||
</label>
|
||||
<label className="check">
|
||||
<input
|
||||
type="radio"
|
||||
name="calc-ambiguity"
|
||||
checked={ambiguity === "later"}
|
||||
onChange={() => setAmbiguity("later")}
|
||||
/>
|
||||
A másodikban, már téli időszámítás szerint
|
||||
</label>
|
||||
</fieldset>
|
||||
)}
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert" style={{ margin: 0 }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{result && (
|
||||
<section ref={resultRef} className="calc-result" aria-live="polite" aria-label="A születési horoszkópod">
|
||||
<ChartView result={result.result} birth={result.birth} />
|
||||
</section>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user