diff --git a/src/App.tsx b/src/App.tsx index 66159f7..969116b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,7 @@ import { needsConsent } from "@config/legal"; import { EditorPage } from "@pages/EditorPage"; import { hydrateLogStore } from "@store/log-store"; import { useSettingsStore } from "@store/settings-store"; +import { useEditorStore } from "@store/editor-store"; import i18n from "@i18n/index"; import { IS_TAURI } from "@utils/platform"; @@ -89,6 +90,20 @@ function ConsentGuard() { } export default function App() { + useEffect(() => { + // A first run has no saved draft yet: start it in the Default Output + // Language from Settings rather than the editor's built-in English. + try { + if (localStorage.getItem("ytdescgen-editor-draft") === null) { + useEditorStore.setState({ + language: useSettingsStore.getState().defaultOutputLanguage, + }); + } + } catch { + // Storage unavailable (private mode): nothing to decide. + } + }, []); + useEffect(() => { // Tauri: move data files older versions misplaced, start automatic // backups (desktop) — then load the logs, which that may have moved. diff --git a/src/components/editor/GameInfoForm.tsx b/src/components/editor/GameInfoForm.tsx index 181109d..90d9b2d 100644 --- a/src/components/editor/GameInfoForm.tsx +++ b/src/components/editor/GameInfoForm.tsx @@ -1,9 +1,31 @@ +import { useId, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { Input } from "@components/ui/Input"; import { Select } from "@components/ui/Select"; import { PLATFORMS } from "@config/platforms"; import { useEditorStore } from "@store/editor-store"; import { FIELD_LIMITS } from "@config/field-limits"; +import { usePresetStore } from "@store/preset-store"; +import { useHistoryStore } from "@store/history-store"; +import { applyStoreLink, matchStoreLink } from "@utils/store-paste"; + +/** Games the user has written about before: presets, then recent history. */ +function useGameNameSuggestions(): string[] { + const presets = usePresetStore((s) => s.presets); + const entries = useHistoryStore((s) => s.entries); + return useMemo(() => { + const seen = new Set(); + const names: string[] = []; + for (const name of [...presets.map((p) => p.gameName), ...entries.map((e) => e.gameName)]) { + const key = name.trim().toLowerCase(); + if (!key || seen.has(key)) continue; + seen.add(key); + names.push(name.trim()); + if (names.length >= 50) break; + } + return names; + }, [presets, entries]); +} /** * Core identity fields for the video (game name, channel, platform). @@ -15,6 +37,8 @@ export function GameInfoForm() { const store = useEditorStore(); const platformOptions = PLATFORMS.map((p) => ({ value: p.id, label: p.label })); + const suggestionsId = useId(); + const suggestions = useGameNameSuggestions(); return (
@@ -24,9 +48,23 @@ export function GameInfoForm() { placeholder={t("editor.gameNamePlaceholder")} value={store.gameName} onChange={(e) => store.set("gameName", e.target.value)} + onPaste={(e) => { + // A store link pasted here goes to its store field instead, and + // the game name is read from it. + const match = matchStoreLink(e.clipboardData.getData("text")); + if (!match) return; + e.preventDefault(); + applyStoreLink(match); + }} + list={suggestionsId} autoComplete="off" enterKeyHint="next" /> + + {suggestions.map((name) => ( + s.profiles); + const presets = usePresetStore((s) => s.presets); + const updateProfile = useProfileStore((s) => s.updateProfile); + const updatePreset = usePresetStore((s) => s.updatePreset); + const lastProfileId = useSettingsStore((s) => s.lastProfileId); + const lastPresetId = useSettingsStore((s) => s.lastPresetId); + // The drift hints compare against the whole form, so this re-renders with + // it — a card of two selects and two buttons. + const editor = useEditorStore(); + const [pending, setPending] = useState(null); + + const activeProfile = profiles.find((p) => p.id === lastProfileId); + const activePreset = presets.find((p) => p.id === lastPresetId); + const data = editorDataOf(editor); + // Compared the way applying would write them (legacy values mapped), so a + // freshly applied item never shows as changed. + const profileDrift = activeProfile + ? changedSince(data, normalizeEditorPatch(profilePatch(activeProfile))) + : []; + const presetDrift = activePreset + ? changedSince(data, normalizeEditorPatch(presetPatch(activePreset))) + : []; + + const usesPart = VIDEO_TYPES.find((v) => v.id === editor.videoType)?.extraFields.some( + (f) => f === "partNumber", + ); + const nextPart = nextPartNumber(editor.partNumber); + + const apply = (target: Pending) => { + if (target.kind === "profile") applyProfile(target.item); + else applyPreset(target.item); + }; + + const choose = (target: Omit) => { + const patch = + target.kind === "profile" + ? profilePatch(target.item as Profile) + : presetPatch(target.item as GamePreset); + const count = overwrittenFields(data, normalizeEditorPatch(patch)).length; + const full = { ...target, count } as Pending; + if (count > 0) setPending(full); + else apply(full); + }; + + const hasLibrary = profiles.length > 0 || presets.length > 0; + + return ( + + {hasLibrary ? ( +
+ ({ value: p.id, label: p.gameName })), + ]} + onChange={(id) => { + const item = presets.find((p) => p.id === id); + if (item) choose({ kind: "preset", item }); + }} + /> +
+ ) : ( +

+ {t("editor.quick.emptyLibrary")}{" "} + + {t("tabs.profiles")} + +

+ )} + + {activeProfile && profileDrift.length > 0 && ( + { + updateProfile(activeProfile.id, profileFieldsFromEditor(data)); + toast.success(t("profiles.updated", { name: activeProfile.name })); + }} + /> + )} + {activePreset && presetDrift.length > 0 && ( + { + updatePreset(activePreset.id, presetFieldsFromEditor(data)); + toast.success(t("presets.updated", { name: activePreset.gameName })); + }} + /> + )} + +
+ {usesPart && ( + + )} + +
+ + { + if (pending) apply(pending); + setPending(null); + }} + onCancel={() => setPending(null)} + /> +
+ ); +} + +function DriftHint({ + text, + action, + onUpdate, +}: { + text: string; + action: string; + onUpdate: () => void; +}) { + return ( +
+

{text}

+ +
+ ); +} diff --git a/src/components/editor/SocialEditor.tsx b/src/components/editor/SocialEditor.tsx index d80dfbf..61e62ee 100644 --- a/src/components/editor/SocialEditor.tsx +++ b/src/components/editor/SocialEditor.tsx @@ -18,7 +18,9 @@ export function SocialEditor() { {t("editor.social")}
- Donate + + {t("editor.socialGroups.donate")} + {donateFields.map((field) => (
- Social + + {t("editor.socialGroups.social")} + {socialFields.map((field) => ( field.urlPrefix ? validateUrlWithPrefix(v, field.urlPrefix) : validateUrl(v) } - helpText={ - field.id === "mastodon" - ? "Full URL including instance, e.g. https://mastodon.social/@user" - : undefined - } + helpText={field.id === "mastodon" ? t("editor.mastodonHelp") : undefined} /> ))}
diff --git a/src/components/editor/StoreLinkEditor.tsx b/src/components/editor/StoreLinkEditor.tsx index bb02bbd..1bbe7e8 100644 --- a/src/components/editor/StoreLinkEditor.tsx +++ b/src/components/editor/StoreLinkEditor.tsx @@ -8,6 +8,7 @@ import { PLATFORMS } from "@config/platforms"; import { useEditorStore } from "@store/editor-store"; import { validateUrlWithPattern } from "@utils/validation"; import { extractGameNameFromUrl, isLinkNameMismatch } from "@utils/url-extractors"; +import { applyStoreLink, matchStoreLink } from "@utils/store-paste"; import type { StoreLinkType } from "@engine/types"; import { FIELD_LIMITS } from "@config/field-limits"; @@ -67,10 +68,17 @@ export function StoreLinkEditor() { // Game Name field is still empty, auto-fill it from the URL slug. The // toast carries an Undo action so a wrong guess is one click away from // being reverted. Never overwrites a non-empty Game Name. - const handlePaste = (e: ClipboardEvent) => { - if (gameName.trim()) return; + const handlePaste = (e: ClipboardEvent, platformId: string) => { const pasted = e.clipboardData.getData("text").trim(); if (!pasted) return; + // A link for another store goes to that store's field. + const match = matchStoreLink(pasted); + if (match && match.platformId !== platformId) { + e.preventDefault(); + applyStoreLink(match); + return; + } + if (gameName.trim()) return; const extracted = extractGameNameFromUrl(pasted); if (!extracted) return; @@ -131,7 +139,7 @@ export function StoreLinkEditor() { setNested("storeLinks", platform.id, final); }} validate={(v) => validateUrlWithPattern(v, platform.urlPattern)} - onPaste={handlePaste} + onPaste={(e) => handlePaste(e, platform.id)} /> s.showQualityBadge); + const titleFormat = useSettingsStore((s) => s.titleFormat); + const setTitleFormat = useSettingsStore((s) => s.setTitleFormat); // Lazy-loaded locales (v0.26): only request the bundle while the modal // is actually open; the list fills in on the ready flip. - const ready = useLanguagesReady(open ? [state.language] : []); + const ready = useLanguagesReady(open ? [input.language] : []); const variants = useMemo(() => { if (!open || !ready) return []; - const input: GeneratorInput = { - videoType: state.videoType, - language: state.language, - genres: state.genres, - gameName: state.gameName, - gameNameLocalized: state.gameNameLocalized, - channelName: state.channelName, - platform: state.platform, - partNumber: state.partNumber, - bossName: state.bossName, - dlcName: state.dlcName, - challengeName: state.challengeName, - modName: state.modName, - resolution: state.resolution, - fps: state.fps, - graphicsPreset: state.graphicsPreset, - spoilerWarning: state.spoilerWarning, - matureWarning: state.matureWarning, - storeLinks: state.storeLinks, - social: state.social, - rig: state.rig, + const tFn = i18n.getFixedT(input.language, "templates"); + return buildTitleVariants(input, tFn, { ...titleFormat, showQualityBadge }); + }, [open, ready, input, titleFormat, showQualityBadge]); + + const isCurrent = (variant: TitleVariant) => + (titleFormat.order ?? "gameFirst") === variant.format.order && + titleFormat.badgePosition === variant.format.badgePosition; + + // Without a quality badge two shapes read the same; list each title once, + // preferring the one in use. + const shown = variants.filter((variant, index) => { + if (isCurrent(variant)) return true; + const current = variants.find(isCurrent); + if (current && current.title === variant.title) return false; + return variants.findIndex((other) => other.title === variant.title) === index; + }); + + const apply = (variant: TitleVariant) => { + const before = { + order: titleFormat.order ?? "gameFirst", + badgePosition: titleFormat.badgePosition, }; - const tFn = i18n.getFixedT(state.language, "templates"); - return buildTitleVariants(input, tFn, showQualityBadge); - }, [ - open, - ready, - showQualityBadge, - state.videoType, - state.language, - state.genres, - state.gameName, - state.gameNameLocalized, - state.channelName, - state.platform, - state.partNumber, - state.bossName, - state.dlcName, - state.challengeName, - state.modName, - state.resolution, - state.fps, - state.graphicsPreset, - state.spoilerWarning, - state.matureWarning, - state.storeLinks, - state.social, - state.rig, - ]); + setTitleFormat(variant.format); + toast.success(t("output.variantApplied", { name: t(variant.labelKey) }), { + action: { label: t("common.undo"), onClick: () => setTitleFormat(before) }, + }); + onClose(); + }; return ( - +
- {variants.map((variant) => ( -
-
-

- {t(variant.labelKey)} -

-
- - + {shown.map((variant) => { + const over = variant.title.length > YT_LIMITS.TITLE_MAX; + const current = isCurrent(variant); + return ( +
+
+

+ {t(variant.labelKey)} + {current && {t("output.variantCurrent")}} +

+
+ + + {!current && ( + + )} +
-
-

- {variant.title} -

-
- ))} +

+ {variant.title} +

+ + ); + })}
); diff --git a/src/components/presets/PresetSelector.tsx b/src/components/presets/PresetSelector.tsx deleted file mode 100644 index 5e02662..0000000 --- a/src/components/presets/PresetSelector.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { useTranslation } from "react-i18next"; -import { Select } from "@components/ui/Select"; -import { usePresetStore } from "@store/preset-store"; -import { applyPreset } from "@utils/library-apply"; - -/** Fill the game fields from a saved preset (with Undo). */ -export function PresetSelector() { - const { t } = useTranslation("ui"); - const presets = usePresetStore((s) => s.presets); - - if (presets.length === 0) return null; - - const options = [ - { value: "", label: t("presets.selectPreset") }, - ...presets.map((p) => ({ value: p.id, label: p.gameName })), - ]; - - return ( -
diff --git a/src/pages/EditorPage.tsx b/src/pages/EditorPage.tsx index acbaa00..b249d6c 100644 --- a/src/pages/EditorPage.tsx +++ b/src/pages/EditorPage.tsx @@ -1,4 +1,4 @@ -import { useState, type ReactNode } from "react"; +import { useEffect, useState, type ReactNode } from "react"; import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { @@ -38,7 +38,7 @@ import { MusicAttributionEditor } from "@components/editor/MusicAttributionEdito import { SponsorCreditEditor } from "@components/editor/SponsorCreditEditor"; import { LivePreview } from "@components/editor/LivePreview"; import { DraftIndicator } from "@components/editor/DraftIndicator"; -import { PresetSelector } from "@components/presets/PresetSelector"; +import { QuickStart } from "@components/editor/QuickStart"; import { ValidatedInput } from "@components/ui/ValidatedInput"; import { Button } from "@components/ui/Button"; import { ConfirmDialog } from "@components/ui/ConfirmDialog"; @@ -51,6 +51,8 @@ import { VIDEO_TYPES } from "@config/video-types"; import { useEditorStore } from "@store/editor-store"; import { useSettingsStore } from "@store/settings-store"; import { useDocumentTitle } from "@hooks/use-document-title"; +import { startOver } from "@utils/library-apply"; +import { applyStoreLink, isTypingTarget, matchStoreLink } from "@utils/store-paste"; import { normalizePlaylistUrl, validatePlaylistUrl } from "@utils/validation"; interface Section { @@ -95,7 +97,6 @@ const SECTIONS: readonly Section[] = [ <> - @@ -175,7 +176,6 @@ function useSectionSummaries(): Partial> { export function EditorPage() { const { t } = useTranslation("ui"); useDocumentTitle(t("tabs.editor")); - const reset = useEditorStore((s) => s.reset); const accordion = useSettingsStore((s) => s.editorAccordionState); const toggleAccordion = useSettingsStore((s) => s.toggleEditorAccordion); const setAccordions = useSettingsStore((s) => s.setEditorAccordions); @@ -186,6 +186,20 @@ export function EditorPage() { const isOpen = (id: string): boolean => accordion[id] ?? false; const allOpen = SECTION_IDS.every(isOpen); + // A store link pasted while no field has focus still lands where it + // belongs (fields handle their own pastes). + useEffect(() => { + const onPaste = (e: ClipboardEvent) => { + if (isTypingTarget(document.activeElement)) return; + const match = matchStoreLink(e.clipboardData?.getData("text") ?? ""); + if (!match) return; + e.preventDefault(); + applyStoreLink(match); + }; + document.addEventListener("paste", onPaste); + return () => document.removeEventListener("paste", onPaste); + }, []); + return (