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

Shareable boards (via links?) #33

Open
jedahan opened this issue Feb 16, 2021 · 1 comment
Open

Shareable boards (via links?) #33

jedahan opened this issue Feb 16, 2021 · 1 comment

Comments

@jedahan
Copy link

jedahan commented Feb 16, 2021

Lovely project. A few years ago I made something that has a small overlap with this one, and implemented a fun feature where I could share a board just through a link. Basic idea was every few seconds, I would update the fragment url with an encoded version of the data. That way I could copy the link, send it to someone, and they would effectively have a local 'fork' of the board.

The relevant ~25 lines of logic code can be found here https://github.com/jedahan/saltpeanuts/blob/master/app.js#L1-L45 , but the gist is:

const data = (() => {
  const hash = rison.decode_object(decodeURI(window.location.hash.substring(1)));
  if (hash.updated > 0) { return hash; }

  const local = rison.decode_object(localStorage.getItem('saltpeanuts') || '');
  if (local.updated > 0) { return local; }

  return {
    updated: new Date(),
    blocks: [ 'study japanese', 'email', 'mozilla/nsf', 'click me!', 'elusive index 4' ],
    schedule: {
      monday: [1, 0, 0, 4],
      tuesday: [4, 4, 4, 4],
      wednesday: [],
      thursday: [],
      friday: [],
    },
  };
})();

window.setInterval(function() {
  data.updated = new Date();
  const datastring = rison.encode_object(data);

  localStorage.setItem('saltpeanuts', datastring);
  window.location.hash = datastring;
}, 2000 );

I used rison to encode the data in human-readable, url-safe format, but you can use whatever format you prefer or write your own encode/decoder if importing the ~500 line rison.js is too heavy.

@jedahan
Copy link
Author

jedahan commented Feb 16, 2021

A potentially lighter-weight and 'more standards compliant' encoding scheme may be selectors/states from https://w3c.github.io/web-annotation/selector-note/converter/ and https://w3c.github.io/web-annotation/selector-note/

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

1 participant