All checks were successful
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
180 lines
5.8 KiB
TypeScript
180 lines
5.8 KiB
TypeScript
import { raw } from "hono/html";
|
||
import type { Child } from "hono/jsx";
|
||
import type { AgendaDay, AgendaItem } from "./agenda.js";
|
||
import { formatDayHeading, formatTime, LOCALES, type Locale, type MessageKey, t } from "./i18n.js";
|
||
import { styles } from "./styles.js";
|
||
|
||
type LayoutProps = { locale: Locale; showExamples: boolean; children?: Child };
|
||
|
||
function Layout({ locale, showExamples, children }: LayoutProps) {
|
||
return (
|
||
<html lang={locale}>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<meta name="robots" content="noindex" />
|
||
<title>{t(locale, "app.name")}</title>
|
||
<style>{raw(styles)}</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
<header class="top">
|
||
<span class="brand">{t(locale, "app.name")}</span>
|
||
<nav class="langs" aria-label={t(locale, "lang.label")}>
|
||
{LOCALES.map((code) => (
|
||
<a
|
||
href={`/?lang=${code}`}
|
||
lang={code}
|
||
aria-current={code === locale ? "true" : undefined}
|
||
>
|
||
{t(locale, `lang.${code}`)}
|
||
</a>
|
||
))}
|
||
</nav>
|
||
</header>
|
||
{showExamples && (
|
||
<p class="note warn" data-testid="mock-banner">
|
||
{t(locale, "mock.banner")}
|
||
</p>
|
||
)}
|
||
<main>{children}</main>
|
||
</div>
|
||
</body>
|
||
</html>
|
||
);
|
||
}
|
||
|
||
export const NOTICES = ["denied", "failed", "setup", "browser", "consent"] as const;
|
||
export type Notice = (typeof NOTICES)[number];
|
||
|
||
/** Календарь не подключён: что это, что сделать и что будет дальше. */
|
||
export function ConnectPage(props: {
|
||
locale: Locale;
|
||
isMock: boolean;
|
||
notice?: Notice | null;
|
||
/** Подключение не удалось уже не в первый раз: подсказка другая. */
|
||
repeated?: boolean;
|
||
/** Образец списка (у мока): показывается под кнопкой и помечен как образец. */
|
||
sample?: { days: AgendaDay[]; timeZone: string } | null;
|
||
}) {
|
||
const { locale, notice } = props;
|
||
return (
|
||
<Layout locale={locale} showExamples={Boolean(props.isMock && props.sample)}>
|
||
<div class="card">
|
||
<h1>{t(locale, "connect.title")}</h1>
|
||
<p class="lead">{t(locale, "connect.lead")}</p>
|
||
<p>{t(locale, "connect.steps")}</p>
|
||
<p>{t(locale, "connect.readonly")}</p>
|
||
{notice && (
|
||
<p class="note error inline" role="alert" data-testid="connect-error">
|
||
{t(locale, props.repeated ? `notice.${notice}.again` : `notice.${notice}`)}
|
||
</p>
|
||
)}
|
||
{notice && props.repeated && notice === "setup" ? (
|
||
<a class="link" href="/connect" data-testid="retry-link">
|
||
{t(locale, "reconnect.anyway")}
|
||
</a>
|
||
) : (
|
||
<a class="button" href="/connect">
|
||
{t(locale, notice ? "reconnect.button" : "connect.button")}
|
||
</a>
|
||
)}
|
||
</div>
|
||
{props.sample && (
|
||
<section class="sample" data-testid="sample" aria-label={t(locale, "sample.title")}>
|
||
<h2>{t(locale, "sample.title")}</h2>
|
||
<p class="lead">{t(locale, "sample.lead")}</p>
|
||
<DayList days={props.sample.days} locale={locale} timeZone={props.sample.timeZone} />
|
||
</section>
|
||
)}
|
||
</Layout>
|
||
);
|
||
}
|
||
|
||
/** Сообщение из двух фраз и одно действие. */
|
||
export function MessagePage(props: {
|
||
locale: Locale;
|
||
isMock: boolean;
|
||
title: MessageKey;
|
||
message: MessageKey;
|
||
action: { href: string; label: MessageKey };
|
||
}) {
|
||
const { locale } = props;
|
||
return (
|
||
<Layout locale={locale} showExamples={false}>
|
||
<div class="card">
|
||
<h1>{t(locale, props.title)}</h1>
|
||
<p role="alert">{t(locale, props.message)}</p>
|
||
<a class="button" href={props.action.href}>
|
||
{t(locale, props.action.label)}
|
||
</a>
|
||
</div>
|
||
</Layout>
|
||
);
|
||
}
|
||
|
||
function Item({ item, locale, timeZone }: { item: AgendaItem; locale: Locale; timeZone: string }) {
|
||
const when =
|
||
item.kind === "timed" && item.start
|
||
? formatTime(locale, item.start, timeZone)
|
||
: t(locale, item.kind === "ongoing" ? "agenda.ongoing" : "agenda.allDay");
|
||
return (
|
||
<li>
|
||
<span class="when">{when}</span>
|
||
<span class={item.title ? "what" : "what untitled"}>
|
||
{item.title ?? t(locale, "agenda.untitled")}
|
||
</span>
|
||
</li>
|
||
);
|
||
}
|
||
|
||
function DayList({
|
||
days,
|
||
locale,
|
||
timeZone,
|
||
}: {
|
||
days: AgendaDay[];
|
||
locale: Locale;
|
||
timeZone: string;
|
||
}) {
|
||
return (
|
||
<>
|
||
{days.map((day) => (
|
||
<section class="day">
|
||
<h2>{formatDayHeading(locale, day.key, day.offset)}</h2>
|
||
<ul class="items">
|
||
{day.items.map((item) => (
|
||
<Item item={item} locale={locale} timeZone={timeZone} />
|
||
))}
|
||
</ul>
|
||
</section>
|
||
))}
|
||
</>
|
||
);
|
||
}
|
||
|
||
/** Календарь подключён: список на 7 дней или сообщение о пустой неделе. Только просмотр. */
|
||
export function AgendaPage(props: {
|
||
locale: Locale;
|
||
isMock: boolean;
|
||
days: AgendaDay[];
|
||
timeZone: string;
|
||
}) {
|
||
const { locale, days, timeZone } = props;
|
||
return (
|
||
<Layout locale={locale} showExamples={props.isMock && days.length > 0}>
|
||
<h1>{t(locale, "agenda.title")}</h1>
|
||
<div class="status">{t(locale, "agenda.connected")}</div>
|
||
<p class="lead">{t(locale, "agenda.lead")}</p>
|
||
{days.length === 0 ? (
|
||
<div class="card empty">
|
||
<strong>{t(locale, "agenda.empty")}</strong>
|
||
<span class="lead">{t(locale, "agenda.emptyHint")}</span>
|
||
</div>
|
||
) : (
|
||
<DayList days={days} locale={locale} timeZone={timeZone} />
|
||
)}
|
||
</Layout>
|
||
);
|
||
}
|