Skip to content

feat: add ability to save files#204

Merged
cguedes merged 9 commits into
mainfrom
197-save-files
Jun 28, 2023
Merged

feat: add ability to save files#204
cguedes merged 9 commits into
mainfrom
197-save-files

Conversation

@sehyod

@sehyod sehyod commented Jun 27, 2023

Copy link
Copy Markdown
Collaborator

This adds the ability to save files:

  • Files are saved in memory so that switching between tabs does not reset the content
  • Pressing cmd+S (or ctrl+S in non-macOS environment) saves the file on the disk
  • Saving is also available in the top menu, in File->Save
Screen.Recording.2023-06-27.at.13.06.39.mov

Implementation choices:
Four atoms are available for files:

  • loadableFileAtom is the atom containing the loadable file (the state is loading when initially reading the file from disk, and should stay hasData afterwards)
  • updateFileBufferAtom updates a buffer atom. This is currently updated on every update in the editor. The need of a buffer comes from the fact that updating the actual atom triggers a re-render of the editor, that deletes the history and resets focus
  • saveFileInMemoryAtom saves the content of the buffer in the loadableFileAtom. This atom is currently called when an editor instance is unmounted (ie. when switching between tabs)
  • saveFileAtom actually writes the content of the buffer on the disk. It does NOT update the loadableFileAtom, to prevent the editor from re-rendering and resetting focus and history.

Closes #197

@sehyod sehyod requested a review from cguedes June 27, 2023 12:06
@codecov

codecov Bot commented Jun 27, 2023

Copy link
Copy Markdown

Codecov Report

Merging #204 (e4250db) into main (90949c1) will increase coverage by 0.14%.
The diff coverage is 60.32%.

@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
+ Coverage   71.99%   72.13%   +0.14%     
==========================================
  Files          97       99       +2     
  Lines        4859     4974     +115     
  Branches      391      405      +14     
==========================================
+ Hits         3498     3588      +90     
- Misses       1344     1369      +25     
  Partials       17       17              
Impacted Files Coverage Δ
src/App.tsx 0.00% <0.00%> (ø)
src/editor/TipTapEditor.tsx 0.00% <0.00%> (ø)
src/panels/MainPanel.tsx 0.00% <0.00%> (ø)
src/views/TipTapView.tsx 0.00% <0.00%> (ø)
src/filesystem.ts 17.68% <12.50%> (-0.30%) ⬇️
src/EventsListener.tsx 100.00% <100.00%> (ø)
src/atoms/core/fileContent.ts 100.00% <100.00%> (ø)
src/atoms/core/paneGroup.ts 100.00% <100.00%> (ø)
src/atoms/createFileContentAtoms.ts 100.00% <100.00%> (ø)
src/atoms/fileActions.ts 100.00% <100.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

cguedes
cguedes previously approved these changes Jun 27, 2023
Comment thread src/atoms/fileActions.test.ts
cguedes
cguedes previously approved these changes Jun 28, 2023
@cguedes cguedes merged commit 1b64038 into main Jun 28, 2023
@cguedes cguedes deleted the 197-save-files branch June 28, 2023 10:01
@danvk

danvk commented Jun 29, 2023

Copy link
Copy Markdown
Collaborator

Exciting that we can persist files now! Two questions:

  • Is there a "factory reset" option available? I was playing around with Tiptap and got myself into a bad state. Running yarn tauri:dev:debug no longer resets my state, so I'm not sure how to get out of this.
  • When you save a file to disk, where does it go? The refstudio directory?

@sehyod

sehyod commented Jun 30, 2023

Copy link
Copy Markdown
Collaborator Author
  • There is no such option for now. However, we are planning on adding the ability to remove files (see Add ability to delete files #212). Could you give more details about the bad state you got yourself into? Maybe it's worth filing an issue about it?
  • It goes to the project subdirectory in the refstudio directory. Something like /Users/$USER/Library/Application Support/com.tauri.dev/project-x

@cguedes

cguedes commented Jun 30, 2023

Copy link
Copy Markdown
Collaborator

@danvk we've had to update the references model (FE), and since we persist that information in the localStorage sometimes you need to reset that info using the UI (i.e. "DEBUG: reset references store") or directly via dev tools (Application > Storage). I normally also run the ./scripts/reset_uploads.sh utility script to reset all the BE data.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to save files

3 participants