Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

added delete function

Daniele49ade746233
diff --git a/webmarker/src/App.js b/webmarker/src/App.js
index 1625122d..e2a0bd95 100644
--- a/webmarker/src/App.js
+++ b/webmarker/src/App.js
@@ -15,7 +15,7 @@ function App() {
function search(e) {
setSearchQuery(e.target.value);
}
-
+
const filteredData = data.filter((e) => {
return (e.name.toLowerCase().includes(searchQuery.toLowerCase()) || e.title.toLowerCase().includes(searchQuery.toLowerCase()) || e.tag.toLowerCase().includes(searchQuery.toLowerCase()))
});
@@ -29,12 +29,12 @@ function App() {
}
fetchData();
- }, []);
+ }, [data]);
return (
<div className="App">
<div className="head">
- <input className="search" type="search" placeholder="Search for name/title/tag" onChange={search}/>
+ <input className="search" type="search" placeholder="Search for Name/Title/Tag" onChange={search}/>
<button className="add-btn"><span className="material-icons-outlined md-36" onClick={() => setIsAdding(true)}>add</span></button>
<button className="settings-btn"><span className="material-icons-outlined md-36">settings</span></button>
</div>
diff --git a/webmarker/src/componets/EditModal.js b/webmarker/src/componets/EditModal.js
new file mode 100644
index 00000000..63971f03
--- /dev/null
+++ b/webmarker/src/componets/EditModal.js
@@ -0,0 +1,9 @@
+import React from 'react';
+
+const EditModal = ({id}) => {
+ return (
+ <div>{id}</div>
+ )
+}
+
+export default EditModal
\ No newline at end of file
diff --git a/webmarker/src/componets/List.js b/webmarker/src/componets/List.js
index fc39d5a3..60d84f0c 100644
--- a/webmarker/src/componets/List.js
+++ b/webmarker/src/componets/List.js
@@ -1,6 +1,27 @@
import '../styles/List.css';
+import { useState } from 'react';
const List = ({data}) => {
+ const [reload, setReload] = useState(0);
+
+ async function deleteEntity(id) {
+ fetch("/delete", {
+
+ // Adding method type
+ method: "DELETE",
+
+ // Adding body or contents to send
+ body: JSON.stringify({id}),
+
+ // Adding headers to the request
+ headers: {
+ "Content-type": "application/json; charset=UTF-8"
+ }
+ })
+ .then(res => res.text())
+ .then(message => {console.log(message)})
+ }
+
return (
<table className="table">
<thead>
@@ -22,6 +43,7 @@ const List = ({data}) => {
<td>{e.title}</td>
<td><a href={e.link}>{url.hostname}</a></td>
<td>{e.tag}</td>
+ <td className="delete" onClick={() => deleteEntity(e._id)}><div>X</div></td>
</tr>
} catch (e) {
console.log(e)
diff --git a/webmarker/src/styles/List.css b/webmarker/src/styles/List.css
index d10fef1f..3c654025 100644
--- a/webmarker/src/styles/List.css
+++ b/webmarker/src/styles/List.css
@@ -1,29 +1,40 @@
.table {
- width: 100%;
- text-align: left;
- padding-top: 20px;
- }
-
- .table td {
- font-size: 1.3rem;
- padding: 5px;
- }
-
- .table th {
- font-size: 1.6rem;
- padding: 5px;
- }
-
- .table tbody tr:nth-of-type(2n-1) {
- background-color:#273949;
- }
-
- .table a {
- text-decoration: none;
- color: rgb(194, 193, 193);
- font-size: 1rem;
- }
-
- .table a:hover {
- text-decoration: underline;
- }
\ No newline at end of file
+ width: 100%;
+ text-align: left;
+ padding-top: 20px;
+}
+
+.table td {
+ font-size: 1.3rem;
+ padding: 5px;
+}
+
+.table th {
+ font-size: 1.6rem;
+ padding: 5px;
+}
+
+.table tbody tr:nth-of-type(2n-1) {
+ background-color:#273949;
+}
+
+.table tbody td {
+ border-radius: 10px;
+}
+
+
+.table a {
+ text-decoration: none;
+ color: rgb(194, 193, 193);
+ font-size: 1rem;
+}
+
+.table a:hover {
+ text-decoration: underline;
+}
+
+.delete {
+ background-color: red;
+ color: white;
+ cursor: pointer;
+}
\ No newline at end of file
diff --git a/webmarker/src/styles/Modal.css b/webmarker/src/styles/Modal.css
index 22fe70d9..3db1fbc1 100644
--- a/webmarker/src/styles/Modal.css
+++ b/webmarker/src/styles/Modal.css
@@ -1,5 +1,5 @@
.overlay {
- position: absolute;
+ position: fixed;
top: 0;
left: 0;
background-color: rgba(49, 64, 73, 0.781);
diff --git a/webmarker_backend/server.js b/webmarker_backend/server.js
index f03b0337..54b012b6 100644
--- a/webmarker_backend/server.js
+++ b/webmarker_backend/server.js
@@ -1,6 +1,6 @@
const express = require('express');
const app = express();
-const { MongoClient } = require('mongodb');
+const { MongoClient, ObjectId } = require('mongodb');
const phantom = require('phantom');
const port = process.env.PORT || 3001;
@@ -23,6 +23,14 @@ app.post('/post', async (req, res) => {
insertDoc(req.body);
});
+app.delete('/delete', async (req, res) => {
+ const id = req.body.id.toString();
+
+ await deleteDoc(id);
+
+ res.send(`Bookmark with ObjectId "${id}" deleted.`);
+});
+
async function insertDoc(doc) {
try {
await client.connect();
@@ -61,6 +69,24 @@ async function getDoc() {
}
}
+async function deleteDoc(doc) {
+ try {
+ await client.connect();
+
+ const database = client.db("sample_db");
+ const list = database.collection("list");
+ const result = await list.deleteOne({"_id": ObjectId(doc)});
+ }
+
+ catch(err) {
+ console.log(err);
+ }
+
+ finally {
+ await client.close();
+ }
+}
+
async function getTitle(url) {
const instance = await phantom.create();
const page = await instance.createPage();