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

share scenario button / basically, allow scenario to be encoded in URL #2

Closed
dieck opened this issue Jan 5, 2019 · 6 comments
Closed

Comments

@dieck
Copy link

dieck commented Jan 5, 2019

Hi!

I am not quite sure, but if you store everything in localStorage anyway, wouldn't is be the easiest way to export and import that whole thing?

// Export localStorage to Base64 encoded JSON to present to user
var toExport = window.btoa( unescape( encodeURIComponent( JSON.stringify( JSON.stringify( localStorage)))));

and

// Import Base64 encoded JSON into localStorage
var tmpdata = JSON.parse( decodeURIComponent( escape( window.atob( toImport))));
Object.keys(tmpdata).forEach(function (k) { localStorage.setItem(k, data[k]); });

I am not that familiar with React, otherwise I might have tried to create a pull request :)

Possible enhancements: Compression, e.g. https://github.com/pieroxy/lz-string/ or https://github.com/tcorral/JSONC

@AluminumAngel
Copy link
Owner

What are the advantages of that approach?

How does your code slot into the functions storeState() and restoreState()?

@dieck
Copy link
Author

dieck commented Jan 6, 2019

Well, storeState() and restoreState() work only locally in your browser.
The lines above* can be used to export to a (long) string and import from that, to present to the user and thus traverse browsers and computers.

(* They are untested, and maybe not very efficient or elegant, but should do the trick)

I am just setting up a flask environment to take a look at the system myself, maybe I can propose a pull after all

@AluminumAngel
Copy link
Owner

I see what you are saying. Encoding the scenario in a URL, to allow sharing, is a very good idea.

@omireault
Copy link

omireault commented Jan 10, 2019

This could be used to crowd-source the scenario implementations. You can curate a bookmarked URL list that will load each scenario, room by room. Once someone trustworthy has validated the URL does correspond to the scenario, it can be added under a new Bookmark button or something in the app itself for everyone to use.

@AluminumAngel
Copy link
Owner

Agreed. This can be a powerful feature. Got me excited enough to pick the project back up again.

I did a test of the naive solution, and unfortunately it resulted in 10K URLs. I've got something more sophisticated working. Need to add validation and clean it up. Soon.

@AluminumAngel
Copy link
Owner

AluminumAngel commented Jan 20, 2019

Great idea! Feature added at fb27077.

Deploying now.

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

No branches or pull requests

3 participants