Files
poli0981andClaude Opus 5.5 3b1b17ebf1 fix(qodana): clear the first run's findings
The first Qodana run found 74 problems in TypeScript / JavaScript and 12 in
Rust. Fixed:
- React 19.3 deprecates `FormEvent`: the three save forms take the
  `SubmitEvent` their `onSubmit` hands them.
- The URL patterns read `\S` instead of `[^\s]` (18 patterns in platforms.ts
  and playtest-platforms.ts, same characters).
- public/theme-init.js declares its browser globals and drops an unused
  catch binding.
- The two private `stable()` JSON helpers (restore.ts, library-apply.ts)
  become one `stableJson()` in src/utils/stable-json.ts, with a test.
- vitest.config.ts reuses vite.config.ts's alias map instead of a copy.
- Accordion destructures `icon` as `Icon` instead of copying it, a JSDoc
  link points at nothing any more, and i18next's `init()` promise is
  `void`ed on purpose.
- Rust: the three "show the main window" blocks become `show_main_window`.

Excluded in qodana.yaml, each with its reason: the Discord webhook secret
reference (HardcodedPasswords), escaped `]` / `}` in regexes, the
`@i18n/index` imports tsconfig needs, the three react-hooks warnings
eslint.config.js documents, the legacy `@deprecated` draft fields in the
files that migrate them; in src-tauri/qodana.yaml the module paths
`generate_handler!` needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 10:38:59 +07:00

95 lines
3.2 KiB
TypeScript

import { useId, useState, type SubmitEvent } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
import { Modal } from "@components/ui/Modal";
import { Button } from "@components/ui/Button";
import { Input } from "@components/ui/Input";
import { Checkbox } from "@components/ui/Checkbox";
import { editorDataOf, useEditorStore } from "@store/editor-store";
import { useTemplateStore, type EditorTemplate } from "@store/template-store";
import { FIELD_LIMITS } from "@config/field-limits";
interface TemplateSaveFormProps {
open: boolean;
onClose: () => void;
editTemplate?: EditorTemplate;
}
/**
* Save the whole editor form as a template (every field — templates saved
* before v1.0.0 kept only part of it), or rename / refresh one. Mounted only
* while open, so it always starts from the template as it is now.
*/
export function TemplateSaveForm(props: TemplateSaveFormProps) {
return props.open ? <TemplateSaveFormBody {...props} /> : null;
}
function TemplateSaveFormBody({ onClose, editTemplate }: TemplateSaveFormProps) {
const { t } = useTranslation("ui");
const formId = useId();
const addTemplate = useTemplateStore((s) => s.addTemplate);
const updateTemplate = useTemplateStore((s) => s.updateTemplate);
const [name, setName] = useState(editTemplate?.name ?? "");
const [fromEditor, setFromEditor] = useState(false);
const save = (e: SubmitEvent) => {
e.preventDefault();
const snapshot = structuredClone(editorDataOf(useEditorStore.getState()));
const finalName = name.trim() || snapshot.gameName.trim() || t("templates.unnamed");
if (editTemplate) {
updateTemplate(editTemplate.id, {
name: finalName,
snapshot: fromEditor ? snapshot : undefined,
});
toast.success(t("templates.updated", { name: finalName }));
} else {
addTemplate(finalName, snapshot);
toast.success(t("templates.savedAs", { name: finalName }));
}
onClose();
};
return (
<Modal
open
onClose={onClose}
title={editTemplate ? t("templates.editTemplate") : t("templates.saveAsTemplate")}
footer={
<>
<Button variant="ghost" onClick={onClose}>
{t("common.cancel")}
</Button>
<Button type="submit" form={formId}>
{t("common.save")}
</Button>
</>
}
>
<form id={formId} onSubmit={save} className="flex flex-col gap-3">
<Input
label={t("templates.templateName")}
maxLength={FIELD_LIMITS.SHORT_NAME}
placeholder={t("templates.templateNamePlaceholder")}
value={name}
onChange={(e) => setName(e.target.value)}
autoFocus
/>
{editTemplate ? (
<Checkbox
checked={fromEditor}
onChange={setFromEditor}
label={
<span className="flex flex-col gap-0.5">
<span className="text-text-primary text-sm">{t("templates.updateFromEditor")}</span>
<span className="text-text-muted text-xs">{t("templates.saveHint")}</span>
</span>
}
/>
) : (
<p className="text-text-muted text-xs">{t("templates.saveHint")}</p>
)}
</form>
</Modal>
);
}