diff --git a/webmarker/src/App.js b/webmarker/src/App.js index 1625122..e2a0bd9 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 (
- +
diff --git a/webmarker/src/componets/EditModal.js b/webmarker/src/componets/EditModal.js new file mode 100644 index 0000000..63971f0 --- /dev/null +++ b/webmarker/src/componets/EditModal.js @@ -0,0 +1,9 @@ +import React from 'react'; + +const EditModal = ({id}) => { + return ( +
{id}
+ ) +} + +export default EditModal \ No newline at end of file diff --git a/webmarker/src/componets/List.js b/webmarker/src/componets/List.js index fc39d5a..60d84f0 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 ( @@ -22,6 +43,7 @@ const List = ({data}) => { + } catch (e) { console.log(e) diff --git a/webmarker/src/styles/List.css b/webmarker/src/styles/List.css index d10fef1..3c65402 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; - } + width: 100%; + text-align: left; + padding-top: 20px; +} - .table a { - text-decoration: none; - color: rgb(194, 193, 193); - font-size: 1rem; - } +.table td { + font-size: 1.3rem; + padding: 5px; +} - .table a:hover { - text-decoration: underline; - } \ No newline at end of file +.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 22fe70d..3db1fbc 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 f03b033..54b012b 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();
{e.title} {url.hostname} {e.tag} deleteEntity(e._id)}>
X