From 912c94c2984b2239fe7cae45c8da31bdce34b2b3 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sat, 5 Sep 2026 13:45:57 +0700 Subject: [PATCH] fix(guide) : link catalog items correctly --- components/admin/guide-section-editor.tsx | 90 +---------------------- components/public/structured-guide.tsx | 73 +++++++++++++----- lib/guides/schemas.test.ts | 4 +- lib/guides/schemas.ts | 1 - 4 files changed, 55 insertions(+), 113 deletions(-) diff --git a/components/admin/guide-section-editor.tsx b/components/admin/guide-section-editor.tsx index 3afe964..cc2239f 100644 --- a/components/admin/guide-section-editor.tsx +++ b/components/admin/guide-section-editor.tsx @@ -269,7 +269,6 @@ type TeamValue = { let clientIdCounter = 0; const DEFAULT_EXTRA_BACKGROUND_COLOR = "#24232C"; -const DEFAULT_EXTRA_TEXT_COLOR = "#FAFAFA"; const RichTextEditor = dynamic( () => import("@/components/rich-text-editor").then((module) => module.RichTextEditor), { @@ -330,7 +329,6 @@ export interface GuideSectionEditorProps { body: string; percent: string | null; backgroundColor: string | null; - textColor: string | null; catalogItems: ExtraCatalogItem[]; highlights: Array<{ text: string; color: string }>; imageUrl: string | null; @@ -3438,7 +3436,6 @@ function ExtraEditor({ guide, initial, characters, weapons, artifacts }: EditorB ? null : Number(row.percent), backgroundColor: row.backgroundColor, - textColor: row.textColor, catalogItems: row.catalogItems, highlights: [], })), @@ -3471,7 +3468,6 @@ function ExtraEditor({ guide, initial, characters, weapons, artifacts }: EditorB id: row.id || createClientId("extra-row-record"), body: normalizeExtraRichText(row.body, row.highlights ?? []), backgroundColor: row.backgroundColor ?? null, - textColor: row.textColor ?? null, catalogItems: row.catalogItems ?? [], highlights: [], clientId: row.clientId || createClientId("extra-row"), @@ -3867,7 +3863,7 @@ function ExtraEditor({ guide, initial, characters, weapons, artifacts }: EditorB />
- สีการ์ด (optional) + สีพื้นหลังการ์ด (optional) สีจะใช้เฉพาะการ์ดนี้บนหน้า Guide @@ -3954,89 +3950,6 @@ function ExtraEditor({ guide, initial, characters, weapons, artifacts }: EditorB ใช้สีตามธีม - - สีข้อความ - { - if (row.textColor !== null) return; - setSections( - sections.map((item, index) => - index === sectionIndex - ? { - ...item, - rows: item.rows.map((candidate, inner) => - inner === rowIndex - ? { - ...candidate, - textColor: DEFAULT_EXTRA_TEXT_COLOR, - } - : candidate, - ), - } - : item, - ), - ); - }} - onChange={(event) => - setSections( - sections.map((item, index) => - index === sectionIndex - ? { - ...item, - rows: item.rows.map((candidate, inner) => - inner === rowIndex - ? { ...candidate, textColor: event.target.value } - : candidate, - ), - } - : item, - ), - ) - } - /> - -
@@ -4067,7 +3980,6 @@ function ExtraEditor({ guide, initial, characters, weapons, artifacts }: EditorB body: "", percent: null, backgroundColor: null, - textColor: null, catalogItems: [], highlights: [], clientId: createClientId("extra-row"), diff --git a/components/public/structured-guide.tsx b/components/public/structured-guide.tsx index bfb7af3..b6ab09d 100644 --- a/components/public/structured-guide.tsx +++ b/components/public/structured-guide.tsx @@ -1,10 +1,11 @@ import Image from "next/image"; import Link from "next/link"; import { ArrowUpRightIcon, ChevronLeftIcon } from "lucide-react"; -import type { CSSProperties, ReactNode } from "react"; +import type { ReactNode } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; +import { Kbd } from "@/components/ui/kbd"; import { Card, CardAction, @@ -313,6 +314,13 @@ function metric(value: string | null) { : `${Number(value).toLocaleString(undefined, { maximumFractionDigits: 2 })}%`; } +function lunarisItemUrl( + kind: "character" | "weapon" | "artifact", + key: string, +): string { + return `https://lunaris.moe/${kind}/${encodeURIComponent(key)}`; +} + function WeaponSection({ guide }: { guide: PublicGuide }) { return ; } @@ -435,7 +443,12 @@ function WeaponSectionContent({ : "md:grid-cols-[minmax(0,3fr)_minmax(0,1fr)]", )} > -
) : null}
- +
-
-
+ {!exporting ? ( + + + ) : null} + {row.second ? ( -
-
+ {!exporting ? ( + + + ) : null} + ) : null}
@@ -1180,16 +1213,7 @@ function ExtraSectionContent({ {row.imageUrl ? (
{row.catalogItems.map((item) => ( - + ))} ) : null} {row.heading} - + {row.percent ? {metric(row.percent)} : null} diff --git a/lib/guides/schemas.test.ts b/lib/guides/schemas.test.ts index f014727..71bee25 100644 --- a/lib/guides/schemas.test.ts +++ b/lib/guides/schemas.test.ts @@ -146,17 +146,15 @@ describe("structured guide validation", () => { body: "First line\nSecond line", percent: null, }; - const input = (style: { backgroundColor: string | null; textColor?: string | null; highlights: Array<{ text: string; color: string }> }) => ({ + const input = (style: { backgroundColor: string | null; highlights: Array<{ text: string; color: string }> }) => ({ expectedVersion: 1, sections: [{ title: "Extra", rows: [{ ...row, ...style }] }], }); expect(extraSectionSchema.safeParse(input({ backgroundColor: null, highlights: [] })).success).toBe(true); - expect(extraSectionSchema.safeParse(input({ backgroundColor: "#24232C", textColor: "#FAFAFA", highlights: [] })).success).toBe(true); expect(extraSectionSchema.safeParse(input({ backgroundColor: "#24232C", highlights: [{ text: "MASSIVE", color: "#FF0000" }] })).success).toBe(true); expect(extraSectionSchema.safeParse({ expectedVersion: 1, sections: [{ title: "Extra", rows: [row] }] }).success).toBe(true); expect(extraSectionSchema.safeParse(input({ backgroundColor: "red", highlights: [] })).success).toBe(false); - expect(extraSectionSchema.safeParse(input({ backgroundColor: null, textColor: "white", highlights: [] })).success).toBe(false); expect(extraSectionSchema.safeParse(input({ backgroundColor: null, highlights: [{ text: "MASSIVE", color: "red" }] })).success).toBe(false); expect(extraSectionSchema.safeParse(input({ backgroundColor: null, highlights: [{ text: "MASSIVE", color: "#FF0000" }, { text: "MASSIVE", color: "#00FF00" }] })).success).toBe(false); }); diff --git a/lib/guides/schemas.ts b/lib/guides/schemas.ts index 70a8acb..2006e02 100644 --- a/lib/guides/schemas.ts +++ b/lib/guides/schemas.ts @@ -140,7 +140,6 @@ const extraRowSchema = z.strictObject({ body: z.string().trim().max(10_000), percent: percent.nullable(), backgroundColor: hexColor.nullable().default(null), - textColor: hexColor.nullable().default(null), catalogItems: z.array(z.strictObject({ kind: z.enum(["character", "weapon", "artifact"]), key: z.string().trim().min(1).max(64),