Skip to content

Commit

Permalink
Store currently-selected listing in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Mar 12, 2024
1 parent 3ac06ed commit e35c2d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class Selector {
let names = this.model.storage.list();

let first = names ? names[0] : null;
let stored = this.model.storage.loadMetadata("__name__");

this.state.name = this.state.name || first;
this.state.name = this.state.name || stored || first;

// Set the selector list with those names.
this.setNames(names, this.state.name);
Expand Down Expand Up @@ -137,6 +138,8 @@ class Selector {
// Update the state.
this.state.name = name;

this.model.storage.storeMetadata("__name__", name);

// Emit the select event.
this.dispatcher.select(this, name);
}
Expand Down
12 changes: 12 additions & 0 deletions scripts/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ class Storage {
/* Public functions */
/*********************************************************************************************/

storeMetadata(key, value) {
if (key.startsWith("__")) {
localStorage.setItem(key, value);
}
}

loadMetadata(key) {
if (key.startsWith("__")) {
return localStorage.getItem(key);
}
}

count() {
return this.list().length;
}
Expand Down

0 comments on commit e35c2d1

Please sign in to comment.