Skip to content

Commit

Permalink
Fix clipboard for empty browser cache (#1783)
Browse files Browse the repository at this point in the history
Set browser local storage values for clipboard if their corresponding
variables are null on load, which happens if the browser storage is
cleared.
  • Loading branch information
anvit committed Mar 27, 2024
1 parent 2ec316d commit 412a0eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
17 changes: 3 additions & 14 deletions js/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
this.storage = localStorage;
this.types = ['informationObject', 'actor', 'repository'];
this.initialItems = {'informationObject': [], 'actor': [], 'repository': []};
this.items = JSON.parse(this.storage.getItem('clipboard'));
this.exportTokens = JSON.parse(this.storage.getItem('exportTokens'));

if (!this.items)
{
this.items = this.initialItems;
}

if (!this.exportTokens)
{
this.exportTokens = [];
}

this.items = JSON.parse(this.storage.getItem('clipboard')) || this.initialItems;
this.exportTokens = JSON.parse(this.storage.getItem('exportTokens')) || [];
this.init();
};

Expand Down Expand Up @@ -344,7 +333,7 @@

// Load items from local storage in case activity
// in another tab has changed the content
this.items = JSON.parse(this.storage.getItem("clipboard"));
this.items = JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;

var type = $button.data('clipboard-type');
var slug = $button.data('clipboard-slug');
Expand Down
25 changes: 8 additions & 17 deletions plugins/arDominionB5Plugin/js/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,11 @@ import Tooltip from "bootstrap/js/dist/tooltip";

this.storage = localStorage;
this.types = ["informationObject", "actor", "repository"];
this.initialItems = JSON.stringify({
informationObject: [],
actor: [],
repository: [],
});
this.items = JSON.parse(this.storage.getItem("clipboard"));
this.exportTokens = JSON.parse(this.storage.getItem("exportTokens"));

if (!this.items) {
this.items = JSON.parse(this.initialItems);
}

if (!this.exportTokens) {
this.exportTokens = [];
}
this.initialItems = { informationObject: [], actor: [], repository: [] };
this.items =
JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;
this.exportTokens =
JSON.parse(this.storage.getItem("exportTokens")) || [];

this.init();
}
Expand Down Expand Up @@ -335,7 +325,8 @@ import Tooltip from "bootstrap/js/dist/tooltip";

// Load items from local storage in case activity
// in another tab has changed the content
this.items = JSON.parse(this.storage.getItem("clipboard"));
this.items =
JSON.parse(this.storage.getItem("clipboard")) || this.initialItems;

var $button = $(event.target).closest("button");
var type = $button.data("clipboard-type");
Expand Down Expand Up @@ -375,7 +366,7 @@ import Tooltip from "bootstrap/js/dist/tooltip";
if (type && this.types.includes(type)) {
this.items[type] = [];
} else {
this.items = JSON.parse(this.initialItems);
this.items = this.initialItems;
}

this.storage.setItem("clipboard", JSON.stringify(this.items));
Expand Down

0 comments on commit 412a0eb

Please sign in to comment.