Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented autosave on a 5-second timer #3037

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Levi-Lesches
Copy link

Fixes #2871 by saving the editor content to local storage under they key user_input every 5 seconds, and in dispose


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@Levi-Lesches
Copy link
Author

@parlough I fixed the double quotes

Copy link
Member

@parlough parlough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Thanks so much for implementing this again :D

pkgs/dartpad_ui/lib/editor/editor.dart Outdated Show resolved Hide resolved
Comment on lines +281 to +282
fallbackSnippet: web.window.localStorage.getItem('user_input') ??
Samples.getDefault(type: 'dart'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth it to convert this fallback to a callback, so we don't unnecessarily retrieve the old snippet?

Copy link
Author

@Levi-Lesches Levi-Lesches Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ?? is short circuiting, so it should be fine? EDIT: Just checked, it is

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, if you meant not retrieving the old snippet or user input in case a gist id or otherwise is provided.

I tried making it a callback, and got some very strange errors on the web side. Each time I restarted, it was that JS can't read some property, but it was a different property each time. Once it didn't even let the flutter tool connect because the bootstrapper got stuck. Not sure what's up with that but I'll leave the PR as-is for now

@Levi-Lesches
Copy link
Author

@parlough Any updates?

@Levi-Lesches
Copy link
Author

Sorry for the annoying pings, just want to make sure this doesn't slip between the cracks

@parlough
Copy link
Member

@Levi-Lesches Sorry for the delay, I've been away.

The change looks good to me, but before landing, we need to wait for others to determine DartPad's storage policies and how we will inform users of them.

I'll land this PR when able and ping you if any changes are needed.

Thanks again!

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 support for automatically saving most recent snippet to local storage
2 participants