84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
"use client";
|
||||
|
|
|
|||
|
|
import { useState } from "react";
|
|||
|
|
|
|||
|
|
import { countryName, formatBirthDate } from "@/lib/astro";
|
|||
|
|
import type { BirthData } from "@/lib/types";
|
|||
|
|
|
|||
|
|
import { BirthForm } from "./BirthForm";
|
|||
|
|
|
|||
|
|
export interface SavedBirth {
|
|||
|
|
birth: BirthData;
|
|||
|
|
placeName: string | null;
|
|||
|
|
region: string | null;
|
|||
|
|
countryCode: string | null;
|
|||
|
|
zone: string;
|
|||
|
|
utcOffset: string;
|
|||
|
|
dst: boolean;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** Shows the saved birth data (and the chart tables), or the form to enter or correct it. */
|
|||
|
|
export function BirthEditor({ chart, children }: { chart: SavedBirth | null; children: React.ReactNode }) {
|
|||
|
|
const [editing, setEditing] = useState(chart === null);
|
|||
|
|
|
|||
|
|
if (editing || !chart) {
|
|||
|
|
return (
|
|||
|
|
<div className="field" style={{ gap: 16 }}>
|
|||
|
|
{chart ? (
|
|||
|
|
<p className="muted">
|
|||
|
|
A javított adatokból új képlet készül, és az lesz a saját képleted. A régit a meglévő összevetések miatt
|
|||
|
|
megtartjuk.
|
|||
|
|
</p>
|
|||
|
|
) : (
|
|||
|
|
<p className="muted">
|
|||
|
|
Add meg a születésed adatait. Ebből számoljuk a képletedet; a helyi időt és az akkori időzónát (nyári
|
|||
|
|
időszámítást) a születési hely alapján magunk határozzuk meg.
|
|||
|
|
</p>
|
|||
|
|
)}
|
|||
|
|
<BirthForm
|
|||
|
|
initial={chart ? { ...chart.birth, placeName: chart.placeName, region: chart.region } : null}
|
|||
|
|
onCancel={chart ? () => setEditing(false) : undefined}
|
|||
|
|
onSaved={() => setEditing(false)}
|
|||
|
|
/>
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const { birth } = chart;
|
|||
|
|
const country = chart.countryCode ?? birth.country;
|
|||
|
|
return (
|
|||
|
|
<div className="field" style={{ gap: 24 }}>
|
|||
|
|
<div className="card-head" style={{ alignItems: "flex-start" }}>
|
|||
|
|
<dl className="facts">
|
|||
|
|
<dt>Dátum</dt>
|
|||
|
|
<dd>{formatBirthDate(birth.date)}</dd>
|
|||
|
|
<dt>Időpont</dt>
|
|||
|
|
<dd>
|
|||
|
|
{birth.time ? (
|
|||
|
|
<>
|
|||
|
|
{birth.time.slice(0, 5)}{" "}
|
|||
|
|
<span className="muted">
|
|||
|
|
({chart.zone}, UTC{chart.utcOffset}
|
|||
|
|
{chart.dst ? ", nyári idő" : ""})
|
|||
|
|
</span>
|
|||
|
|
</>
|
|||
|
|
) : (
|
|||
|
|
<span className="muted">ismeretlen</span>
|
|||
|
|
)}
|
|||
|
|
</dd>
|
|||
|
|
<dt>Hely</dt>
|
|||
|
|
<dd>
|
|||
|
|
{chart.placeName ?? birth.place ?? "–"}
|
|||
|
|
{chart.region && <span className="muted">, {chart.region}</span>}
|
|||
|
|
{country && <span className="muted">, {countryName(country)}</span>}
|
|||
|
|
</dd>
|
|||
|
|
</dl>
|
|||
|
|
<button type="button" className="btn" onClick={() => setEditing(true)}>
|
|||
|
|
Adatok javítása
|
|||
|
|
</button>
|
|||
|
|
</div>
|
|||
|
|
{children}
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
}
|