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

Adds project save/load functionality to :play #37

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

Conversation

gunsch
Copy link
Collaborator

@gunsch gunsch commented Sep 27, 2024

💸 TL;DR

Replaces the "Export" button with a "Project" drop-down menu that includes "Save", "Load", and "Export".

"Save" and "Load" allow the user to develop on multiple projects at a time.

📜 Details

Some notes on implementation:

  • Storage and data

    • The data model has Projects, which each have ProjectFiles[], to allow for building multi-file storage later. (though just runs with one file for now)
    • The backing data store can be swapped out by the play embedder, allowing us to persist these when hosted on Dev Portal. The local implementation uses a simple IndexedDB as a slightly fancier localStorage.
    • This does not currently support the "static asset management" stuff that @ObsidianSnoo added a bit ago.
  • UI

    • I tried to align the existing "name" concept (top-left of the play UI) with the saved Project name. Those should generally stay in sync and help inform each other (i.e. if you set a "name", that's the default suggested value when you go to save the Project).
    • The dialog boxes are kinda ugly right now, I know. Gonna chat with Knut about that soon.
    • There's an odd interplay between the URL-based "save" (that I've now renamed "autosave") and the new project save/load functionality. I've tried to make them play nicely together but it's not ideal. Gonna chat with Knut about this also.
    • There's a placeholder for a "account button" so that Portal can inject a logged-in UI chip + dropdown.
  • Project doc

  • Jira: add project menu

  • Jira: add project save/load functionality

🧪 Testing Steps / Validation

This was built during snoosweek with a lot of eyes on it from me, Andrei, and Emi! Trying to get it cleaned up and landed now.

Menu:
image

Save dialog:
image

Load dialog:
image

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

wu-emi and others added 4 commits August 21, 2024 09:00
Adds a slot for account button in play-pen-header, that can be specified via play-pen.
## 💸 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)
@@ -60,8 +60,8 @@
"gzip": "3.5 KB"
},
"dist/play-pen.js": {
"none": "31900 KB",
"gzip": "5150 KB"
"none": "32100 KB",
Copy link
Member

Choose a reason for hiding this comment

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

this is a pretty big bump. does this PR really add 200 KB?

@@ -150,10 +150,12 @@ export class PlayNewPenButton extends LitElement {
<div class="container">
<button
class="new-pen"
@click=${() =>
@click=${() => {
this.dispatchEvent(Bubble<string>('new-project', ''))
Copy link
Member

Choose a reason for hiding this comment

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

would you mind updating the HTMLElementEventMap at the top of the file? same thing for other events in the patch.

@@ -0,0 +1,35 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

would you mind using types over interfaces where possible? interfaces are open and can be merged (eg, HTMLElementEventMap); types are closed and defined at creation.

* This can be injected into play-pen to provide a different implementation.
*/
export interface ProjectStorageClient {
CreateProject(name: string): Promise<PlayProject>
Copy link
Member

Choose a reason for hiding this comment

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

is this a Protobuf type? if not, can we use camelCase?

/** readonly */
id?: string | undefined
name: string
/** readonly */
Copy link
Member

Choose a reason for hiding this comment

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

should we mark these with the readonly keyword?


declare global {
interface HTMLElementEventMap {
'edit-src': CustomEvent<string>
Copy link
Member

Choose a reason for hiding this comment

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

copypasta?

@click=${() =>
this.dispatchEvent(
new CustomEvent('open-export-dialog', {
bubbles: true,
Copy link
Member

Choose a reason for hiding this comment

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

can we use utils/bubble?

Comment on lines +78 to +79
<input
type="button"
Copy link
Member

Choose a reason for hiding this comment

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

why can't we use a button?


@property() src: string = ''

@state() private _loading = false
Copy link
Member

Choose a reason for hiding this comment

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

🔕 please type all members.

@@ -0,0 +1,118 @@
// Implementation of ProjectStorageClient backed by IndexedDB,
Copy link
Member

Choose a reason for hiding this comment

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

@gunsch @ObsidianSnoo, this adds another data source and removes some of the focus of play as a dumb fiddle. I think we should get together next week and chat about realistic goals for play to avoid remaking the organic mistakes of Studio. Ryan and I chatted earlier in the year about needing to do some refactors for internal vs external features, single file support, and other topics but haven't had much time to work on it.

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.

3 participants