added delete function
This commit is contained in:
parent
c757b2bfa6
commit
e49ade7462
|
@ -29,12 +29,12 @@ function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, [data]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<div className="head">
|
<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="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>
|
<button className="settings-btn"><span className="material-icons-outlined md-36">settings</span></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const EditModal = ({id}) => {
|
||||||
|
return (
|
||||||
|
<div>{id}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditModal
|
|
@ -1,6 +1,27 @@
|
||||||
import '../styles/List.css';
|
import '../styles/List.css';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
const List = ({data}) => {
|
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 (
|
return (
|
||||||
<table className="table">
|
<table className="table">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -22,6 +43,7 @@ const List = ({data}) => {
|
||||||
<td>{e.title}</td>
|
<td>{e.title}</td>
|
||||||
<td><a href={e.link}>{url.hostname}</a></td>
|
<td><a href={e.link}>{url.hostname}</a></td>
|
||||||
<td>{e.tag}</td>
|
<td>{e.tag}</td>
|
||||||
|
<td className="delete" onClick={() => deleteEntity(e._id)}><div>X</div></td>
|
||||||
</tr>
|
</tr>
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
background-color:#273949;
|
background-color:#273949;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table tbody td {
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.table a {
|
.table a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: rgb(194, 193, 193);
|
color: rgb(194, 193, 193);
|
||||||
|
@ -27,3 +32,9 @@
|
||||||
.table a:hover {
|
.table a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete {
|
||||||
|
background-color: red;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
.overlay {
|
.overlay {
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
background-color: rgba(49, 64, 73, 0.781);
|
background-color: rgba(49, 64, 73, 0.781);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient, ObjectId } = require('mongodb');
|
||||||
const phantom = require('phantom');
|
const phantom = require('phantom');
|
||||||
|
|
||||||
const port = process.env.PORT || 3001;
|
const port = process.env.PORT || 3001;
|
||||||
|
@ -23,6 +23,14 @@ app.post('/post', async (req, res) => {
|
||||||
insertDoc(req.body);
|
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) {
|
async function insertDoc(doc) {
|
||||||
try {
|
try {
|
||||||
await client.connect();
|
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) {
|
async function getTitle(url) {
|
||||||
const instance = await phantom.create();
|
const instance = await phantom.create();
|
||||||
const page = await instance.createPage();
|
const page = await instance.createPage();
|
||||||
|
|
Ŝarĝante…
Reference in New Issue