Skip to content

Commit

Permalink
Change popup redraw
Browse files Browse the repository at this point in the history
Now, when the last item is removed from the dump, it looks like it was
cleared eventhough an array is still in the storage.
  • Loading branch information
aledeg committed May 26, 2018
1 parent ccf9459 commit 87a8e94
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions popup/load.content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@ function deleteItem(event) {
});
}

browser.storage.local.get('urls').then(obj => {
if (obj.urls) {
obj.urls.forEach((item, index) => {
const listItem = document.createElement('p');
const itemLink = document.createElement('a');
itemLink.href = item.url;
itemLink.innerHTML = item.title;
const itemDelete = document.createElement('button');
itemDelete.dataset.index = index;
itemDelete.onclick = deleteItem;
const deleteImage = document.createElement('img');
deleteImage.src = browser.extension.getURL('icons/trash-48.png');
itemDelete.appendChild(deleteImage);
function loadDump() {
document.querySelector('#popup-content').innerHTML = '';
browser.storage.local.get('urls').then(obj => {
if (obj.urls && obj.urls.length !== 0) {
obj.urls.forEach((item, index) => {
const listItem = document.createElement('p');
const itemLink = document.createElement('a');
itemLink.href = item.url;
itemLink.innerHTML = item.title;
const itemDelete = document.createElement('button');
itemDelete.dataset.index = index;
itemDelete.onclick = deleteItem;
const deleteImage = document.createElement('img');
deleteImage.src = browser.extension.getURL('icons/trash-48.png');
itemDelete.appendChild(deleteImage);

listItem.appendChild(itemDelete);
listItem.appendChild(itemLink);
listItem.appendChild(itemDelete);
listItem.appendChild(itemLink);

document.querySelector('#popup-content').appendChild(listItem);
});
} else {
const emptyItem = document.createElement('p');
emptyItem.innerHTML = 'The dump is empty!';
document.querySelector('#popup-content').appendChild(emptyItem);
}
});
document.querySelector('#popup-content').appendChild(listItem);
});
} else {
const emptyItem = document.createElement('p');
emptyItem.innerHTML = 'The dump is empty!';
document.querySelector('#popup-content').appendChild(emptyItem);
}
});
}

document.querySelectorAll('.download').forEach(item => {
item.addEventListener('click', (event) => {
Expand All @@ -56,11 +59,12 @@ document.querySelector('.dropdown-toggle').addEventListener('click', (event) =>
function handleMessage(message) {
switch (message.action) {
case 'reload':
window.location.reload(true);
loadDump();
break;
default:
// Do nothing on purpose
}
}

browser.runtime.onMessage.addListener(handleMessage);
loadDump();

0 comments on commit 87a8e94

Please sign in to comment.