Skip to content

Commit

Permalink
Fix link deletion
Browse files Browse the repository at this point in the history
Before, the link deletion action was broken. It didn't remove the
selected link and the refresh was not working properly.
Now, deleting a link is working as expected. In the process, I have
simplified the code by removing DOM element.

See #24
  • Loading branch information
aledeg committed Apr 20, 2019
1 parent 608a470 commit 42a8ae6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
14 changes: 7 additions & 7 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ function download(downloadOptions) {
});
}

function deleteLink(index) {
function deleteLink(link) {
browser.storage.local.get('urls').then(obj => {
if (!obj.urls) return;
const { urls } = obj;
let { urls } = obj;

urls.splice(index, 1);
urls = urls.filter((item) => item.url != link.url && item.title != link.title);

browser.storage.local.set({ urls });
}).then(browser.runtime.sendMessage({
action: 'reload'
}));
browser.storage.local.set({ urls }).then(browser.runtime.sendMessage({
action: 'reload'
}));
});
}

function clear() {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"manifest_version": 2,
"name": "LinkDump",
"version": "1.9",
"version": "1.10",
"description": "__MSG_extensionDescription__",
"icons": {
"48": "icons/linkdump-48.png"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkdump",
"version": "1.9.0",
"version": "1.10.0",
"description": "Store links and dump them",
"main": "background.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions popup/load.content.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ div.btn-group {
background-color: transparent;
border: none;
cursor: pointer;
}
.delete img {
height: 16px;
padding-right: 4px;
}
.empty {
display: none;
Expand Down
14 changes: 7 additions & 7 deletions popup/load.content.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function deleteItem(event) {
browser.runtime.sendMessage({
action: 'delete',
payload: event.target.dataset.index
payload: {
url: event.target.nextSibling.href,
title: event.target.nextSibling.text
}
});
}

Expand Down Expand Up @@ -43,15 +46,12 @@ function drawContent() {
const itemLink = document.createElement('a');
itemLink.href = item.url;
itemLink.textContent = item.title;
const itemDelete = document.createElement('button');
itemDelete.dataset.index = index;
itemDelete.onclick = deleteItem;
itemDelete.classList = 'delete'
const deleteImage = document.createElement('img');
deleteImage.src = browser.extension.getURL('icons/trash-48.png');
itemDelete.appendChild(deleteImage);
deleteImage.onclick = deleteItem;
deleteImage.classList = 'delete';

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

document.querySelector('#popup-content').appendChild(listItem);
Expand Down

0 comments on commit 42a8ae6

Please sign in to comment.