diff --git a/src/components/DownloadResult.tsx b/src/components/DownloadResult.tsx index 9cb04286..6fac016a 100644 --- a/src/components/DownloadResult.tsx +++ b/src/components/DownloadResult.tsx @@ -3,7 +3,8 @@ import { useState, useEffect } from "react"; import { ExportResult } from "@/lib/types"; import { formatBytes } from "@/lib/utils"; -import { Download, RotateCcw, Share2, AlertCircle, Volume2, VolumeX } from "lucide-react"; +import { buildDownloadFilename } from "@/lib/fileNaming"; +import { Download, RotateCcw, Share2, Volume2, VolumeX } from "lucide-react"; import LottiePlayer from "./LottiePlayer"; import { NativeShareButton } from "./NativeShareButton"; import successAnim from "@/lib/lottie/success.json"; @@ -27,15 +28,17 @@ interface Props { onReset: () => void; soundOnCompletion: boolean; onToggleSound: () => void; + defaultName?: string; } -export default function DownloadResult({ result, onReset, soundOnCompletion, onToggleSound }: Props) { - const defaultName = `reframe_${result.width}x${result.height}`; - const [name, setName] = useState(defaultName); +export default function DownloadResult({ result, onReset, soundOnCompletion, onToggleSound, defaultName }: Props) { + const [name, setName] = useState(defaultName ?? `reframe_${result.width}x${result.height}`); - const invalidCharRegex = /[<>:"/\\|?*]/; - const isValid = !invalidCharRegex.test(name) && name.trim().length > 0; - const filename = `${name.trim() || "untitled"}.${result.format}`; + useEffect(() => { + setName(defaultName ?? `reframe_${result.width}x${result.height}`); + }, [defaultName, result.width, result.height]); + + const filename = buildDownloadFilename(name, result.format); const shareHref = `https://x.com/intent/tweet?text=${encodeURIComponent(SHARE_TWEET_TEXT)}`; @@ -105,7 +108,7 @@ export default function DownloadResult({ result, onReset, soundOnCompletion, onT - = 100 ? "text-[var(--error)] font-medium" : "text-[var(--muted)]")}> + {100 - name.length} chars remaining @@ -117,8 +120,7 @@ export default function DownloadResult({ result, onReset, soundOnCompletion, onT onChange={(e) => setName(e.target.value)} maxLength={100} className={cn( - "flex-1 px-3 py-2.5 bg-[var(--bg)] border rounded-lg text-sm transition-colors text-[var(--text)] placeholder:text-[var(--muted)]", - !isValid && name.length > 0 ? "border-[var(--error)] focus:outline-[var(--error)] focus:ring-1 focus:ring-[var(--error)]" : "border-[var(--border)] focus:outline-[var(--accent)]" + "flex-1 px-3 py-2.5 bg-[var(--bg)] border border-[var(--border)] rounded-lg text-sm transition-colors text-[var(--text)] placeholder:text-[var(--muted)] focus:outline-[var(--accent)]" )} placeholder="Enter filename" /> @@ -126,27 +128,16 @@ export default function DownloadResult({ result, onReset, soundOnCompletion, onT .{result.format} - {!isValid && name.length > 0 && ( -

- - Filename contains invalid characters (\ / : * ? " < > |) -

- )}
{ - if (!isValid) e.preventDefault(); - }} >