progmaweb
The site and account service of Progmasoft: a Next.js frontend and an ASP.NET Core API.
Clonegit clone https://git.progmasoft.com/progmaweb
Pick a policy by a condition rather than by an index
- Commit
39a301172c3752e7b22f9ea2c3a4b1d4c73cfeb1- Author
- Leitwolf11 ·
- Parents
53fb8b8bde85
Changes
apps/web/components/PolicyPage.tsx | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/web/components/PolicyPage.tsx b/apps/web/components/PolicyPage.tsx index c0e8eda..235a265 100644 --- a/apps/web/components/PolicyPage.tsx +++ b/apps/web/components/PolicyPage.tsx @@ -5,16 +5,31 @@ import type { Metadata } from "next"; import { Footer } from "@/components/Footer"; import { SiteHeader } from "@/components/SiteHeader"; import { getLocale } from "@/lib/locale.server"; -import { type PolicyKind, policyUrls, policyVersion } from "@/lib/policies"; +import { + type PolicyKind, + type PolicyMessages, + type PolicyText, + policyUrls, + policyVersion, +} from "@/lib/policies"; import { getPolicyMessages } from "@/lib/policy-messages"; +/** One policy and the other, with their addresses. */ +function select(messages: PolicyMessages, kind: PolicyKind) { + const privacy = { text: messages.privacy, url: policyUrls.privacy }; + const security = { text: messages.security, url: policyUrls.security }; + return kind === "privacy" + ? { policy: privacy, other: { ...security, path: "/security" } } + : { policy: security, other: { ...privacy, path: "/privacy" } }; +} + /** The title, description and canonical address of a policy page. */ export async function policyMetadata(kind: PolicyKind): Promise<Metadata> { - const policy = getPolicyMessages(await getLocale())[kind]; + const { policy } = select(getPolicyMessages(await getLocale()), kind); return { - title: policy.title, - description: policy.description, - alternates: { canonical: policyUrls[kind] }, + title: policy.text.title, + description: policy.text.description, + alternates: { canonical: policy.url }, }; } @@ -22,8 +37,9 @@ export async function policyMetadata(kind: PolicyKind): Promise<Metadata> { export async function PolicyPage({ kind }: { kind: PolicyKind }) { const locale = await getLocale(); const messages = getPolicyMessages(locale); - const policy = messages[kind]; - const other: PolicyKind = kind === "privacy" ? "security" : "privacy"; + const selected = select(messages, kind); + const policy: PolicyText = selected.policy.text; + const other = selected.other; return ( <div className="pm-page"> <SiteHeader locale={locale} /> @@ -49,8 +65,7 @@ export async function PolicyPage({ kind }: { kind: PolicyKind }) { </section> ))} <p className="pm-policy-see-also"> - {messages.seeAlso}:{" "} - <a href={`/${other}`}>{messages[other].title}</a> + {messages.seeAlso}: <a href={other.path}>{other.text.title}</a> </p> </article> </section>