2022-04-22 07:13:22 -05:00
|
|
|
import '../styles/List.css';
|
2022-04-26 01:20:42 -05:00
|
|
|
import { useState } from 'react';
|
2022-04-16 12:50:42 -05:00
|
|
|
|
2022-04-22 07:13:22 -05:00
|
|
|
const List = ({data}) => {
|
2022-04-26 01:20:42 -05:00
|
|
|
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)})
|
|
|
|
}
|
|
|
|
|
2022-04-16 12:50:42 -05:00
|
|
|
return (
|
|
|
|
<table className="table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2022-04-26 05:50:07 -05:00
|
|
|
<th className='number'>#</th>
|
2022-04-16 12:50:42 -05:00
|
|
|
<th>Name</th>
|
|
|
|
<th>Title</th>
|
|
|
|
<th>Link</th>
|
2022-04-19 07:22:53 -05:00
|
|
|
<th>Tag</th>
|
2022-04-16 12:50:42 -05:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{data.map((e, i) => {
|
2022-04-22 07:13:22 -05:00
|
|
|
try {
|
|
|
|
const url = new URL(e.link)
|
|
|
|
return <tr key={i}>
|
2022-04-26 05:50:07 -05:00
|
|
|
<td className='number'>{i + 1}</td>
|
2022-04-22 07:13:22 -05:00
|
|
|
<td>{e.name}</td>
|
|
|
|
<td>{e.title}</td>
|
|
|
|
<td><a href={e.link}>{url.hostname}</a></td>
|
|
|
|
<td>{e.tag}</td>
|
2022-04-26 05:50:07 -05:00
|
|
|
<td className="delete" onClick={() => deleteEntity(e._id)}><div>x</div></td>
|
2022-04-22 07:13:22 -05:00
|
|
|
</tr>
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
2022-04-16 12:50:42 -05:00
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default List
|