Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d63cdf737a |
@@ -1104,3 +1104,13 @@ span.tarot-fan-card { cursor: default; }
|
|||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
.tarot-flip-inner, .tarot-fan-card, .tarot-demo-text { transition: none; animation: none; }
|
.tarot-flip-inner, .tarot-fan-card, .tarot-demo-text { transition: none; animation: none; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Birth date and time: our own Hungarian fields (not the browser's date and time inputs) */
|
||||||
|
.birth-fields { border: 0; margin: 0; padding: 0; min-width: 0; }
|
||||||
|
.birth-fields legend { padding: 0; margin-bottom: 8px; }
|
||||||
|
.birth-row { display: flex; align-items: center; gap: 8px; }
|
||||||
|
.birth-year { width: 5.5em; flex: none; }
|
||||||
|
.birth-month { flex: 1 1 auto; min-width: 0; }
|
||||||
|
.birth-day { width: 5.2em; flex: none; }
|
||||||
|
.birth-time { width: 4.4em; flex: none; text-align: center; }
|
||||||
|
.birth-colon { color: var(--muted); font-weight: 600; }
|
||||||
|
|||||||
@@ -16,6 +16,41 @@ const ERRORS: Record<string, string> = {
|
|||||||
invalid_date: "Érvénytelen dátum.",
|
invalid_date: "Érvénytelen dátum.",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MONTHS = [
|
||||||
|
"január",
|
||||||
|
"február",
|
||||||
|
"március",
|
||||||
|
"április",
|
||||||
|
"május",
|
||||||
|
"június",
|
||||||
|
"július",
|
||||||
|
"augusztus",
|
||||||
|
"szeptember",
|
||||||
|
"október",
|
||||||
|
"november",
|
||||||
|
"december",
|
||||||
|
];
|
||||||
|
|
||||||
|
const pad = (n: number) => String(n).padStart(2, "0");
|
||||||
|
const daysIn = (year: number, month: number) => new Date(Date.UTC(year || 2000, month, 0)).getUTCDate();
|
||||||
|
|
||||||
|
/** "YYYY-MM-DD" from the three fields, or null while it is not a real date. */
|
||||||
|
function composeDate(year: string, month: string, day: string): string | null {
|
||||||
|
const y = Number(year);
|
||||||
|
const m = Number(month);
|
||||||
|
const d = Number(day);
|
||||||
|
if (!/^\d{4}$/.test(year) || y < 1000 || !m || !d || d > daysIn(y, m)) return null;
|
||||||
|
return `${year}-${pad(m)}-${pad(d)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "HH:MM" from the two fields, or null while it is not a real time. */
|
||||||
|
function composeTime(hour: string, minute: string): string | null {
|
||||||
|
if (!/^\d{1,2}$/.test(hour) || !/^\d{1,2}$/.test(minute)) return null;
|
||||||
|
const h = Number(hour);
|
||||||
|
const m = Number(minute);
|
||||||
|
return h <= 23 && m <= 59 ? `${pad(h)}:${pad(m)}` : null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Someone else's chart: added with a name, or (with `chartId`) corrected. */
|
/** Someone else's chart: added with a name, or (with `chartId`) corrected. */
|
||||||
export type PersonTarget = { chartId?: string; name?: string };
|
export type PersonTarget = { chartId?: string; name?: string };
|
||||||
|
|
||||||
@@ -32,8 +67,16 @@ export function BirthForm({
|
|||||||
onSaved: (chartId: string) => void;
|
onSaved: (chartId: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const [name, setName] = useState(person?.name ?? "");
|
const [name, setName] = useState(person?.name ?? "");
|
||||||
const [date, setDate] = useState(initial?.date ?? "");
|
// Our own fields, not the browser's date and time inputs: those follow the
|
||||||
const [time, setTime] = useState(initial?.time?.slice(0, 5) ?? "");
|
// operating system's or the browser's region (US order, AM/PM in Safari).
|
||||||
|
const [year, setYear] = useState(initial?.date?.slice(0, 4) ?? "");
|
||||||
|
const [month, setMonth] = useState(initial?.date ? String(Number(initial.date.slice(5, 7))) : "");
|
||||||
|
const [day, setDay] = useState(initial?.date ? String(Number(initial.date.slice(8, 10))) : "");
|
||||||
|
const [hour, setHour] = useState(initial?.time?.slice(0, 2) ?? "");
|
||||||
|
const [minute, setMinute] = useState(initial?.time?.slice(3, 5) ?? "");
|
||||||
|
const minuteRef = useRef<HTMLInputElement>(null);
|
||||||
|
const date = composeDate(year, month, day) ?? "";
|
||||||
|
const time = composeTime(hour, minute) ?? "";
|
||||||
const [timeUnknown, setTimeUnknown] = useState(initial ? !initial.time : false);
|
const [timeUnknown, setTimeUnknown] = useState(initial ? !initial.time : false);
|
||||||
const [country, setCountry] = useState(initial?.country ?? "HU");
|
const [country, setCountry] = useState(initial?.country ?? "HU");
|
||||||
const [place, setPlace] = useState<Place | null>(
|
const [place, setPlace] = useState<Place | null>(
|
||||||
@@ -57,8 +100,11 @@ export function BirthForm({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setError(null);
|
setError(null);
|
||||||
if (person && !name.trim()) return setError("Add meg a nevét.");
|
if (person && !name.trim()) return setError("Add meg a nevét.");
|
||||||
if (!date) return setError("Add meg a születési dátumot.");
|
if (!year && !month && !day) return setError("Add meg a születési dátumot.");
|
||||||
if (!timeUnknown && !time) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod.");
|
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 && !hour && !minute) return setError("Add meg a születési időt, vagy jelöld, hogy nem tudod.");
|
||||||
|
if (!timeUnknown && !time) return setError("Ellenőrizd az időt: óra 0–23, perc 0–59.");
|
||||||
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try {
|
try {
|
||||||
@@ -120,37 +166,106 @@ export function BirthForm({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="grid-2">
|
<div className="grid-2">
|
||||||
<div className="field">
|
<fieldset className="field birth-fields">
|
||||||
<label htmlFor="birth-date">Születési dátum</label>
|
<legend className="label">Születési dátum</legend>
|
||||||
<input
|
<div className="birth-row">
|
||||||
id="birth-date"
|
<label className="sr-only" htmlFor="birth-year">
|
||||||
type="date"
|
Év
|
||||||
className="inp"
|
</label>
|
||||||
min="1000-01-01"
|
<input
|
||||||
max={today}
|
id="birth-year"
|
||||||
value={date}
|
className="inp birth-year"
|
||||||
onChange={(e) => setDate(e.target.value)}
|
inputMode="numeric"
|
||||||
required
|
autoComplete="bday-year"
|
||||||
/>
|
placeholder="év"
|
||||||
</div>
|
maxLength={4}
|
||||||
<div className="field">
|
value={year}
|
||||||
<label htmlFor="birth-time">Születési idő (helyi idő)</label>
|
onChange={(e) => setYear(e.target.value.replace(/\D/g, ""))}
|
||||||
<input
|
/>
|
||||||
id="birth-time"
|
<label className="sr-only" htmlFor="birth-month">
|
||||||
type="time"
|
Hónap
|
||||||
className="inp"
|
</label>
|
||||||
value={timeUnknown ? "" : time}
|
<select
|
||||||
disabled={timeUnknown}
|
id="birth-month"
|
||||||
onChange={(e) => {
|
className="inp birth-month"
|
||||||
setTime(e.target.value);
|
autoComplete="bday-month"
|
||||||
setAmbiguous(false);
|
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="birth-day">
|
||||||
|
Nap
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="birth-day"
|
||||||
|
className="inp birth-day"
|
||||||
|
autoComplete="bday-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="birth-hour">
|
||||||
|
Óra
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="birth-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);
|
||||||
|
// Two digits (or one that cannot start a valid hour): on to the minutes.
|
||||||
|
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="birth-minute">
|
||||||
|
Perc
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="birth-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">
|
<label className="check">
|
||||||
<input type="checkbox" checked={timeUnknown} onChange={(e) => setTimeUnknown(e.target.checked)} />
|
<input type="checkbox" checked={timeUnknown} onChange={(e) => setTimeUnknown(e.target.checked)} />
|
||||||
Nem tudom a születési időt
|
Nem tudom a születési időt
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid-2">
|
<div className="grid-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user