From 3c985a07d6d59dd478cd23b8afb7f5beaa900fe5 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Wed, 30 Sep 2026 22:29:44 +0700 Subject: [PATCH] feat(editor): quick start, next part, store links pasted anywhere, more stores and platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Editor: - Quick start at the top: pick the channel profile and the game preset (remembered per device); replacing fields that hold something else asks first, everything offers Undo; "Update profile / preset" appears when the editor drifts from the one in use. - Next part (number + 1) and New video (same game) clear what belonged to the last video: boss, timestamps, endings, pinned comment, sponsor… Applying a preset for another game or a template does the same first. - Start over replaces Clear Draft and keeps the channel (profile fields); a new draft starts in the Default Output Language (it was always "en"). - A store link pasted anywhere — the page, the Game name field, another store's field — lands in the right store field, sets the platform for a game's first link and names the game from it (Roman numerals and well-known possessives restored: "Final Fantasy VII", "Baldur's Gate 3"). Steam links keep their name slug and drop tracking parameters. - Game-name suggestions from presets and history. Catalogs: - Stores: EA app, Ubisoft, Battle.net, Google Play, App Store, Meta Quest. - Social: YouTube, Threads, Kick, Reddit, Bilibili; "X (Twitter)" with the X mark; threads.net and youtu.be links accepted. - Cross-posting: YouTube Shorts, X (counted the way X counts — CJK, Vietnamese letters with diacritics and emoji count twice), Threads (one topic tag), Bluesky; hashtag caps per platform. - Banks: MBV, VCBNeo, Vikki Bank (renamed OceanBank, CBBank, DongA Bank — saved old names get a one-click switch), Cake by VPBank, Timo. Output: - An empty channel name no longer leaves "…of Hades on ." — the channel phrase is dropped per language (8 locales, every template tested). - Title alternatives are real title shapes with the user's separator and badge case; "Use this shape" sets them (new Title order setting: game first / video first); over-long ones can't be copied. - Copy All can include the tags (setting); Batch picks Part or Demo part and continues from the editor's part number; Ctrl/Cmd+S saves the output to History. - Social editor headings and hints translated. Co-Authored-By: Claude Opus 5.5 --- src/App.tsx | 15 + src/components/editor/GameInfoForm.tsx | 38 +++ src/components/editor/QuickStart.tsx | 201 +++++++++++++ src/components/editor/SocialEditor.tsx | 14 +- src/components/editor/StoreLinkEditor.tsx | 14 +- .../editor/VietnameseDonateEditor.tsx | 18 ++ src/components/icons/brand.tsx | 2 + src/components/output/VariantPicker.tsx | 155 +++++----- src/components/presets/PresetSelector.tsx | 29 -- src/components/ui/ShortcutHelpModal.tsx | 2 +- src/config/library-fields.ts | 30 ++ src/config/platforms.ts | 57 +++- src/config/social-fields.ts | 38 ++- src/config/social-platforms.ts | 59 +++- src/config/vietnamese-banks.ts | 28 ++ src/engine/channel-phrase.ts | 62 ++++ src/engine/description-builder.ts | 12 +- src/engine/limits.ts | 21 +- src/engine/pinned-comment-builder.ts | 5 +- src/engine/playlist-builder.ts | 20 +- src/engine/social-post-builder.ts | 73 ++++- src/engine/template-renderer.ts | 1 + src/engine/title-builder.ts | 40 ++- src/engine/title-variants.ts | 75 ++--- src/engine/types.ts | 5 + src/hooks/use-keyboard-shortcuts.ts | 18 +- src/hooks/use-output-copy.ts | 11 +- src/hooks/use-save-to-history.ts | 44 +++ src/i18n/locales/_schema.json | 31 +- src/i18n/locales/en/ui.json | 78 ++++- src/i18n/locales/es/ui.json | 78 ++++- src/i18n/locales/id/ui.json | 78 ++++- src/i18n/locales/ja/ui.json | 78 ++++- src/i18n/locales/ko/ui.json | 78 ++++- src/i18n/locales/pt-BR/ui.json | 78 ++++- src/i18n/locales/vi/ui.json | 78 ++++- src/i18n/locales/zh/ui.json | 78 ++++- src/pages/BatchPage.tsx | 40 ++- src/pages/EditorPage.tsx | 32 +- src/pages/OutputPage.tsx | 20 +- src/pages/PlaylistPage.tsx | 2 +- src/pages/SettingsPage.tsx | 18 ++ src/pages/SocialPage.tsx | 12 +- src/store/settings-heal.ts | 23 ++ src/store/settings-store.ts | 3 + src/utils/backup/sanitize.ts | 2 + src/utils/library-apply.ts | 150 ++++++++-- src/utils/store-paste.ts | 76 +++++ src/utils/url-extractors.ts | 68 ++++- src/utils/validation.ts | 4 +- tests/config/platforms.test.ts | 8 +- tests/engine/channel-phrase.test.ts | 68 +++++ tests/engine/description-builder.test.ts | 2 +- tests/engine/quick-entry-engine.test.ts | 122 ++++++++ tests/store/settings-heal.test.ts | 23 ++ tests/utils/quick-entry.test.ts | 276 ++++++++++++++++++ tests/utils/url-extractors.test.ts | 6 +- tests/utils/validation.test.ts | 8 +- 58 files changed, 2297 insertions(+), 408 deletions(-) create mode 100644 src/components/editor/QuickStart.tsx delete mode 100644 src/components/presets/PresetSelector.tsx create mode 100644 src/engine/channel-phrase.ts create mode 100644 src/hooks/use-save-to-history.ts create mode 100644 src/utils/store-paste.ts create mode 100644 tests/engine/channel-phrase.test.ts create mode 100644 tests/engine/quick-entry-engine.test.ts create mode 100644 tests/utils/quick-entry.test.ts 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 (