Choose save location and filename when saving a map to machine - #1514
Open
spencerpruitt wants to merge 1 commit into
Open
Choose save location and filename when saving a map to machine#1514spencerpruitt wants to merge 1 commit into
spencerpruitt wants to merge 1 commit into
Conversation
Saving a map to the local machine dropped the .map file into the browser's Downloads folder under an auto-generated name, with no way to choose where it goes. This adds an OS "Save As" dialog on every Save to Machine so the user picks the folder and filename each time — overwrite an existing file by re-selecting it, or write a new file by choosing a new name/folder. The dialog is pre-filled with the usual name and filtered to .map. Uses the File System Access API (showSaveFilePicker), available in Chromium-based browsers. Firefox/Safari lack it and fall back to the existing Downloads behavior, with a one-time note explaining why. - src/io/save-to-file.ts: new module wrapping the picker and the fallback, returning a discriminated outcome (saved | downloaded-fallback | cancelled). Cancel (AbortError, checked by name so a DOMException is handled) is a silent no-op; the fallback reuses the shared downloadFile helper; write/permission errors propagate to the existing save dialog. - src/io/save.ts: saveToMachine routes through it and maps outcomes to tips; the one-time fallback note's localStorage access is guarded so a save never fails when storage is blocked (e.g. Safari private mode). - Unit tests stub the browser globals; vitest.config gains the "@" -> src alias (mirroring vite.config.ts / tsconfig) so tests resolve runtime @/ imports. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for afmg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Today, Save → machine writes the
.mapfile straight to the browser's Downloads folder under an auto-generated name. There's no way to choose where the file goes or what it's called, so users have to fish the file out of Downloads and move it, and can't decide whether to overwrite an existing map or keep a separate copy.This PR makes Save to Machine open the OS "Save As" dialog every time, so the user chooses the folder and filename on each save:
The dialog is pre-filled with the usual
<map name> <timestamp>and filtered to.map.Browser support
Uses the File System Access API (
showSaveFilePicker), available in Chromium-based browsers (Chrome, Edge, Opera, Brave). Firefox and Safari don't support it, so they fall back to the existing Downloads behaviour (via the shareddownloadFilehelper), with a one-time tip explaining why the picker wasn't offered. Saving works everywhere.Scope
Only the
.mapSave to Machine path — the machine button and the Ctrl+S hotkey, which sharesaveMap("machine"). Dropbox, browser-storage save, auto-save, and all exports are unchanged.Implementation
src/io/save-to-file.ts(new): a small module wrapping the picker and the fallback behind one function,saveToFileSystem(mapData, suggestedName), returning a discriminated outcome —saved/downloaded-fallback/cancelled. It holds no cross-save state. Cancelling the dialog (AbortError, matched by name so aDOMExceptionis handled too) is a silent no-op; write/permission errors propagate to the existing save error dialog.src/io/save.ts:saveToMachineroutes through the new module and maps the outcome to the usualtip(...)messages. The one-time fallback note is remembered inlocalStorage, guarded so a save never fails if storage is blocked (e.g. Safari private mode).vitest.config.ts: adds the@→srcalias (mirroringvite.config.ts/tsconfig) so unit tests can resolve runtime@/...imports.Tests
New Vitest unit tests stub the browser globals and cover: the picker opens on every save; the suggested name and
.mapfilter are passed; cancel (including a DOMException-style AbortError) is a no-op; an unsupported browser delegates todownloadFile; write/permission errors propagate; and the outcome → tip mapping including the one-time fallback note and the storage-unavailable case.Manual testing
🤖 Generated with Claude Code