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

Add basic URL Encoding for scratchpad text state #1441

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Conversation

gcrois
Copy link

@gcrois gcrois commented Dec 12, 2024

This branch implements a basic mechanism to encode and retrieve the text state of a scratchpad:

Screenshot 2024-12-12 at 1 54 49 PM

Currently, this takes precedence over the local store.

Example: prime finder

Future potential improvements:

  1. String compression for larger programs (URL limit is around 2k characters)
  2. Use GitHub API to retrieve a gist (save too?)
  3. Add a fun icon for the button
  4. Encode more parts of the application state (active view? livelit model?)

Comment on lines +70 to +87
// Override the load function
let load = (): t => {
switch (JsUtil.QueryParams.get_param(key_string)) {
| Some(data) =>
let decompressed = StringUtil.decompress(data);
let zip = Haz3lcore.Printer.zipper_of_string(decompressed);
switch (zip) {
| Some(zip) => (0, [PersistentZipper.persist(zip)])
| None => init()
};
| None =>
switch (JsUtil.get_localstore(key_string)) {
| None => init()
| Some(data) => deserialize(data, default())
}
};
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This blows away all the scratch buffers a user currently has. Not sure how we want to handle it. We could create a new scratch buffer or maybe highjack the active one?

Copy link
Author

Choose a reason for hiding this comment

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

I think my ideal solution here is for the URL to encode some arbitrary partial state -- some of which could be a named scratchpad added to the editor state -- maybe the default names would be protected to prevent malicious links deleting existing work.

Alternatively (and more easily), we could have some "visitor" mode in which your state isn't persisted through traditional methods, and some option to merge the visitor state with your local state.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the easiest thing is to just add a third section under scratch and documentation that only shows up if you're using the share url.

Copy link
Author

Choose a reason for hiding this comment

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

lol... you're totally right, that's way easier

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.

2 participants