Skip to content

Implements project saving and loading in Play #35

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

Merged
merged 6 commits into from
Aug 22, 2024
Merged

Conversation

gunsch
Copy link
Collaborator

@gunsch gunsch commented Aug 21, 2024

💸 TL;DR

Implements Project-level saving and loading in Play.

Details

This includes:

  • Adding the Save/Load buttons in the Project menu
  • Dialogs for both Save and Load flows
  • Logic that proxies the actual storage to something behind the ProjectStorageClient interface, which can be swapped out later
  • Storing the current project in sessionStorage, so that it persists across reload but not across tabs
  • Making sure "New" projects clear the current stored project
  • Making sure we can load/save projects several times
  • Using the Pen title as the project name (both when saving and loading)

@gunsch gunsch changed the base branch from main to snoosweek August 22, 2024 04:12
@gunsch gunsch marked this pull request as ready for review August 22, 2024 04:13
@gunsch gunsch changed the title saving loading Implements project saving and loading in Play Aug 22, 2024
? html`
<div>
<select id="project-select" size="8">
${this._projects.map(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm curious what might be a good sort order to show these in. Last updated?

Comment on lines +54 to +62
return new Promise((resolve, reject) => {
const request = store.add(project)
request.onsuccess = () => {
resolve(project)
}
request.onerror = () => {
reject(request.error)
}
})

Choose a reason for hiding this comment

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

I wonder if we can create a helper for that (and other similar operations)

function IDBRequestToPromise<SuccessPayload>(request: IDBRequest, successPayload: SuccessPayload) {
return new Promise((resolve, reject) => {
      request.onsuccess = () => {
        resolve(successPayload)
      }
      request.onerror = () => {
        reject(request.error)
      }
    })
}
return IDBRequestToPromise<Project>(store.add(project), project);

Something like that. IDK if it's better or not for readability though.

@gunsch gunsch merged commit cde78f2 into snoosweek Aug 22, 2024
@gunsch gunsch deleted the saving-loading branch August 22, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants