From 2a386f99b0f28afba19532ef64756ddedcd1a50e Mon Sep 17 00:00:00 2001 From: David Montero Date: Sun, 5 Apr 2026 22:27:17 +0200 Subject: [PATCH] fix: SaveProjectModal uses active board files/kind and better error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs fixed: 1. SaveProjectModal was reading from the legacy global `files` array instead of the active board's file group, causing projects to be saved with the wrong board_type (e.g. 'arduino-uno' for ESP32 projects). Now reads from fileGroups[activeBoard.activeFileGroupId] and uses activeBoard.boardKind for board_type. 2. Error handling was always showing "Save failed." — now shows: - "Server unreachable. Check your connection and try again." for network errors - "Not authenticated. Please log in and try again." for 401 responses - The server's detail message (with status code) for other errors Co-Authored-By: Claude Sonnet 4.6 --- .../components/layout/SaveProjectModal.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/layout/SaveProjectModal.tsx b/frontend/src/components/layout/SaveProjectModal.tsx index dc3181d..4d0b073 100644 --- a/frontend/src/components/layout/SaveProjectModal.tsx +++ b/frontend/src/components/layout/SaveProjectModal.tsx @@ -12,10 +12,17 @@ interface SaveProjectModalProps { export const SaveProjectModal: React.FC = ({ onClose }) => { const navigate = useNavigate(); - const files = useEditorStore((s) => s.files); + const { boards, activeBoardId, components, wires } = useSimulatorStore(); + const activeBoard = boards.find((b) => b.id === activeBoardId) ?? boards[0]; + // Use the active board's file group; fall back to legacy global files + const activeFiles = useEditorStore((s) => + (s.fileGroups[activeBoard?.activeFileGroupId ?? '']?.length + ? s.fileGroups[activeBoard.activeFileGroupId] + : s.files) ?? s.files + ); + const boardKind = activeBoard?.boardKind ?? 'arduino-uno'; // Legacy: save primary .ino content for the project code field - const code = files.find((f) => f.name === 'sketch.ino')?.content ?? files[0]?.content ?? ''; - const { boardType, components, wires } = useSimulatorStore(); + const code = activeFiles.find((f) => f.name.endsWith('.ino'))?.content ?? activeFiles[0]?.content ?? ''; const currentProject = useProjectStore((s) => s.currentProject); const setCurrentProject = useProjectStore((s) => s.setCurrentProject); @@ -44,8 +51,8 @@ export const SaveProjectModal: React.FC = ({ onClose }) = name: name.trim(), description: description.trim() || undefined, is_public: isPublic, - board_type: boardType, - files: files.map((f) => ({ name: f.name, content: f.content })), + board_type: boardKind, + files: activeFiles.map((f) => ({ name: f.name, content: f.content })), code, components_json: JSON.stringify(components), wires_json: JSON.stringify(wires), @@ -69,7 +76,13 @@ export const SaveProjectModal: React.FC = ({ onClose }) = navigate(`/project/${saved.id}`, { replace: true }); onClose(); } catch (err: any) { - setError(err?.response?.data?.detail || 'Save failed.'); + if (!err?.response) { + setError('Server unreachable. Check your connection and try again.'); + } else if (err.response.status === 401) { + setError('Not authenticated. Please log in and try again.'); + } else { + setError(err.response?.data?.detail || `Save failed (${err.response.status}).`); + } } finally { setSaving(false); }