diff --git a/components/admin/delete-confirmation-dialog.tsx b/components/admin/delete-confirmation-dialog.tsx index 7addc12..f1cb8df 100644 --- a/components/admin/delete-confirmation-dialog.tsx +++ b/components/admin/delete-confirmation-dialog.tsx @@ -37,7 +37,9 @@ export function DeleteConfirmationDialog({ }: DeleteConfirmationDialogProps) { return ( - {trigger ? {children} : null} + {trigger ? ( + {children} + ) : null} {title} @@ -45,7 +47,9 @@ export function DeleteConfirmationDialog({ ยกเลิก - {confirmLabel} + + {confirmLabel} + diff --git a/components/admin/editor-inspector.tsx b/components/admin/editor-inspector.tsx index 31752bf..72750eb 100644 --- a/components/admin/editor-inspector.tsx +++ b/components/admin/editor-inspector.tsx @@ -104,32 +104,48 @@ export function EditorInspector({ - Inspector - Live Preview + + Inspector + + + Live Preview + {selected ? ( - {blockLabels[selected.type] ?? selected.type} - {selected.id} + + {blockLabels[selected.type] ?? selected.type} + + + {selected.id} + ความกว้าง | undefined)?.width ?? "content")} + value={String( + ( + selected.responsiveLayout as + | Record + | undefined + )?.width ?? "content", + )} onValueChange={(width) => patchSelected({ responsiveLayout: { - ...(selected.responsiveLayout as object ?? {}), + ...((selected.responsiveLayout as object) ?? {}), width, }, }) } > - + + + คอลัมน์อ่านง่าย พื้นที่กว้าง @@ -140,14 +156,22 @@ export function EditorInspector({ ซ่อนบนมือถือ - เนื้อหานี้จะเริ่มแสดงตั้งแต่หน้าจอแท็บเล็ต + + เนื้อหานี้จะเริ่มแสดงตั้งแต่หน้าจอแท็บเล็ต + | undefined)?.hideOnMobile)} + checked={Boolean( + ( + selected.responsiveLayout as + | Record + | undefined + )?.hideOnMobile, + )} onCheckedChange={(hideOnMobile) => patchSelected({ responsiveLayout: { - ...(selected.responsiveLayout as object ?? {}), + ...((selected.responsiveLayout as object) ?? {}), hideOnMobile, }, }) @@ -175,7 +199,10 @@ export function EditorInspector({ )} - + @@ -200,12 +227,18 @@ function AdvancedBlockSettings({ แหล่งข้อมูล onConfigChange({ ...config, dataSourceId })} + onValueChange={(dataSourceId) => + onConfigChange({ ...config, dataSourceId }) + } > - + + + {Object.values(sources).map((source) => ( - {source.name} · v{source.version} + + {source.name} · v{source.version} + ))} @@ -226,7 +259,11 @@ function DataSourceEditor({ }) { const [rowId, setRowId] = useState(null); const evaluated = useMemo(() => { - try { return evaluateDataSource(source); } catch { return null; } + try { + return evaluateDataSource(source); + } catch { + return null; + } }, [source]); const selectedRow = source.rows.find((row) => row.id === rowId); const formulaFields = source.fields.filter((field) => field.formula); @@ -246,10 +283,13 @@ function DataSourceEditor({ {source.name} - แหล่งข้อมูลทั่วโลก · เวอร์ชัน {source.version} + + แหล่งข้อมูลทั่วโลก · เวอร์ชัน {source.version} + - {saving ? "กำลังบันทึก" : "บันทึกข้อมูล"} + + {saving ? "กำลังบันทึก" : "บันทึกข้อมูล"} @@ -257,9 +297,15 @@ function DataSourceEditor({ const cell = previewRow?.cells[field.key]; return ( - {field.label} + + {field.label} + - fx + + + fx + + updateField(field.key, event.target.value)} /> - + + + - {source.fields.filter((candidate) => candidate.key !== field.key).map((candidate) => {candidate.label})} + {source.fields + .filter((candidate) => candidate.key !== field.key) + .map((candidate) => ( + + {candidate.label} + + ))} - {cell?.error ? สูตรนี้ยังคำนวณไม่ได้: ตรวจสอบชื่อฟิลด์และตัวหาร : ตัวอย่างผลลัพธ์: {cell?.display ?? "-"}} + {cell?.error ? ( + + สูตรนี้ยังคำนวณไม่ได้: ตรวจสอบชื่อฟิลด์และตัวหาร + + ) : ( + + ตัวอย่างผลลัพธ์:{" "} + + {cell?.display ?? "-"} + + + )} ); })} - {source.fields.slice(0, 3).map((field) => {field.label})} - {source.rows.slice(0, 10).map((row) => {source.fields.slice(0, 3).map((field) => {row.values[field.key] ?? previewRow?.cells[field.key]?.display ?? "-"})} setRowId(row.id)}>แก้ไข)} + + + {source.fields.slice(0, 3).map((field) => ( + {field.label} + ))} + + + + + {source.rows.slice(0, 10).map((row) => ( + + {source.fields.slice(0, 3).map((field) => ( + + {row.values[field.key] ?? + previewRow?.cells[field.key]?.display ?? + "-"} + + ))} + + setRowId(row.id)} + > + แก้ไข + + + + ))} + { const id = crypto.randomUUID(); - onChange({ ...source, rows: [...source.rows, { id, values: Object.fromEntries(source.fields.map((field) => [field.key, null])) }] }); + onChange({ + ...source, + rows: [ + ...source.rows, + { + id, + values: Object.fromEntries( + source.fields.map((field) => [field.key, null]), + ), + }, + ], + }); setRowId(id); }} - >เพิ่มแถว + > + + เพิ่มแถว + - { if (!open) setRowId(null); }}> + { + if (!open) setRowId(null); + }} + > แก้ไขแถวข้อมูล - กรอกค่าต้นทาง ระบบจะคำนวณฟิลด์สูตรให้อัตโนมัติ + + กรอกค่าต้นทาง ระบบจะคำนวณฟิลด์สูตรให้อัตโนมัติ + {selectedRow ? ( {source.fields.map((field) => ( - {field.label} + + {field.label} + onChange({ - ...source, - rows: source.rows.map((row) => row.id === selectedRow.id ? { ...row, values: { ...row.values, [field.key]: event.target.value || null } } : row), - })} + onChange={(event) => + onChange({ + ...source, + rows: source.rows.map((row) => + row.id === selectedRow.id + ? { + ...row, + values: { + ...row.values, + [field.key]: event.target.value || null, + }, + } + : row, + ), + }) + } /> ))} ) : null} - setRowId(null)}>เสร็จสิ้น + + setRowId(null)}>เสร็จสิ้น + diff --git a/components/admin/guide-overview-form.tsx b/components/admin/guide-overview-form.tsx index af11921..4dd142e 100644 --- a/components/admin/guide-overview-form.tsx +++ b/components/admin/guide-overview-form.tsx @@ -6,19 +6,49 @@ import { useState } from "react"; import { saveGuideOverview } from "@/app/admin/actions"; import { AutosaveStatus } from "@/components/admin/autosave-status"; import { MediaUploader } from "@/components/admin/media-uploader"; -import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; -import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"; +import { + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Field, + FieldDescription, + FieldError, + FieldGroup, + FieldLabel, +} from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { useAutosave } from "@/hooks/use-autosave"; import { adminDraftKey } from "@/lib/editor/local-draft"; import { parseYouTubeUrl } from "@/lib/guides/youtube"; -export function GuideOverviewForm({ guide }: { guide: { id: string; version: number; overview: string; youtubeUrl: string | null; coverMediaId: string; coverUrl: string; name: string } }) { +export function GuideOverviewForm({ + guide, +}: { + guide: { + id: string; + version: number; + overview: string; + youtubeUrl: string | null; + coverMediaId: string; + coverUrl: string; + name: string; + }; +}) { const [overview, setOverview] = useState(guide.overview); const [youtubeUrl, setYoutubeUrl] = useState(guide.youtubeUrl ?? ""); - const [cover, setCover] = useState({ id: guide.coverMediaId, url: guide.coverUrl }); - const invalidYoutubeUrl = Boolean(youtubeUrl.trim() && !parseYouTubeUrl(youtubeUrl.trim())); + const [cover, setCover] = useState({ + id: guide.coverMediaId, + url: guide.coverUrl, + }); + const invalidYoutubeUrl = Boolean( + youtubeUrl.trim() && !parseYouTubeUrl(youtubeUrl.trim()), + ); const value = { coverMediaId: cover.id, overview, youtubeUrl }; const incompleteIssues = [ !cover.id ? "กรุณาอัปโหลด Guide Image" : null, @@ -30,19 +60,34 @@ export function GuideOverviewForm({ guide }: { guide: { id: string; version: num value, valid: Boolean(cover.id && overview.trim() && !invalidYoutubeUrl), initialVersion: guide.version, - persist: (next, expectedVersion) => saveGuideOverview(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveGuideOverview(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "overview"), localDraft, parseLocalDraft: (candidate) => { if (!candidate || typeof candidate !== "object") return null; const draft = candidate as Record; - if (typeof draft.overview !== "string" || !draft.cover || typeof draft.cover !== "object") return null; + if ( + typeof draft.overview !== "string" || + !draft.cover || + typeof draft.cover !== "object" + ) + return null; const draftCover = draft.cover as Record; - if (typeof draftCover.id !== "string" || typeof draftCover.url !== "string") return null; - if (draft.youtubeUrl !== undefined && typeof draft.youtubeUrl !== "string") return null; + if ( + typeof draftCover.id !== "string" || + typeof draftCover.url !== "string" + ) + return null; + if ( + draft.youtubeUrl !== undefined && + typeof draft.youtubeUrl !== "string" + ) + return null; return { overview: draft.overview, - youtubeUrl: typeof draft.youtubeUrl === "string" ? draft.youtubeUrl : "", + youtubeUrl: + typeof draft.youtubeUrl === "string" ? draft.youtubeUrl : "", cover: { id: draftCover.id, url: draftCover.url }, }; }, @@ -52,5 +97,68 @@ export function GuideOverviewForm({ guide }: { guide: { id: string; version: num setCover(draft.cover); }, }); - return Overviewภาพ ข้อความ และวิดีโอนี้แสดงบนหน้าแรกของ GuideGuide Image setCover(asset)} />Overview setOverview(event.target.value)} />{overview.length}/500 ตัวอักษรYouTube video link setYoutubeUrl(event.target.value)} />ไม่บังคับ รองรับลิงก์ YouTube, youtu.be, Shorts และ Live{invalidYoutubeUrl ? กรุณาใส่ลิงก์วิดีโอ YouTube ที่ถูกต้อง : null}; + return ( + + + Overview + + ภาพ ข้อความ และวิดีโอนี้แสดงบนหน้าแรกของ Guide + + + + + + Guide Image + + + + setCover(asset)} /> + + + Overview + setOverview(event.target.value)} + /> + {overview.length}/500 ตัวอักษร + + + + YouTube video link + + setYoutubeUrl(event.target.value)} + /> + + ไม่บังคับ รองรับลิงก์ YouTube, youtu.be, Shorts และ Live + + {invalidYoutubeUrl ? ( + กรุณาใส่ลิงก์วิดีโอ YouTube ที่ถูกต้อง + ) : null} + + + + + + + + ); } diff --git a/components/admin/guide-section-editor.tsx b/components/admin/guide-section-editor.tsx index 103ce6a..0a853cb 100644 --- a/components/admin/guide-section-editor.tsx +++ b/components/admin/guide-section-editor.tsx @@ -47,21 +47,47 @@ import { import { AutosaveStatus } from "@/components/admin/autosave-status"; import { DeleteConfirmationDialog } from "@/components/admin/delete-confirmation-dialog"; import { MediaUploader } from "@/components/admin/media-uploader"; -import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { - Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, + Card, + CardAction, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, } from "@/components/ui/card"; import { - Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, + Combobox, + ComboboxContent, + ComboboxEmpty, + ComboboxInput, + ComboboxItem, + ComboboxList, } from "@/components/ui/combobox"; import { - Field, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, + Field, + FieldDescription, + FieldGroup, + FieldLabel, + FieldLegend, + FieldSet, } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { - Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { Toggle } from "@/components/ui/toggle"; @@ -93,31 +119,107 @@ import { type TalentPriority, type TalentRelation, } from "@/lib/guides/talents"; -import { finalizePercentInput, normalizePercentInput } from "@/lib/guides/percent-input"; +import { + finalizePercentInput, + normalizePercentInput, +} from "@/lib/guides/percent-input"; import { formatGuideValidationIssues } from "@/lib/guides/validation-messages"; import { cn } from "@/lib/utils"; -type CatalogItem = { key: string; name: string; imageUrl: string; rarity?: number | null; weaponType?: string | null }; -type Guide = { id: string; characterKey: string; version: number; name: string }; -type WeaponValue = { id: string; weaponKey: string; refinement: number; overallPercent: string | null; personalPercent: string | null; note: string | null; weapon: CatalogItem }; -type ArtifactValue = { id: string; name: string; rows: Array<{ firstArtifactKey: string; secondArtifactKey: string | null; percent: string; note: string | null }> }; -type ArtifactProfile = { sands: string[]; goblet: string[]; circlet: string[]; substats: string[]; targets: Array<{ stat: string; value: string }>; talents: TalentPriority[]; note: string | null } | null; -type ConstellationValue = { level: number; detail: string; cumulativePercent: string; isGreat: boolean }; -type ConstellationGroupValue = { id: string; note: string | null; rows: ConstellationValue[] }; -type CatalogConstellation = { level: number; name: string; description: string; iconUrl: string | null }; -type CatalogTalent = { type: "NA" | "E" | "Q"; name: string; iconUrl: string | null }; -type TeamValue = { id: string; title: string; rotationSeconds: string; combo: string; members: Array<{ characterKey: string; weaponKey: string | null; artifactKey: string | null; secondArtifactKey: string | null; constellation: number; refinement: number; damage: string }> }; +type CatalogItem = { + key: string; + name: string; + imageUrl: string; + rarity?: number | null; + weaponType?: string | null; +}; +type Guide = { + id: string; + characterKey: string; + version: number; + name: string; +}; +type WeaponValue = { + id: string; + weaponKey: string; + refinement: number; + overallPercent: string | null; + personalPercent: string | null; + note: string | null; + weapon: CatalogItem; +}; +type ArtifactValue = { + id: string; + name: string; + rows: Array<{ + firstArtifactKey: string; + secondArtifactKey: string | null; + percent: string; + note: string | null; + }>; +}; +type ArtifactProfile = { + sands: string[]; + goblet: string[]; + circlet: string[]; + substats: string[]; + targets: Array<{ stat: string; value: string }>; + talents: TalentPriority[]; + note: string | null; +} | null; +type ConstellationValue = { + level: number; + detail: string; + cumulativePercent: string; + isGreat: boolean; +}; +type ConstellationGroupValue = { + id: string; + note: string | null; + rows: ConstellationValue[]; +}; +type CatalogConstellation = { + level: number; + name: string; + description: string; + iconUrl: string | null; +}; +type CatalogTalent = { + type: "NA" | "E" | "Q"; + name: string; + iconUrl: string | null; +}; +type TeamValue = { + id: string; + title: string; + rotationSeconds: string; + combo: string; + members: Array<{ + characterKey: string; + weaponKey: string | null; + artifactKey: string | null; + secondArtifactKey: string | null; + constellation: number; + refinement: number; + damage: string; + }>; +}; let clientIdCounter = 0; function createClientId(prefix: string): string { const browserCrypto = globalThis.crypto; - if (typeof browserCrypto?.randomUUID === "function") return `${prefix}-${browserCrypto.randomUUID()}`; + if (typeof browserCrypto?.randomUUID === "function") + return `${prefix}-${browserCrypto.randomUUID()}`; clientIdCounter += 1; return `${prefix}-${Date.now()}-${clientIdCounter}`; } -function parseEditorDraft(value: unknown, arrayKeys: string[], stringKeys: string[] = []): Draft | null { +function parseEditorDraft( + value: unknown, + arrayKeys: string[], + stringKeys: string[] = [], +): Draft | null { if (!value || typeof value !== "object") return null; const record = value as Record; if (arrayKeys.some((key) => !Array.isArray(record[key]))) return null; @@ -140,24 +242,91 @@ export interface GuideSectionEditorProps { artifactProfile: ArtifactProfile; constellationGroups: ConstellationGroupValue[]; teams: TeamValue[]; - extras: Array<{ title: string; rows: Array<{ mediaId: string | null; ratio: "1:1" | "16:9"; heading: string; body: string; percent: string | null; imageUrl: string | null }> }>; + extras: Array<{ + title: string; + rows: Array<{ + mediaId: string | null; + ratio: "1:1" | "16:9"; + heading: string; + body: string; + percent: string | null; + imageUrl: string | null; + }>; + }>; }; } -const SELECTED_TOGGLE_CLASS = "aria-pressed:border-primary aria-pressed:ring-2 aria-pressed:ring-primary/30"; +const SELECTED_TOGGLE_CLASS = + "aria-pressed:border-primary aria-pressed:ring-2 aria-pressed:ring-primary/30"; -function CatalogPicker({ items, value, onChange, placeholder, rarityBackground = false, showSelectedImage = false }: { items: CatalogItem[]; value: string; onChange: (value: string) => void; placeholder: string; rarityBackground?: boolean; showSelectedImage?: boolean }) { +function CatalogPicker({ + items, + value, + onChange, + placeholder, + rarityBackground = false, + showSelectedImage = false, +}: { + items: CatalogItem[]; + value: string; + onChange: (value: string) => void; + placeholder: string; + rarityBackground?: boolean; + showSelectedImage?: boolean; +}) { const selected = items.find((item) => item.key === value) ?? null; return ( - {showSelectedImage && selected ? : null} + {showSelectedImage && selected ? ( + + + + ) : null} - onChange(next?.key ?? "")} itemToStringLabel={(item) => item.name} itemToStringValue={(item) => item.key} autoHighlight> - + onChange(next?.key ?? "")} + itemToStringLabel={(item) => item.name} + itemToStringValue={(item) => item.key} + autoHighlight + > + ไม่พบรายการ - {(item) => {item.name}} + {(item) => ( + + + + + {item.name} + + )} @@ -166,13 +335,47 @@ function CatalogPicker({ items, value, onChange, placeholder, rarityBackground = ); } -function StatSelect({ label, options, value, max, onChange }: { label: string; options: readonly string[]; value: string[]; max: number; onChange: (value: string[]) => void }) { +function StatSelect({ + label, + options, + value, + max, + onChange, +}: { + label: string; + options: readonly string[]; + value: string[]; + max: number; + onChange: (value: string[]) => void; +}) { return ( {label} - { if (next.length <= max) onChange(next); }}> - - {options.map((option) => = max && !value.includes(option)}>{option})} + { + if (next.length <= max) onChange(next); + }} + > + + + + + + + {options.map((option) => ( + = max && !value.includes(option)} + > + + {option} + + ))} + + เลือกได้สูงสุด {max} ค่า @@ -187,27 +390,66 @@ function StatIcons({ values }: { values: readonly string[] }) { return recommendedIcon ? [recommendedIcon] : []; }); if (!iconNames.length) return null; - return {iconNames.map((iconName) => )}; + return ( + + {iconNames.map((iconName) => ( + + ))} + + ); } function StatIcon({ iconName }: { iconName: string }) { const [hasError, setHasError] = useState(false); if (hasError) { - const PlaceholderIcon = iconName === "healing-bonus" ? HeartPulseIcon : SparklesIcon; - return ; + const PlaceholderIcon = + iconName === "healing-bonus" ? HeartPulseIcon : SparklesIcon; + return ( + + ); } - return setHasError(true)} />; + return ( + setHasError(true)} + /> + ); } -function TalentLevelPicker({ value, onChange }: { value?: string; onChange: (value?: string) => void }) { +function TalentLevelPicker({ + value, + onChange, +}: { + value?: string; + onChange: (value?: string) => void; +}) { const selected = talentLevelOptions.find((level) => level === value) ?? null; return ( - onChange(next ?? undefined)}> - + onChange(next ?? undefined)} + > + ไม่พบระดับ - {(level) => ระดับ {level}} + {(level) => ( + + ระดับ {level} + + )} @@ -223,7 +465,14 @@ function SortableTalentCard({ catalogTalent?: CatalogTalent; onLevelChange: (level?: string) => void; }) { - const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: talent.type }); + const { + attributes, + listeners, + setNodeRef, + transform, + transition, + isDragging, + } = useSortable({ id: talent.type }); return ( - {catalogTalent?.iconUrl ? : null} - {talent.type}. {catalogTalent?.name ?? talent.type} + {catalogTalent?.iconUrl ? ( + + ) : null} + + {talent.type}. {catalogTalent?.name ?? talent.type} + - + - ลากเพื่อจัดลำดับ {catalogTalent?.name ?? talent.type} + + ลากเพื่อจัดลำดับ {catalogTalent?.name ?? talent.type} + @@ -252,8 +520,21 @@ function SortableTalentCard({ ); } -function SortableWeaponCard({ id, children }: { id: string; children: (dragHandle: ReactNode) => ReactNode }) { - const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id }); +function SortableWeaponCard({ + id, + children, +}: { + id: string; + children: (dragHandle: ReactNode) => ReactNode; +}) { + const { + attributes, + listeners, + setNodeRef, + transform, + transition, + isDragging, + } = useSortable({ id }); return ( {children( - + ลากเพื่อจัดลำดับอาวุธ , @@ -270,8 +558,21 @@ function SortableWeaponCard({ id, children }: { id: string; children: (dragHandl ); } -function SortableArtifactRow({ id, children }: { id: string; children: (dragHandle: ReactNode) => ReactNode }) { - const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id }); +function SortableArtifactRow({ + id, + children, +}: { + id: string; + children: (dragHandle: ReactNode) => ReactNode; +}) { + const { + attributes, + listeners, + setNodeRef, + transform, + transition, + isDragging, + } = useSortable({ id }); return ( {children( - + ลากเพื่อจัดลำดับ Artifact , @@ -288,8 +596,21 @@ function SortableArtifactRow({ id, children }: { id: string; children: (dragHand ); } -function SortableTeamItem({ id, children }: { id: string; children: (dragHandle: ReactNode) => ReactNode }) { - const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id }); +function SortableTeamItem({ + id, + children, +}: { + id: string; + children: (dragHandle: ReactNode) => ReactNode; +}) { + const { + attributes, + listeners, + setNodeRef, + transform, + transition, + isDragging, + } = useSortable({ id }); return ( {children( - + ลากเพื่อจัดลำดับ Team , @@ -312,7 +640,9 @@ export function GuideSectionEditor(props: GuideSectionEditorProps) { {props.section === "weapon" ? : null} {props.section === "artifact" ? : null} - {props.section === "constellations" ? : null} + {props.section === "constellations" ? ( + + ) : null} {props.section === "team" ? : null} {props.section === "extra" ? : null} @@ -322,26 +652,60 @@ export function GuideSectionEditor(props: GuideSectionEditorProps) { type EditorBase = GuideSectionEditorProps; function WeaponEditor({ guide, weapons, characters, initial }: EditorBase) { - const characterWeaponType = characters.find((character) => character.key === guide.characterKey)?.weaponType; - const compatibleWeapons = weapons.filter((weapon) => supportsWeaponType(characterWeaponType, weapon.weaponType)); + const characterWeaponType = characters.find( + (character) => character.key === guide.characterKey, + )?.weaponType; + const compatibleWeapons = weapons.filter((weapon) => + supportsWeaponType(characterWeaponType, weapon.weaponType), + ); const weaponSensors = useSensors( useSensor(PointerSensor), - useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), + useSensor(KeyboardSensor, { + coordinateGetter: sortableKeyboardCoordinates, + }), ); const [note, setNote] = useState(initial.sectionNote ?? ""); - const [rows, setRows] = useState(initial.weapons.map((row) => ({ clientId: row.id, weaponKey: row.weaponKey, refinement: row.refinement, overallPercent: row.overallPercent ?? "", personalPercent: row.personalPercent ?? "", note: row.note ?? "" }))); - const value = { note: note.trim() || null, rows: rows.map((row) => ({ weaponKey: row.weaponKey, refinement: row.refinement, overallPercent: row.overallPercent === "" ? null : Number(row.overallPercent), personalPercent: row.personalPercent === "" ? null : Number(row.personalPercent), note: row.note.trim() || null })) }; - const validation = weaponSectionSchema.safeParse({ ...value, expectedVersion: guide.version }); + const [rows, setRows] = useState( + initial.weapons.map((row) => ({ + clientId: row.id, + weaponKey: row.weaponKey, + refinement: row.refinement, + overallPercent: row.overallPercent ?? "", + personalPercent: row.personalPercent ?? "", + note: row.note ?? "", + })), + ); + const value = { + note: note.trim() || null, + rows: rows.map((row) => ({ + weaponKey: row.weaponKey, + refinement: row.refinement, + overallPercent: + row.overallPercent === "" ? null : Number(row.overallPercent), + personalPercent: + row.personalPercent === "" ? null : Number(row.personalPercent), + note: row.note.trim() || null, + })), + }; + const validation = weaponSectionSchema.safeParse({ + ...value, + expectedVersion: guide.version, + }); const localDraft = { note, rows }; const autosave = useAutosave({ value, valid: validation.success, initialVersion: guide.version, - persist: (next, expectedVersion) => saveWeaponSection(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveWeaponSection(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "weapon"), localDraft, - parseLocalDraft: (candidate) => parseEditorDraft(candidate, ["rows"], ["note"]), - restoreLocalDraft: (draft) => { setNote(draft.note); setRows(draft.rows); }, + parseLocalDraft: (candidate) => + parseEditorDraft(candidate, ["rows"], ["note"]), + restoreLocalDraft: (draft) => { + setNote(draft.note); + setRows(draft.rows); + }, }); const handleWeaponDragEnd = ({ active, over }: DragEndEvent) => { if (!over || active.id === over.id) return; @@ -353,36 +717,318 @@ function WeaponEditor({ guide, weapons, characters, initial }: EditorBase) { }; return ( - Weapon tier listลากเพื่อเรียงอาวุธจากดีที่สุดลงมา และกรอกเปอร์เซ็นต์อย่างน้อยหนึ่งช่อง ระบบจะบันทึกอัตโนมัติ + + Weapon tier list + + ลากเพื่อเรียงอาวุธจากดีที่สุดลงมา และกรอกเปอร์เซ็นต์อย่างน้อยหนึ่งช่อง + ระบบจะบันทึกอัตโนมัติ + + - Header note (optional) setNote(event.target.value)} /> - - row.clientId)} strategy={verticalListSortingStrategy}> + + + Header note (optional) + + setNote(event.target.value)} + /> + + + row.clientId)} + strategy={verticalListSortingStrategy} + > - {rows.map((row, rowIndex) => { const selectedWeapon = compatibleWeapons.find((weapon) => weapon.key === row.weaponKey); return {(dragHandle) => {selectedWeapon ? : null}อันดับ {rowIndex + 1}{dragHandle}} title={`ลบ ${selectedWeapon?.name ?? `อาวุธอันดับ ${rowIndex + 1}`}?`} description="รายการอาวุธและเปอร์เซ็นต์เปรียบเทียบจะถูกลบออกจาก Guide" onConfirm={() => setRows(rows.filter((item) => item.clientId !== row.clientId))}>ลบอาวุธอาวุธ setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, weaponKey } : item))} />Refinement { const next = selected[0]; if (next) setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, refinement: Number(next.slice(1)) } : item)); }}>{[1, 2, 3, 4, 5].map((refinement) => R{refinement})}Overall % setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, overallPercent: normalizePercentInput(event.target.value, item.overallPercent) } : item))} onBlur={() => setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, overallPercent: finalizePercentInput(item.overallPercent) } : item))} />Personal % setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, personalPercent: normalizePercentInput(event.target.value, item.personalPercent) } : item))} onBlur={() => setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, personalPercent: finalizePercentInput(item.personalPercent) } : item))} />Note (optional) setRows(rows.map((item) => item.clientId === row.clientId ? { ...item, note: event.target.value } : item))} />}; })} + {rows.map((row, rowIndex) => { + const selectedWeapon = compatibleWeapons.find( + (weapon) => weapon.key === row.weaponKey, + ); + return ( + + {(dragHandle) => ( + + + + {selectedWeapon ? ( + + + + ) : null} + อันดับ {rowIndex + 1} + + + + {dragHandle} + + } + title={`ลบ ${selectedWeapon?.name ?? `อาวุธอันดับ ${rowIndex + 1}`}?`} + description="รายการอาวุธและเปอร์เซ็นต์เปรียบเทียบจะถูกลบออกจาก Guide" + onConfirm={() => + setRows( + rows.filter( + (item) => item.clientId !== row.clientId, + ), + ) + } + > + + ลบอาวุธ + + + + + + + + + อาวุธ + + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { ...item, weaponKey } + : item, + ), + ) + } + /> + + + Refinement + { + const next = selected[0]; + if (next) + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { + ...item, + refinement: Number( + next.slice(1), + ), + } + : item, + ), + ); + }} + > + {[1, 2, 3, 4, 5].map((refinement) => ( + + R{refinement} + + ))} + + + + + + Overall % + + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { + ...item, + overallPercent: + normalizePercentInput( + event.target.value, + item.overallPercent, + ), + } + : item, + ), + ) + } + onBlur={() => + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { + ...item, + overallPercent: + finalizePercentInput( + item.overallPercent, + ), + } + : item, + ), + ) + } + /> + + + Personal % + + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { + ...item, + personalPercent: + normalizePercentInput( + event.target.value, + item.personalPercent, + ), + } + : item, + ), + ) + } + onBlur={() => + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { + ...item, + personalPercent: + finalizePercentInput( + item.personalPercent, + ), + } + : item, + ), + ) + } + /> + + + + + Note (optional) + + + setRows( + rows.map((item) => + item.clientId === row.clientId + ? { ...item, note: event.target.value } + : item, + ), + ) + } + /> + + + + + )} + + ); + })} - setRows([...rows, { clientId: createClientId("weapon"), weaponKey: "", refinement: 1, overallPercent: "", personalPercent: "", note: "" }])}>เพิ่มอาวุธ + + + setRows([ + ...rows, + { + clientId: createClientId("weapon"), + weaponKey: "", + refinement: 1, + overallPercent: "", + personalPercent: "", + note: "", + }, + ]) + } + > + + เพิ่มอาวุธ + + + ); } -function ArtifactEditor({ guide, artifacts, initial, catalogTalents }: EditorBase) { +function ArtifactEditor({ + guide, + artifacts, + initial, + catalogTalents, +}: EditorBase) { const profile = initial.artifactProfile; const artifactSensors = useSensors( useSensor(PointerSensor), - useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), + useSensor(KeyboardSensor, { + coordinateGetter: sortableKeyboardCoordinates, + }), ); const talentSensors = useSensors( useSensor(PointerSensor), - useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), + useSensor(KeyboardSensor, { + coordinateGetter: sortableKeyboardCoordinates, + }), + ); + const [groups, setGroups] = useState(() => + (["Late Game", "Early Game"] as const).map((name, index) => ({ + name, + rows: + initial.artifactGroups[index]?.rows.map((row, rowIndex) => ({ + ...row, + clientId: `${name}-${rowIndex}`, + })) ?? [], + })), ); - const [groups, setGroups] = useState(() => (["Late Game", "Early Game"] as const).map((name, index) => ({ - name, - rows: initial.artifactGroups[index]?.rows.map((row, rowIndex) => ({ ...row, clientId: `${name}-${rowIndex}` })) ?? [], - }))); const [sands, setSands] = useState(profile?.sands ?? []); const [goblet, setGoblet] = useState(profile?.goblet ?? []); const [circlet, setCirclet] = useState(profile?.circlet ?? []); @@ -402,71 +1048,348 @@ function ArtifactEditor({ guide, artifacts, initial, catalogTalents }: EditorBas const [talents, setTalents] = useState(() => { const source: TalentPriority[] = profile?.talents.length ? profile.talents - : (["NA", "E", "Q"] as const).map((type, priority) => ({ type, priority: priority + 1 })); - return normalizeTalentPriorities(source.map((talent) => ({ - ...talent, - level: talent.level && talentLevelOptions.includes(talent.level as (typeof talentLevelOptions)[number]) ? talent.level : undefined, - }))); + : (["NA", "E", "Q"] as const).map((type, priority) => ({ + type, + priority: priority + 1, + })); + return normalizeTalentPriorities( + source.map((talent) => ({ + ...talent, + level: + talent.level && + talentLevelOptions.includes( + talent.level as (typeof talentLevelOptions)[number], + ) + ? talent.level + : undefined, + })), + ); }); const [note, setNote] = useState(profile?.note ?? ""); - const value = { groups: groups.map((group) => ({ name: group.name, rows: group.rows.map((row) => ({ firstArtifactKey: row.firstArtifactKey, secondArtifactKey: row.secondArtifactKey, percent: Number(row.percent), note: row.note?.trim() || null })) })), sands, goblet, circlet, substats, targets: targets.filter((target) => target.value.trim()).map((target) => ({ stat: target.stat, value: target.value.trim() })), talents, note: note || null }; - const validation = artifactSectionSchema.safeParse({ ...value, expectedVersion: guide.version }); - const localDraft = { groups, sands, goblet, circlet, substats, targets, talents, note }; + const value = { + groups: groups.map((group) => ({ + name: group.name, + rows: group.rows.map((row) => ({ + firstArtifactKey: row.firstArtifactKey, + secondArtifactKey: row.secondArtifactKey, + percent: Number(row.percent), + note: row.note?.trim() || null, + })), + })), + sands, + goblet, + circlet, + substats, + targets: targets + .filter((target) => target.value.trim()) + .map((target) => ({ stat: target.stat, value: target.value.trim() })), + talents, + note: note || null, + }; + const validation = artifactSectionSchema.safeParse({ + ...value, + expectedVersion: guide.version, + }); + const localDraft = { + groups, + sands, + goblet, + circlet, + substats, + targets, + talents, + note, + }; const autosave = useAutosave({ value, valid: validation.success, initialVersion: guide.version, - persist: (next, expectedVersion) => saveArtifactSection(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveArtifactSection(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "artifact"), localDraft, - parseLocalDraft: (candidate) => parseEditorDraft(candidate, ["groups", "sands", "goblet", "circlet", "substats", "targets", "talents"], ["note"]), - restoreLocalDraft: (draft) => { setGroups(draft.groups); setSands(draft.sands); setGoblet(draft.goblet); setCirclet(draft.circlet); setSubstats(draft.substats); setTargets(draft.targets); setTalents(draft.talents); setNote(draft.note); }, + parseLocalDraft: (candidate) => + parseEditorDraft( + candidate, + [ + "groups", + "sands", + "goblet", + "circlet", + "substats", + "targets", + "talents", + ], + ["note"], + ), + restoreLocalDraft: (draft) => { + setGroups(draft.groups); + setSands(draft.sands); + setGoblet(draft.goblet); + setCirclet(draft.circlet); + setSubstats(draft.substats); + setTargets(draft.targets); + setTalents(draft.talents); + setNote(draft.note); + }, }); const orderedTalents = normalizeTalentPriorities(talents); const handleArtifactDragEnd = ({ active, over }: DragEndEvent) => { if (!over || active.id === over.id) return; - const activeGroupIndex = groups.findIndex((group) => group.rows.some((row) => row.clientId === active.id)); - const overGroupIndex = groups.findIndex((group) => group.rows.some((row) => row.clientId === over.id)); + const activeGroupIndex = groups.findIndex((group) => + group.rows.some((row) => row.clientId === active.id), + ); + const overGroupIndex = groups.findIndex((group) => + group.rows.some((row) => row.clientId === over.id), + ); if (activeGroupIndex === -1 || activeGroupIndex !== overGroupIndex) return; - setGroups((current) => current.map((group, groupIndex) => { - if (groupIndex !== activeGroupIndex) return group; - const from = group.rows.findIndex((row) => row.clientId === active.id); - const to = group.rows.findIndex((row) => row.clientId === over.id); - return from === -1 || to === -1 ? group : { ...group, rows: arrayMove(group.rows, from, to) }; - })); + setGroups((current) => + current.map((group, groupIndex) => { + if (groupIndex !== activeGroupIndex) return group; + const from = group.rows.findIndex((row) => row.clientId === active.id); + const to = group.rows.findIndex((row) => row.clientId === over.id); + return from === -1 || to === -1 + ? group + : { ...group, rows: arrayMove(group.rows, from, to) }; + }), + ); }; const handleTalentDragEnd = ({ active, over }: DragEndEvent) => { if (!over) return; - setTalents(reorderTalentPriorities(orderedTalents, active.id as TalentPriority["type"], over.id as TalentPriority["type"])); + setTalents( + reorderTalentPriorities( + orderedTalents, + active.id as TalentPriority["type"], + over.id as TalentPriority["type"], + ), + ); }; - const setTalentRelation = (type: TalentPriority["type"], relationToNext: TalentRelation) => { - setTalents(orderedTalents.map((talent) => talent.type === type ? { ...talent, relationToNext } : talent)); + const setTalentRelation = ( + type: TalentPriority["type"], + relationToNext: TalentRelation, + ) => { + setTalents( + orderedTalents.map((talent) => + talent.type === type ? { ...talent, relationToNext } : talent, + ), + ); }; return ( - Artifact tier listจัดชุด Artifact ในกลุ่ม Late Game และ Early Game ระบบจะบันทึกอัตโนมัติ + + Artifact tier list + + จัดชุด Artifact ในกลุ่ม Late Game และ Early Game + ระบบจะบันทึกอัตโนมัติ + + {groups.map((group, groupIndex) => ( - {group.name} + + {group.name} + - - row.clientId)} strategy={verticalListSortingStrategy}> + + row.clientId)} + strategy={verticalListSortingStrategy} + > {group.rows.map((row, rowIndex) => ( - + {(dragHandle) => ( - + {dragHandle} - setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, firstArtifactKey } : candidate) } : item))} /> - setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, secondArtifactKey: secondArtifactKey || null } : candidate) } : item))} /> - setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, percent: normalizePercentInput(event.target.value, candidate.percent) } : candidate) } : item))} onBlur={() => setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, percent: finalizePercentInput(candidate.percent) } : candidate) } : item))} /> - } title={`ลบ Artifact อันดับ ${rowIndex + 1}?`} description={`รายการ Artifact ในกลุ่ม ${group.name} และเปอร์เซ็นต์เปรียบเทียบจะถูกลบออกจาก Guide`} onConfirm={() => setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.filter((_, inner) => inner !== rowIndex) } : item))}>ลบ Artifact + + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + firstArtifactKey, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + secondArtifactKey: + secondArtifactKey || + null, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + percent: + normalizePercentInput( + event.target + .value, + candidate.percent, + ), + } + : candidate, + ), + } + : item, + ), + ) + } + onBlur={() => + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + percent: + finalizePercentInput( + candidate.percent, + ), + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + } + title={`ลบ Artifact อันดับ ${rowIndex + 1}?`} + description={`รายการ Artifact ในกลุ่ม ${group.name} และเปอร์เซ็นต์เปรียบเทียบจะถูกลบออกจาก Guide`} + onConfirm={() => + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.filter( + (_, inner) => + inner !== rowIndex, + ), + } + : item, + ), + ) + } + > + + ลบ Artifact + - Note (optional) setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, note: event.target.value } : candidate) } : item))} /> + + + Note (optional) + + + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + note: event.target + .value, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + )} @@ -475,54 +1398,156 @@ function ArtifactEditor({ guide, artifacts, initial, catalogTalents }: EditorBas - setGroups(groups.map((item, index) => index === groupIndex ? { ...item, rows: [...item.rows, { clientId: createClientId("artifact"), firstArtifactKey: "", secondArtifactKey: null, percent: "100", note: "" }] } : item))}>เพิ่มชุด Artifact + + setGroups( + groups.map((item, index) => + index === groupIndex + ? { + ...item, + rows: [ + ...item.rows, + { + clientId: createClientId("artifact"), + firstArtifactKey: "", + secondArtifactKey: null, + percent: "100", + note: "", + }, + ], + } + : item, + ), + ) + } + > + + เพิ่มชุด Artifact + ))} - Recommended Statsเลือกค่าจากรายการแทนปุ่ม และเลือก Main Stat ได้สูงสุด 3 ค่าต่อชิ้น + + Recommended Stats + + เลือกค่าจากรายการแทนปุ่ม และเลือก Main Stat ได้สูงสุด 3 ค่าต่อชิ้น + + - - - + + + - + Target Stats - {[targetStatOptions.slice(0, 4), targetStatOptions.slice(4)].map((column) => ( + {[ + targetStatOptions.slice(0, 4), + targetStatOptions.slice(4), + ].map((column) => ( {column.map((stat) => { const target = targets.find((item) => item.stat === stat); return ( - - {stat} - setTargets(targets.map((item) => item.stat === stat ? { ...item, value: event.target.value } : item))} /> + + + + {stat} + + + setTargets( + targets.map((item) => + item.stat === stat + ? { ...item, value: event.target.value } + : item, + ), + ) + } + /> ); })} ))} - กรอกเฉพาะค่าเป็นตัวเลข เปอร์เซ็นต์ หรือข้อความ เช่น -% หากไม่กรอกค่า ระบบจะไม่แสดงส่วนค่าสถานะเป้าหมาย + + กรอกเฉพาะค่าเป็นตัวเลข เปอร์เซ็นต์ หรือข้อความ เช่น -% + หากไม่กรอกค่า ระบบจะไม่แสดงส่วนค่าสถานะเป้าหมาย + Talent Priority - - talent.type)} strategy={horizontalListSortingStrategy}> + + talent.type)} + strategy={horizontalListSortingStrategy} + > {orderedTalents.map((talent, index) => { - const catalogTalent = catalogTalents.find((item) => item.type === talent.type); + const catalogTalent = catalogTalents.find( + (item) => item.type === talent.type, + ); return ( - + setTalents(orderedTalents.map((item) => item.type === talent.type ? { ...item, level } : item))} + onLevelChange={(level) => + setTalents( + orderedTalents.map((item) => + item.type === talent.type + ? { ...item, level } + : item, + ), + ) + } /> {index < orderedTalents.length - 1 ? ( { - const relation = selected[0] as TalentRelation | undefined; - if (relation) setTalentRelation(talent.type, relation); + const relation = selected[0] as + | TalentRelation + | undefined; + if (relation) + setTalentRelation(talent.type, relation); }} aria-label={`ตัวเปรียบเทียบหลัง ${catalogTalent?.name ?? talent.type}`} className="shrink-0" > - > - ≥ - = + + > + + + ≥ + + + = + ) : null} @@ -550,80 +1596,369 @@ function ArtifactEditor({ guide, artifacts, initial, catalogTalents }: EditorBas Note (optional) - setNote(event.target.value)} /> + setNote(event.target.value)} + /> - + + + ); } -function ConstellationEditor({ guide, initial, catalogConstellations }: EditorBase) { +function ConstellationEditor({ + guide, + initial, + catalogConstellations, +}: EditorBase) { const [note, setNote] = useState(initial.sectionNote ?? ""); const makeRows = (savedRows: ConstellationValue[] = []) => { - const source = catalogConstellations.length ? catalogConstellations : Array.from({ length: 6 }, (_, index) => ({ level: index + 1, name: `C${index + 1}`, description: savedRows.find((row) => row.level === index + 1)?.detail ?? "", iconUrl: null })); + const source = catalogConstellations.length + ? catalogConstellations + : Array.from({ length: 6 }, (_, index) => ({ + level: index + 1, + name: `C${index + 1}`, + description: + savedRows.find((row) => row.level === index + 1)?.detail ?? "", + iconUrl: null, + })); return source.map((constellation) => { const saved = savedRows.find((row) => row.level === constellation.level); - return { ...constellation, cumulativePercent: saved?.cumulativePercent ?? "", isGreat: saved?.isGreat ?? false }; + return { + ...constellation, + cumulativePercent: saved?.cumulativePercent ?? "", + isGreat: saved?.isGreat ?? false, + }; }); }; const [groups, setGroups] = useState(() => { - const source = initial.constellationGroups.length ? initial.constellationGroups : [{ id: "constellation-condition-default", note: null, rows: [] }]; - return source.map((group) => ({ clientId: group.id, note: group.note ?? "", rows: makeRows(group.rows) })); + const source = initial.constellationGroups.length + ? initial.constellationGroups + : [{ id: "constellation-condition-default", note: null, rows: [] }]; + return source.map((group) => ({ + clientId: group.id, + note: group.note ?? "", + rows: makeRows(group.rows), + })); + }); + const value = { + note: note.trim() || null, + groups: groups.map((group) => ({ + note: group.note.trim() || null, + rows: group.rows + .filter((row) => row.description.trim() && row.cumulativePercent !== "") + .map((row) => ({ + level: row.level, + detail: row.description, + cumulativePercent: Number(row.cumulativePercent), + isGreat: row.isGreat, + })), + })), + }; + const validation = constellationSectionSchema.safeParse({ + ...value, + expectedVersion: guide.version, }); - const value = { note: note.trim() || null, groups: groups.map((group) => ({ note: group.note.trim() || null, rows: group.rows.filter((row) => row.description.trim() && row.cumulativePercent !== "").map((row) => ({ level: row.level, detail: row.description, cumulativePercent: Number(row.cumulativePercent), isGreat: row.isGreat })) })) }; - const validation = constellationSectionSchema.safeParse({ ...value, expectedVersion: guide.version }); const localDraft = { note, groups }; const autosave = useAutosave({ value, valid: validation.success, initialVersion: guide.version, - persist: (next, expectedVersion) => saveConstellationSection(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveConstellationSection(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "constellations"), localDraft, - parseLocalDraft: (candidate) => parseEditorDraft(candidate, ["groups"], ["note"]), - restoreLocalDraft: (draft) => { setNote(draft.note); setGroups(draft.groups); }, + parseLocalDraft: (candidate) => + parseEditorDraft(candidate, ["groups"], ["note"]), + restoreLocalDraft: (draft) => { + setNote(draft.note); + setGroups(draft.groups); + }, }); return ( - Constellationsชื่อ รายละเอียด และไอคอนมาจาก Lunaris อัตโนมัติ กรอกเฉพาะเปอร์เซ็นต์เทียบกับ C0 = 100% + + Constellations + + ชื่อ รายละเอียด และไอคอนมาจาก Lunaris อัตโนมัติ + กรอกเฉพาะเปอร์เซ็นต์เทียบกับ C0 = 100% + + - Header note (optional) setNote(event.target.value)} /> - {groups.map((group, groupIndex) => - Condition {groupIndex + 1}ใช้ note เพื่ออธิบายอาวุธ ทีม หรือเงื่อนไขที่ใช้เปรียบเทียบ{groups.length > 1 ? } title={`ลบ Condition ${groupIndex + 1}?`} description="เปอร์เซ็นต์กลุ่มดาวทั้งหมดในเงื่อนไขนี้จะถูกลบออก" onConfirm={() => setGroups(groups.filter((item) => item.clientId !== group.clientId))}>ลบ Condition {groupIndex + 1} : null} - - Condition note (optional) setGroups(groups.map((item) => item.clientId === group.clientId ? { ...item, note: event.target.value } : item))} /> - - {group.rows.map((row, rowIndex) => {row.iconUrl ? : null}C{row.level} · {row.name}{row.description}Cumulative % setGroups(groups.map((item) => item.clientId === group.clientId ? { ...item, rows: item.rows.map((candidate, index) => index === rowIndex ? { ...candidate, cumulativePercent: normalizePercentInput(event.target.value, candidate.cumulativePercent) } : candidate) } : item))} onBlur={() => setGroups(groups.map((item) => item.clientId === group.clientId ? { ...item, rows: item.rows.map((candidate, index) => index === rowIndex ? { ...candidate, cumulativePercent: finalizePercentInput(candidate.cumulativePercent) } : candidate) } : item))} /> setGroups(groups.map((item) => item.clientId === group.clientId ? { ...item, rows: item.rows.map((candidate, index) => index === rowIndex ? { ...candidate, isGreat } : candidate) } : item))} aria-label={`Mark Condition ${groupIndex + 1} C${row.level} percentage as great`} className={cn(SELECTED_TOGGLE_CLASS, "data-[state=on]:text-warning")}>Great %)} - - - )} + + + Header note (optional) + + setNote(event.target.value)} + /> + + {groups.map((group, groupIndex) => ( + + + Condition {groupIndex + 1} + + ใช้ note เพื่ออธิบายอาวุธ ทีม หรือเงื่อนไขที่ใช้เปรียบเทียบ + + {groups.length > 1 ? ( + + + } + title={`ลบ Condition ${groupIndex + 1}?`} + description="เปอร์เซ็นต์กลุ่มดาวทั้งหมดในเงื่อนไขนี้จะถูกลบออก" + onConfirm={() => + setGroups( + groups.filter( + (item) => item.clientId !== group.clientId, + ), + ) + } + > + + + ลบ Condition {groupIndex + 1} + + + + ) : null} + + + + + Condition note (optional) + + + setGroups( + groups.map((item) => + item.clientId === group.clientId + ? { ...item, note: event.target.value } + : item, + ), + ) + } + /> + + + {group.rows.map((row, rowIndex) => ( + + + {row.iconUrl ? ( + + ) : null} + + C{row.level} · {row.name} + + {row.description} + + + + Cumulative % + + setGroups( + groups.map((item) => + item.clientId === group.clientId + ? { + ...item, + rows: item.rows.map((candidate, index) => + index === rowIndex + ? { + ...candidate, + cumulativePercent: + normalizePercentInput( + event.target.value, + candidate.cumulativePercent, + ), + } + : candidate, + ), + } + : item, + ), + ) + } + onBlur={() => + setGroups( + groups.map((item) => + item.clientId === group.clientId + ? { + ...item, + rows: item.rows.map((candidate, index) => + index === rowIndex + ? { + ...candidate, + cumulativePercent: + finalizePercentInput( + candidate.cumulativePercent, + ), + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + setGroups( + groups.map((item) => + item.clientId === group.clientId + ? { + ...item, + rows: item.rows.map((candidate, index) => + index === rowIndex + ? { ...candidate, isGreat } + : candidate, + ), + } + : item, + ), + ) + } + aria-label={`Mark Condition ${groupIndex + 1} C${row.level} percentage as great`} + className={cn( + SELECTED_TOGGLE_CLASS, + "data-[state=on]:text-warning", + )} + > + + Great % + + + + ))} + + + + ))} - = 20} onClick={() => setGroups([...groups, { clientId: createClientId("constellation-condition"), note: "", rows: makeRows() }])}>เพิ่ม Condition + + = 20} + onClick={() => + setGroups([ + ...groups, + { + clientId: createClientId("constellation-condition"), + note: "", + rows: makeRows(), + }, + ]) + } + > + + เพิ่ม Condition + + + ); } -function TeamEditor({ guide, characters, weapons, artifacts, initial }: EditorBase) { - const fallbackMembers = Array.from({ length: 4 }, () => ({ characterKey: "", weaponKey: null, artifactKey: null, secondArtifactKey: null, constellation: 0, refinement: 1, damage: "0" })); +function TeamEditor({ + guide, + characters, + weapons, + artifacts, + initial, +}: EditorBase) { + const fallbackMembers = Array.from({ length: 4 }, () => ({ + characterKey: "", + weaponKey: null, + artifactKey: null, + secondArtifactKey: null, + constellation: 0, + refinement: 1, + damage: "0", + })); const teamSensors = useSensors( useSensor(PointerSensor), - useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }), + useSensor(KeyboardSensor, { + coordinateGetter: sortableKeyboardCoordinates, + }), ); - const [teams, setTeams] = useState(initial.teams.map(({ id, ...team }) => ({ clientId: id, ...team }))); - const value = { teams: teams.map((team) => ({ title: team.title, rotationSeconds: Number(team.rotationSeconds), combo: team.combo, members: team.members.map((member) => ({ ...member, damage: Number(member.damage) })) })) }; - const validation = teamSectionSchema.safeParse({ ...value, expectedVersion: guide.version }); + const [teams, setTeams] = useState( + initial.teams.map(({ id, ...team }) => ({ clientId: id, ...team })), + ); + const value = { + teams: teams.map((team) => ({ + title: team.title, + rotationSeconds: Number(team.rotationSeconds), + combo: team.combo, + members: team.members.map((member) => ({ + ...member, + damage: Number(member.damage), + })), + })), + }; + const validation = teamSectionSchema.safeParse({ + ...value, + expectedVersion: guide.version, + }); const localDraft = { teams }; const autosave = useAutosave({ value, valid: validation.success, initialVersion: guide.version, - persist: (next, expectedVersion) => saveTeamSection(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveTeamSection(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "team"), localDraft, - parseLocalDraft: (candidate) => parseEditorDraft(candidate, ["teams"]), + parseLocalDraft: (candidate) => + parseEditorDraft(candidate, ["teams"]), restoreLocalDraft: (draft) => setTeams(draft.teams), }); const handleTeamDragEnd = ({ active, over }: DragEndEvent) => { @@ -636,136 +1971,669 @@ function TeamEditor({ guide, characters, weapons, artifacts, initial }: EditorBa }; return ( - Team Calcลากเพื่อเรียง Team แล้วใส่ความเสียหายของตัวละคร 4 ตัว ระบบจะแสดงสัดส่วนและ Total DPS และบันทึกอัตโนมัติ + + Team Calc + + ลากเพื่อเรียง Team แล้วใส่ความเสียหายของตัวละคร 4 ตัว + ระบบจะแสดงสัดส่วนและ Total DPS และบันทึกอัตโนมัติ + + - - team.clientId)} strategy={verticalListSortingStrategy}> - + + team.clientId)} + strategy={verticalListSortingStrategy} + > + {teams.map((team, teamIndex) => { - const total = team.members.reduce((sum, member) => sum + (Number(member.damage) || 0), 0); - const dps = total / (Number(team.rotationSeconds) || 1); - return ( - {(dragHandle) => <> - - - - {team.title || `Team ${teamIndex + 1}`} - Damage {total.toLocaleString()} • DPS {dps.toFixed(0)} - - - - {dragHandle} - = 30} - onClick={() => setTeams((current) => { - const sourceIndex = current.findIndex((item) => item.clientId === team.clientId); - if (sourceIndex === -1 || current.length >= 30) return current; - const source = current[sourceIndex]; - const title = source.title.trim() - ? `${source.title.slice(0, 153)} (Copy)` - : `Team ${sourceIndex + 1} (Copy)`; - const copy = { - ...source, - clientId: createClientId("team"), - title, - members: source.members.map((member) => ({ ...member })), - }; - return current.toSpliced(sourceIndex + 1, 0, copy); - })} - > - ทำสำเนา Team - - } - title={`ลบ ${team.title || `Team ${teamIndex + 1}`}?`} - description="ข้อมูล Team และตัวละครทั้ง 4 คนจะถูกลบออกจาก Guide" - confirmLabel="ยืนยันลบ Team" - onConfirm={() => setTeams(teams.filter((item) => item.clientId !== team.clientId))} - > - ลบ Team - - - - - - ชื่อ Team setTeams(teams.map((item, index) => index === teamIndex ? { ...item, title: event.target.value } : item))} /> - - {team.members.map((member, memberIndex) => { - const character = characters.find((item) => item.key === member.characterKey); - const compatibleWeapons = weapons.filter((weapon) => supportsWeaponType(character?.weaponType, weapon.weaponType)); - return ( - - - ตัวละคร {memberIndex + 1} - {total ? `${((Number(member.damage) || 0) / total * 100).toFixed(2)}% ของ Team` : "0% ของ Team"} - {character ? {character.name.slice(0, 2).toUpperCase()} : null} - - - - ตัวละคร setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, characterKey, weaponKey: null, artifactKey: null, secondArtifactKey: null, constellation: 0, refinement: 1 } : candidate) } : item))} /> - Damage setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, damage: event.target.value } : candidate) } : item))} /> - Weapon setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, weaponKey: weaponKey || null } : candidate) } : item))} />Refinement { const refinement = selected[0]; if (refinement) setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, refinement: Number(refinement.slice(1)) } : candidate) } : item)); }}>{[1, 2, 3, 4, 5].map((refinement) => R{refinement})} - - Artifact set 1 setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, artifactKey: artifactKey || null } : candidate) } : item))} /> - Artifact set 2 setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, secondArtifactKey: secondArtifactKey || null } : candidate) } : item))} /> - - Constellation { const constellation = selected[0]; if (constellation) setTeams(teams.map((item, index) => index === teamIndex ? { ...item, members: item.members.map((candidate, inner) => inner === memberIndex ? { ...candidate, constellation: Number(constellation.slice(1)) } : candidate) } : item)); }}>{[0, 1, 2, 3, 4, 5, 6].map((constellation) => C{constellation})} - - - - ); - })} - - Rotation (seconds) setTeams(teams.map((item, index) => index === teamIndex ? { ...item, rotationSeconds: event.target.value } : item))} /> - Combo setTeams(teams.map((item, index) => index === teamIndex ? { ...item, combo: event.target.value } : item))} /> - - - >} - ); + const total = team.members.reduce( + (sum, member) => sum + (Number(member.damage) || 0), + 0, + ); + const dps = total / (Number(team.rotationSeconds) || 1); + return ( + + {(dragHandle) => ( + <> + + + + + {team.title || `Team ${teamIndex + 1}`} + + + Damage {total.toLocaleString()} • DPS{" "} + {dps.toFixed(0)} + + + + + {dragHandle} + = 30} + onClick={() => + setTeams((current) => { + const sourceIndex = current.findIndex( + (item) => item.clientId === team.clientId, + ); + if ( + sourceIndex === -1 || + current.length >= 30 + ) + return current; + const source = current[sourceIndex]; + const title = source.title.trim() + ? `${source.title.slice(0, 153)} (Copy)` + : `Team ${sourceIndex + 1} (Copy)`; + const copy = { + ...source, + clientId: createClientId("team"), + title, + members: source.members.map((member) => ({ + ...member, + })), + }; + return current.toSpliced( + sourceIndex + 1, + 0, + copy, + ); + }) + } + > + + ทำสำเนา Team + + + } + title={`ลบ ${team.title || `Team ${teamIndex + 1}`}?`} + description="ข้อมูล Team และตัวละครทั้ง 4 คนจะถูกลบออกจาก Guide" + confirmLabel="ยืนยันลบ Team" + onConfirm={() => + setTeams( + teams.filter( + (item) => item.clientId !== team.clientId, + ), + ) + } + > + + ลบ Team + + + + + + + + + ชื่อ Team + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { ...item, title: event.target.value } + : item, + ), + ) + } + /> + + + {team.members.map((member, memberIndex) => { + const character = characters.find( + (item) => item.key === member.characterKey, + ); + const compatibleWeapons = weapons.filter( + (weapon) => + supportsWeaponType( + character?.weaponType, + weapon.weaponType, + ), + ); + return ( + + + + ตัวละคร {memberIndex + 1} + + + {total + ? `${(((Number(member.damage) || 0) / total) * 100).toFixed(2)}% ของ Team` + : "0% ของ Team"} + + {character ? ( + + + + + {character.name + .slice(0, 2) + .toUpperCase()} + + + + ) : null} + + + + + + + ตัวละคร + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + characterKey, + weaponKey: + null, + artifactKey: + null, + secondArtifactKey: + null, + constellation: 0, + refinement: 1, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + + + Damage + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + damage: + event + .target + .value, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + + + Constellation + + { + const constellation = selected[0]; + if (constellation) + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + constellation: + Number( + constellation.slice( + 1, + ), + ), + } + : candidate, + ), + } + : item, + ), + ); + }} + > + {[0, 1, 2, 3, 4, 5, 6].map( + (constellation) => ( + + C{constellation} + + ), + )} + + + + + + + Weapon + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + weaponKey: + weaponKey || + null, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + + + Refinement + + { + const refinement = selected[0]; + if (refinement) + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + refinement: + Number( + refinement.slice( + 1, + ), + ), + } + : candidate, + ), + } + : item, + ), + ); + }} + > + {[1, 2, 3, 4, 5].map( + (refinement) => ( + + R{refinement} + + ), + )} + + + + + + + + Artifact set 1 + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + artifactKey: + artifactKey || + null, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + + + Artifact set 2 + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + members: + item.members.map( + ( + candidate, + inner, + ) => + inner === + memberIndex + ? { + ...candidate, + secondArtifactKey: + secondArtifactKey || + null, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + + + + ); + })} + + + + + Rotation (seconds) + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { + ...item, + rotationSeconds: event.target.value, + } + : item, + ), + ) + } + /> + + + + + Combo + + + setTeams( + teams.map((item, index) => + index === teamIndex + ? { ...item, combo: event.target.value } + : item, + ), + ) + } + /> + + + + > + )} + + ); })} - setTeams([...teams, { clientId: createClientId("team"), title: "", rotationSeconds: "20", combo: "", members: fallbackMembers }])}>เพิ่ม Team + + + setTeams([ + ...teams, + { + clientId: createClientId("team"), + title: "", + rotationSeconds: "20", + combo: "", + members: fallbackMembers, + }, + ]) + } + > + + เพิ่ม Team + + + ); } function ExtraEditor({ guide, initial }: EditorBase) { const [sections, setSections] = useState(initial.extras); - const value = { sections: sections.map((section) => ({ title: section.title, rows: section.rows.map((row) => ({ mediaId: row.mediaId, ratio: row.ratio, heading: row.heading, body: row.body, percent: row.percent === null || row.percent === "" ? null : Number(row.percent) })) })) }; - const validation = extraSectionSchema.safeParse({ ...value, expectedVersion: guide.version }); + const value = { + sections: sections.map((section) => ({ + title: section.title, + rows: section.rows.map((row) => ({ + mediaId: row.mediaId, + ratio: row.ratio, + heading: row.heading, + body: row.body, + percent: + row.percent === null || row.percent === "" + ? null + : Number(row.percent), + })), + })), + }; + const validation = extraSectionSchema.safeParse({ + ...value, + expectedVersion: guide.version, + }); const localDraft = { sections }; const autosave = useAutosave({ value, valid: validation.success, initialVersion: guide.version, - persist: (next, expectedVersion) => saveExtraSectionList(guide.id, { ...next, expectedVersion }), + persist: (next, expectedVersion) => + saveExtraSectionList(guide.id, { ...next, expectedVersion }), storageKey: adminDraftKey(guide.id, "extra"), localDraft, - parseLocalDraft: (candidate) => parseEditorDraft(candidate, ["sections"]), + parseLocalDraft: (candidate) => + parseEditorDraft(candidate, ["sections"]), restoreLocalDraft: (draft) => setSections(draft.sections), }); return ( - Extra sectionsเพิ่มส่วนเสริมแบบภาพ หัวข้อ ข้อความสั้น และเปอร์เซ็นต์ ระบบจะบันทึกอัตโนมัติ + + Extra sections + + เพิ่มส่วนเสริมแบบภาพ หัวข้อ ข้อความสั้น และเปอร์เซ็นต์ + ระบบจะบันทึกอัตโนมัติ + + {sections.map((section, sectionIndex) => ( - setSections(sections.map((item, index) => index === sectionIndex ? { ...item, title: event.target.value } : item))} /> + + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { ...item, title: event.target.value } + : item, + ), + ) + } + /> + } + trigger={ + + } title={`ลบ ${section.title || `Extra section ${sectionIndex + 1}`}?`} description="แถว ข้อความ รูปภาพ และเปอร์เซ็นต์ทั้งหมดในส่วนนี้จะถูกลบออกจาก Guide" - onConfirm={() => setSections(sections.filter((_, index) => index !== sectionIndex))} + onConfirm={() => + setSections( + sections.filter((_, index) => index !== sectionIndex), + ) + } > - ลบส่วน + + ลบส่วน @@ -773,55 +2641,318 @@ function ExtraEditor({ guide, initial }: EditorBase) { {section.rows.map((row, rowIndex) => ( - {row.heading || `แถว ${rowIndex + 1}`} + + {row.heading || `แถว ${rowIndex + 1}`} + } + trigger={ + + } title={`ลบ ${row.heading || `แถว ${rowIndex + 1}`}?`} description="ข้อความ รูปภาพ และเปอร์เซ็นต์ในแถวนี้จะถูกลบออกจาก Guide" - onConfirm={() => setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.filter((_, inner) => inner !== rowIndex) } : item))} + onConfirm={() => + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.filter( + (_, inner) => inner !== rowIndex, + ), + } + : item, + ), + ) + } > - ลบแถว + + ลบแถว {row.imageUrl ? ( - - + + } + trigger={ + + } title="ลบภาพนี้?" description="ภาพจะถูกนำออกจากแถวนี้" confirmLabel="ยืนยันลบภาพ" - onConfirm={() => setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, mediaId: null, imageUrl: null } : candidate) } : item))} + onConfirm={() => + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { + ...candidate, + mediaId: null, + imageUrl: null, + } + : candidate, + ), + } + : item, + ), + ) + } > ) : null} - setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, mediaId: asset.id, imageUrl: asset.url } : candidate) } : item))} /> + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map((candidate, inner) => + inner === rowIndex + ? { + ...candidate, + mediaId: asset.id, + imageUrl: asset.url, + } + : candidate, + ), + } + : item, + ), + ) + } + /> อัตราส่วนภาพ - { const ratio = selected[0]; if (ratio === "1:1" || ratio === "16:9") setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, ratio } : candidate) } : item)); }} className="flex-wrap justify-start"> - 1:1 - 16:9 + { + const ratio = selected[0]; + if (ratio === "1:1" || ratio === "16:9") + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map( + (candidate, inner) => + inner === rowIndex + ? { ...candidate, ratio } + : candidate, + ), + } + : item, + ), + ); + }} + className="flex-wrap justify-start" + > + + 1:1 + + + 16:9 + - หัวข้อ setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, heading: event.target.value } : candidate) } : item))} /> - ข้อความ setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, body: event.target.value } : candidate) } : item))} /> - Percent (optional) setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, percent: normalizePercentInput(event.target.value, candidate.percent ?? "") || null } : candidate) } : item))} onBlur={() => setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: item.rows.map((candidate, inner) => inner === rowIndex ? { ...candidate, percent: finalizePercentInput(candidate.percent ?? "") || null } : candidate) } : item))} /> + + หัวข้อ + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map((candidate, inner) => + inner === rowIndex + ? { + ...candidate, + heading: event.target.value, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + ข้อความ + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map((candidate, inner) => + inner === rowIndex + ? { + ...candidate, + body: event.target.value, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + + + Percent (optional) + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map((candidate, inner) => + inner === rowIndex + ? { + ...candidate, + percent: + normalizePercentInput( + event.target.value, + candidate.percent ?? "", + ) || null, + } + : candidate, + ), + } + : item, + ), + ) + } + onBlur={() => + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: item.rows.map((candidate, inner) => + inner === rowIndex + ? { + ...candidate, + percent: + finalizePercentInput( + candidate.percent ?? "", + ) || null, + } + : candidate, + ), + } + : item, + ), + ) + } + /> + ))} - setSections(sections.map((item, index) => index === sectionIndex ? { ...item, rows: [...item.rows, { mediaId: null, imageUrl: null, ratio: "16:9", heading: "", body: "", percent: null }] } : item))}>เพิ่มแถว + + setSections( + sections.map((item, index) => + index === sectionIndex + ? { + ...item, + rows: [ + ...item.rows, + { + mediaId: null, + imageUrl: null, + ratio: "16:9", + heading: "", + body: "", + percent: null, + }, + ], + } + : item, + ), + ) + } + > + + เพิ่มแถว + ))} - setSections([...sections, { title: "Extra", rows: [] }])}>เพิ่ม Extra section + + + setSections([...sections, { title: "Extra", rows: [] }]) + } + > + + เพิ่ม Extra section + + + ); } diff --git a/lib/catalog/travelers.test.ts b/lib/catalog/travelers.test.ts index 771fba2..521b661 100644 --- a/lib/catalog/travelers.test.ts +++ b/lib/catalog/travelers.test.ts @@ -30,4 +30,16 @@ describe("custom Traveler catalog", () => { expect(isCustomTravelerKey("traveler_hydro")).toBe(true); expect(isCustomTravelerKey("traveler_unknown")).toBe(false); }); + + it("uses element-first display names without changing stable keys", () => { + expect(customTravelers.map(({ key, name }) => ({ key, name }))).toEqual([ + { key: "traveler_pyro", name: "Pyro Traveler" }, + { key: "traveler_hydro", name: "Hydro Traveler" }, + { key: "traveler_anemo", name: "Anemo Traveler" }, + { key: "traveler_geo", name: "Geo Traveler" }, + { key: "traveler_electro", name: "Electro Traveler" }, + { key: "traveler_dendro", name: "Dendro Traveler" }, + { key: "traveler_cryo", name: "Cryo Traveler" }, + ]); + }); }); diff --git a/lib/catalog/travelers.ts b/lib/catalog/travelers.ts index 45a90ca..7abf47e 100644 --- a/lib/catalog/travelers.ts +++ b/lib/catalog/travelers.ts @@ -1,11 +1,11 @@ export const customTravelers = [ - { key: "traveler_pyro", name: "Traveler Pyro", element: "Pyro", rarity: 5, detailKey: "10000005_PYRO", asset: "traveler_pyro.webp" }, - { key: "traveler_hydro", name: "Traveler Hydro", element: "Hydro", rarity: 5, detailKey: "10000005_HYDRO", asset: "traveler_hydro.webp" }, - { key: "traveler_anemo", name: "Traveler Anemo", element: "Anemo", rarity: 5, detailKey: "10000005_ANEMO", asset: "traveler_anemo.webp" }, - { key: "traveler_geo", name: "Traveler Geo", element: "Geo", rarity: 5, detailKey: "10000005_GEO", asset: "traveler_geo.webp" }, - { key: "traveler_electro", name: "Traveler Electro", element: "Electro", rarity: 5, detailKey: "10000005_ELECTRO", asset: "traveler_electro.webp" }, - { key: "traveler_dendro", name: "Traveler Dendro", element: "Dendro", rarity: 5, detailKey: "10000005_DENDRO", asset: "traveler_dendro.webp" }, - { key: "traveler_cryo", name: "Traveler Cryo", element: "Cryo", rarity: 5, detailKey: "10000005_CRYO", asset: "traveler_cyro.webp" }, + { key: "traveler_pyro", name: "Pyro Traveler", element: "Pyro", rarity: 5, detailKey: "10000005_PYRO", asset: "traveler_pyro.webp" }, + { key: "traveler_hydro", name: "Hydro Traveler", element: "Hydro", rarity: 5, detailKey: "10000005_HYDRO", asset: "traveler_hydro.webp" }, + { key: "traveler_anemo", name: "Anemo Traveler", element: "Anemo", rarity: 5, detailKey: "10000005_ANEMO", asset: "traveler_anemo.webp" }, + { key: "traveler_geo", name: "Geo Traveler", element: "Geo", rarity: 5, detailKey: "10000005_GEO", asset: "traveler_geo.webp" }, + { key: "traveler_electro", name: "Electro Traveler", element: "Electro", rarity: 5, detailKey: "10000005_ELECTRO", asset: "traveler_electro.webp" }, + { key: "traveler_dendro", name: "Dendro Traveler", element: "Dendro", rarity: 5, detailKey: "10000005_DENDRO", asset: "traveler_dendro.webp" }, + { key: "traveler_cryo", name: "Cryo Traveler", element: "Cryo", rarity: 5, detailKey: "10000005_CRYO", asset: "traveler_cyro.webp" }, ] as const; export function isCustomTravelerKey(key: string): boolean {
{selected.id}
+ {selected.id} +