diff --git a/components/admin/guide-overview-form.tsx b/components/admin/guide-overview-form.tsx index 1dc5c9a..357a5b2 100644 --- a/components/admin/guide-overview-form.tsx +++ b/components/admin/guide-overview-form.tsx @@ -11,7 +11,6 @@ import { saveGuideOverview } from "@/app/admin/actions"; import { AutosaveStatus } from "@/components/admin/autosave-status"; import { MediaUploader } from "@/components/admin/media-uploader"; import { MaterialPoster, type PosterBlendMode } from "@/components/public/material-poster"; -import { GuideImageExport } from "@/components/public/guide-image-export"; import { Button } from "@/components/ui/button"; import { Card, @@ -468,27 +467,6 @@ export function GuideOverviewForm({ ลบภาพตัวละคร ) : null} - - -
diff --git a/components/public/export-language-dialog.tsx b/components/public/export-language-dialog.tsx deleted file mode 100644 index b65721d..0000000 --- a/components/public/export-language-dialog.tsx +++ /dev/null @@ -1,53 +0,0 @@ -"use client"; - -import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import { - ExportLanguageOption, - type ExportLanguage, -} from "@/components/public/export-language"; - -export function ExportLanguageDialog({ - open, - onOpenChange, - onSelect, -}: { - open: boolean; - onOpenChange: (open: boolean) => void; - onSelect: (language: ExportLanguage) => void; -}) { - return ( - - - - เลือกภาษาในภาพ - What language do you want? - -
- - -
-
-
- ); -} diff --git a/components/public/guide-image-export.tsx b/components/public/guide-image-export.tsx index dce0b37..d2b6dce 100644 --- a/components/public/guide-image-export.tsx +++ b/components/public/guide-image-export.tsx @@ -13,13 +13,13 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; -import { ExportLanguageDialog } from "@/components/public/export-language-dialog"; import { ExportLanguageToggle, useExportLanguage, type ExportLanguage, } from "@/components/public/export-language"; import { Spinner } from "@/components/ui/spinner"; +import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { cn } from "@/lib/utils"; const EXPORT_WIDTH = 1200; @@ -89,55 +89,70 @@ export function GuideImageExport({ const capturing = captureMode !== null; const [storedLanguage, setStoredLanguage] = useExportLanguage(); const language = controlledLanguage ?? storedLanguage; - const [pendingCaptureMode, setPendingCaptureMode] = useState< - "with-notes" | "without-notes" | null - >(null); + const [selectedMode, setSelectedMode] = useState<"with-notes" | "without-notes">( + "with-notes", + ); const [modeDialogOpen, setModeDialogOpen] = useState(false); - function requestCapture(mode: "with-notes" | "without-notes") { + function requestCapture() { setModeDialogOpen(false); - if (promptForLanguage) setPendingCaptureMode(mode); - else setCaptureMode(mode); + setCaptureMode(selectedMode); } - function selectLanguage(nextLanguage: ExportLanguage) { - if (!pendingCaptureMode) return; - setStoredLanguage(nextLanguage); - setCaptureMode(pendingCaptureMode); - setPendingCaptureMode(null); - } - - function exportButton( - mode: "with-notes" | "without-notes" | null, - label: string, - ) { - const loading = capturing && (mode === null || captureMode === mode); + function exportButton(label: string) { return ( ); } + const exportSettings = ( + <> + {showLanguageSelector || promptForLanguage ? ( +
+

ภาษาในภาพ

+ +
+ ) : null} + {allowWithoutNotes ? ( +
+

โน้ต

+ { + const next = values[0]; + if (next === "with-notes" || next === "without-notes") setSelectedMode(next); + }} + > + รวมโน้ต + ไม่รวมโน้ต + +
+ ) : null} + + + ); + useEffect(() => { if (!capturing) return; @@ -204,52 +219,22 @@ export function GuideImageExport({ return ( <> - {showLanguageSelector ? ( - - ) : null} -
- {allowWithoutNotes && modeSelection === "inline" - ? [ - exportButton("with-notes", buttonLabel), - exportButton("without-notes", "ส่งออกภาพโดยไม่รวมโน้ต"), - ] - : exportButton(null, buttonLabel)} -
- {allowWithoutNotes && modeSelection === "dialog" ? ( + {modeSelection === "inline" ? ( + exportSettings + ) : ( +
{exportButton(buttonLabel)}
+ )} + {modeSelection === "dialog" ? ( - เลือกรูปแบบการส่งออก - เลือกว่าจะรวมโน้ตไว้ในภาพหรือไม่ + ตั้งค่าการส่งออกภาพ + เลือกตัวเลือกที่ต้องการก่อนส่งออกภาพ -
- - -
+ {exportSettings}
) : null} - { - if (!open) setPendingCaptureMode(null); - }} - onSelect={selectLanguage} - /> {capturing ? createPortal(
group.rows.some((row) => row[metric] !== null), ); + const [metric, setMetric] = useState( + metricOptions[0]?.[0] ?? "overallPercent", + ); + const metricLabel = metric === "overallPercent" ? "Overall Damage" : "Personal Damage"; return ( @@ -145,27 +147,37 @@ export function WeaponImageExport({ เลือกค่าที่ต้องการใช้สร้างภาพเปรียบเทียบอาวุธ - -
- {metricOptions.map(([metric, label]) => ( - - - - ))} +
+

ประเภทดาเมจ

+ { + const next = values[0]; + if (next === "overallPercent" || next === "personalPercent") setMetric(next); + }} + > + {metricOptions.map(([value]) => ( + + {value === "overallPercent" ? "ดาเมจทั้งทีม" : "ดาเมจส่วนตัว"} + + ))} +
+ + +
); diff --git a/lib/guides/image-export.test.tsx b/lib/guides/image-export.test.tsx index 50bf25d..436389c 100644 --- a/lib/guides/image-export.test.tsx +++ b/lib/guides/image-export.test.tsx @@ -31,30 +31,29 @@ describe("image export controls", () => { expect(html).not.toContain("เงื่อนไข 1"); }); - it("shows one export action when both note modes are available", () => { + it("shows one export trigger and keeps settings in its dialog", () => { const html = renderToStaticMarkup(No notes); expect(html).toContain("ส่งออกภาพ"); - expect(html).toContain("ไทย"); - expect(html).toContain("English"); - expect(html).toContain('data-language-flag="th"'); - expect(html).toContain('data-language-flag="en"'); - expect(html.match(/ { const html = renderToStaticMarkup(Content); expect(html).toContain("ส่งออกภาพ"); - expect(html.match(/ { + it("shows all settings inline with one export action inside an existing dialog", () => { const html = renderToStaticMarkup( Content , ); - expect(html).toContain("ส่งออกภาพโดยไม่รวมโน้ต"); - expect(html.match(/ส่งออกภาพ<\/button>/gu)).toHaveLength(1); }); it("hides the persistent language chooser when language is prompted on export", () => {