first commit

This commit is contained in:
bobban committed 2026-10-22 21:00:25 +02:00
commit b7b0f253ce
85 files changed
+7560

No files matched your search

@@ -0,0 +1,40 @@
import { notFound } from "next/navigation";
import { PageBody, PageHeader } from "@/components/page";
import { TemplateEditor } from "@/components/template-editor";
import { getT } from "@/i18n/server";
import { templateKindFromSlug } from "@/lib/kinds";
import { requireBook } from "@/lib/session";
import { getPresets, getTemplate } from "@/lib/templates";
export default async function TemplateEditPage({
params,
searchParams,
}: {
params: Promise<{ bookId: string; kind: string }>;
searchParams: Promise<{ error?: string; saved?: string }>;
}) {
const { bookId, kind: slug } = await params;
const { error, saved } = await searchParams;
await requireBook(bookId);
const kind = templateKindFromSlug(slug);
if (!kind) notFound();
const { t, locale } = await getT();
const { fields, custom } = await getTemplate(bookId, kind, locale);
const presets = getPresets(kind, locale).map((p) => ({ ...p, label: t(`template.preset.${p.id}`) }));
const kindLabel = kind === "RELATION" ? t("relation.one") : t(`kind.${kind}.one`);
return (
<>
<PageHeader
title={`${t("template.edit")}: ${kindLabel}`}
pretitle={t("template.title")}
actions={<span className={`badge ${custom ? "bg-green-lt" : ""}`}>{custom ? t("template.custom") : t("template.standard")}</span>}
/>
<PageBody>
{error ? <div className="alert alert-danger">{t("template.invalid", { reason: error })}</div> : null}
{saved ? <div className="alert alert-success">{t("common.saved")}</div> : null}
<TemplateEditor bookId={bookId} kind={kind} initialFields={fields} custom={custom} presets={presets} />
</PageBody>
</>
);
}
+54
View File
@@ -0,0 +1,54 @@
import Link from "next/link";
import { IconChartDots3 } from "@tabler/icons-react";
import { kindIcons } from "@/components/kind-icons";
import { PageBody, PageHeader } from "@/components/page";
import { getT } from "@/i18n/server";
import { KINDS, templateSlug, type TemplateKind } from "@/lib/kinds";
import { requireBook } from "@/lib/session";
import { getTemplate } from "@/lib/templates";
export const metadata = { title: "Mallar" };
export default async function TemplatesPage({ params }: { params: Promise<{ bookId: string }> }) {
const { bookId } = await params;
await requireBook(bookId);
const { t, locale } = await getT();
const kinds: { kind: TemplateKind; color: string }[] = [
...KINDS.map(({ kind, color }) => ({ kind: kind as TemplateKind, color })),
{ kind: "RELATION", color: "azure" },
];
const templates = await Promise.all(kinds.map(async (k) => ({ ...k, ...(await getTemplate(bookId, k.kind, locale)) })));
return (
<>
<PageHeader title={t("template.title")} />
<PageBody>
<p className="text-secondary">{t("template.intro")}</p>
<div className="row row-cards">
{templates.map(({ kind, color, fields, custom }) => {
const Icon = kind === "RELATION" ? IconChartDots3 : kindIcons[kind];
return (
<div className="col-md-6 col-xl-4" key={kind}>
<Link href={`/books/${bookId}/templates/${templateSlug(kind)}`} className="card card-link card-link-pop h-100">
<div className="card-body d-flex align-items-center gap-3">
<span className={`avatar bg-${color}-lt`}>
<Icon size={22} />
</span>
<div>
<div className="fw-bold">{kind === "RELATION" ? t("relation.one") : t(`kind.${kind}.one`)}</div>
<div className="text-secondary">{t("template.fields", { n: fields.length })}</div>
</div>
<span className={`badge ms-auto ${custom ? "bg-green-lt" : ""}`}>
{custom ? t("template.custom") : t("template.standard")}
</span>
</div>
</Link>
</div>
);
})}
</div>
</PageBody>
</>
);
}