From 085ac1a5f780996b2cb7033aa253ecd370873c50 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Sat, 6 Dec 2025 23:39:31 +0100 Subject: [PATCH] Fix pattern re-upload after deletion by preserving filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix bug where deleting a cached pattern prevented re-uploading because the filename was lost. After deletion, the pattern remains visible in the UI for re-editing and re-uploading, but the upload would silently fail because displayFileName was empty. The issue occurred because: 1. Pattern loaded from cache uses resumeFileName (from hook) 2. Local fileName state in FileUpload was never set (empty string) 3. After deletion, resumeFileName is cleared to null 4. displayFileName becomes empty, preventing upload Solution: - Add fallback to 'pattern.pes' when pesDataProp exists but no filename - This ensures re-upload works after deletion while keeping pattern visible - Pattern data (pesData) persists in App.tsx state for re-editing Now users can delete a cached pattern and immediately re-upload it with position adjustments or other modifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/components/FileUpload.tsx | 3 ++- src/hooks/useBrotherMachine.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/FileUpload.tsx b/src/components/FileUpload.tsx index b9e406a..4cf0031 100644 --- a/src/components/FileUpload.tsx +++ b/src/components/FileUpload.tsx @@ -39,7 +39,8 @@ export function FileUpload({ // Use prop pesData if available (from cached pattern), otherwise use local state const pesData = pesDataProp || localPesData; - const displayFileName = resumeFileName || fileName; + // When resumeFileName is cleared but we still have pesData, preserve the filename + const displayFileName = resumeFileName || fileName || (pesDataProp ? 'pattern.pes' : ''); const [isLoading, setIsLoading] = useState(false); const handleFileChange = useCallback( diff --git a/src/hooks/useBrotherMachine.ts b/src/hooks/useBrotherMachine.ts index 699175c..1229b57 100644 --- a/src/hooks/useBrotherMachine.ts +++ b/src/hooks/useBrotherMachine.ts @@ -306,6 +306,7 @@ export function useBrotherMachine() { setResumeFileName(null); // NOTE: We intentionally DON'T clear setResumedPattern(null) // so the pattern remains visible in the canvas for re-editing + // However, we DO need to preserve pesData in App.tsx for re-upload await refreshStatus(); } catch (err) {