/aszcendens-kalkulator: Sun, Moon and Ascendant signs from birth data
without an account. A calculation only (no AI, nothing saved), limited to
30 calculations and 300 place searches an hour per visitor address
(POST /v1/public/signs, GET /v1/public/geo/*). Without a birth time there
is no Ascendant, and signs near a border are marked uncertain.
/csillagjegyek and /csillagjegyek/{jegy}: the twelve signs with facts,
Sun, Moon and Ascendant, love, work, a common misbelief and an offer,
each written on its own. Links to the calculator and sign-up.
SEO: metadataBase and canonical addresses, hreflang between the
Hungarian and English privacy pages, Organization and WebSite JSON-LD on
the home page, FAQPage on the calculator, BreadcrumbList on the sign
pages; the sitemap lists the new pages, the footers link them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
311 lines
11 KiB
TypeScript
311 lines
11 KiB
TypeScript
"use client";
|
||
|
||
import Link from "next/link";
|
||
import { useMemo, useRef, useState } from "react";
|
||
|
||
import { CountrySelect, PlaceSearch } from "@/app/profil/BirthForm";
|
||
import { ZODIAC_BY_ID } from "@/content/zodiac";
|
||
import { ApiError, api, errorText } from "@/lib/api";
|
||
import { SIGNS } from "@/lib/astro";
|
||
import { MONTHS, composeDate, composeTime, daysIn } from "@/lib/birth";
|
||
import type { Place } from "@/lib/types";
|
||
|
||
interface Sign {
|
||
sign: string;
|
||
degree: number | null;
|
||
uncertain: boolean;
|
||
}
|
||
interface Result {
|
||
sun: Sign;
|
||
moon: Sign;
|
||
ascendant: Sign | null;
|
||
time_known: boolean;
|
||
}
|
||
|
||
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.",
|
||
};
|
||
|
||
function SignCard({ label, anchor, sign, note }: { label: string; anchor: string; sign: Sign; note?: string }) {
|
||
const z = ZODIAC_BY_ID.get(sign.sign);
|
||
const s = SIGNS[sign.sign];
|
||
return (
|
||
<div className="card calc-sign">
|
||
<span className="eyebrow">{label}</span>
|
||
<div className="calc-sign-main">
|
||
<span className="calc-glyph" aria-hidden="true">
|
||
{s?.glyph}
|
||
</span>
|
||
<strong>{s?.hu ?? sign.sign}</strong>
|
||
{sign.degree !== null && <span className="muted">{sign.degree}°</span>}
|
||
</div>
|
||
{note && (
|
||
<p className="hint" style={{ margin: 0 }}>
|
||
{note}
|
||
</p>
|
||
)}
|
||
{z && (
|
||
<Link href={`/csillagjegyek/${z.slug}#${anchor}`} className="calc-sign-link">
|
||
Mit jelent? →
|
||
</Link>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** The public Sun, Moon and Ascendant calculator: a calculation only, nothing is saved and no AI is used. */
|
||
export function SignCalculator() {
|
||
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 | 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 r = await api<Result>("/public/signs", {
|
||
body: {
|
||
date,
|
||
...(timeUnknown ? {} : { time }),
|
||
country,
|
||
geonames_id: place.geonames_id,
|
||
...(ambiguous ? { ambiguous_time: ambiguity } : {}),
|
||
},
|
||
});
|
||
setResult(r);
|
||
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);
|
||
}
|
||
}
|
||
|
||
const uncertain = "A születési idő nélkül ez a jegy a nap elején vagy végén a szomszédos jegy is lehetett.";
|
||
|
||
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…" : "Kiszámolom"}
|
||
</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="Az eredmény">
|
||
<div className="calc-signs">
|
||
<SignCard
|
||
label="Napjegy"
|
||
anchor="nap"
|
||
sign={result.sun}
|
||
note={result.sun.uncertain ? uncertain : undefined}
|
||
/>
|
||
<SignCard
|
||
label="Holdjegy"
|
||
anchor="hold"
|
||
sign={result.moon}
|
||
note={result.moon.uncertain ? uncertain : undefined}
|
||
/>
|
||
{result.ascendant ? (
|
||
<SignCard label="Aszcendens" anchor="aszcendens" sign={result.ascendant} />
|
||
) : (
|
||
<div className="card calc-sign">
|
||
<span className="eyebrow">Aszcendens</span>
|
||
<p className="muted" style={{ margin: 0 }}>
|
||
Az aszcendens percről percre változik, ezért kiszámolásához pontos születési idő kell.
|
||
</p>
|
||
</div>
|
||
)}
|
||
</div>
|
||
<div className="card calc-cta">
|
||
<div>
|
||
<h2 style={{ margin: 0 }}>Ez csak három pont a képletedből</h2>
|
||
<p className="muted" style={{ margin: "6px 0 0" }}>
|
||
A teljes születési képleted mind a tíz bolygót, a házakat és a fényszögeket is mutatja, és ingyen kapsz
|
||
hozzá egy rövid, személyre szabott összefoglalót.
|
||
</p>
|
||
</div>
|
||
<Link href="/belepes?mod=regisztracio&vissza=/profil" className="btn btn-primary">
|
||
A teljes képletem ingyen
|
||
</Link>
|
||
</div>
|
||
</section>
|
||
)}
|
||
</>
|
||
);
|
||
}
|