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

Merged
merged 18 commits into from
Jan 16, 2025

Conversation

Levi-Lesches
Copy link
Contributor

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
Contributor 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
pkgs/dartpad_ui/lib/main.dart Outdated Show resolved Hide resolved
@Levi-Lesches
Copy link
Contributor Author

@parlough Any updates?

@Levi-Lesches
Copy link
Contributor 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!

@Levi-Lesches
Copy link
Contributor Author

Hi @parlough, any updates?

@johnpryan
Copy link
Contributor

We added a cookie banner now (#3097), so we should be OK to use local storage.

@Levi-Lesches
Copy link
Contributor Author

Levi-Lesches commented Dec 13, 2024

I'm trying to add an integration test that tests:

  • entering text really does save content to the local storage
  • loading the page results in the local storage text being displayed, unless
  • if the page is loaded with a Gist, checks that the Gist is loaded instead of the local storage

This will complicate CI a bit, so I'm updating the README with instructions from the Flutter docs.

@Levi-Lesches
Copy link
Contributor Author

Levi-Lesches commented Dec 13, 2024

I ended up going with unit tests instead as I couldn't get the integration tests to work: WidgetTester.enterText(String) calls WidgetTester.showKeyboard(), which requires an EditableText widget somewhere in the subtree, but the current setup with CodeMirror forwards keyboard input directly to the CodeMirror library without using Flutter's TextInput.

The test cases above are still tested, though, so I'm ready for another review.

EDIT ...okay, now I'm ready. I didn't add tests for:

  • Fallback shows when a Gist has no main.dart file, because the flutterdevrelgists account has no such gist
  • Flutter sample ID takes precedence, because I didn't want the tests to break when Flutter docs change

@Levi-Lesches
Copy link
Contributor Author

Hey, bumping this again

pkgs/dartpad_ui/lib/editor/editor.dart Outdated Show resolved Hide resolved
pkgs/dartpad_ui/test/autosave_test.dart Show resolved Hide resolved
pkgs/dartpad_ui/lib/main.dart Outdated Show resolved Hide resolved
pkgs/dartpad_ui/lib/editor/editor.dart Show resolved Hide resolved
pkgs/dartpad_ui/lib/local_storage.dart Show resolved Hide resolved
Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ✔️
File Coverage

This check for test coverage is informational (issues shown here will not fail the PR).

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/samples/lib/brick_breaker.dart
pkgs/samples/lib/fibonacci.dart
pkgs/samples/lib/google_ai.dart
pkgs/samples/lib/hello_world.dart
pkgs/samples/lib/main.dart
pkgs/samples/lib/sunflower.dart

@Levi-Lesches
Copy link
Contributor Author

@johnpryan

Habits of writing cross-platform code, but of course this is a web-only project. Removed the conditional import and replaced it with the real web implementation.

Forgot -- the tests don't work with web-only imports. Try running the CI now

@johnpryan johnpryan merged commit 4b1ab01 into dart-lang:main Jan 16, 2025
9 checks passed
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
3 participants