2022-04-22 07:13:22 -05:00
|
|
|
import '../styles/List.css';
|
2022-05-10 11:40:08 -05:00
|
|
|
import config from '../config.json';
|
2022-04-16 12:50:42 -05:00
|
|
|
|
2022-05-26 11:15:07 -05:00
|
|
|
const List = ({data, reFetch}) => {
|
2022-04-27 07:19:47 -05:00
|
|
|
function deleteEntity(id) {
|
2022-05-26 11:15:07 -05:00
|
|
|
const address = config.api.address + ":" + config.api.port;
|
|
|
|
fetch(address + "/api", {
|
2022-04-26 01:20:42 -05:00
|
|
|
|
|
|
|
// Adding method type
|
|
|
|
method: "DELETE",
|
|
|
|
|
|
|
|
// Adding body or contents to send
|
|
|
|
body: JSON.stringify({id}),
|
|
|
|
|
|
|
|
// Adding headers to the request
|
|
|
|
headers: {
|
2022-05-10 11:40:08 -05:00
|
|
|
"Content-type": "application/json; charset=UTF-8",
|
2022-04-26 01:20:42 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => res.text())
|
|
|
|
.then(message => {console.log(message)})
|
2022-05-26 11:15:07 -05:00
|
|
|
.then(() => reFetch())
|
2022-04-26 01:20:42 -05:00
|
|
|
}
|
|
|
|
|
2022-04-16 12:50:42 -05:00
|
|
|
return (
|
2022-05-26 11:15:07 -05:00
|
|
|
<div className="list">
|
2022-04-16 12:50:42 -05:00
|
|
|
{data.map((e, i) => {
|
2022-04-22 07:13:22 -05:00
|
|
|
try {
|
2022-05-26 11:15:07 -05:00
|
|
|
const url = new URL(e.link);
|
|
|
|
const favicon = 'http://www.google.com/s2/favicons?domain=' + url.hostname;
|
2022-05-27 02:26:21 -05:00
|
|
|
return <div key={i} className="list-row">
|
2022-05-26 11:15:07 -05:00
|
|
|
<div className="img-content-grp">
|
|
|
|
<img src={favicon} />
|
2022-05-27 02:26:21 -05:00
|
|
|
<div className="list-entity-content">
|
2022-05-26 11:15:07 -05:00
|
|
|
<div className='row-name'><span className="num">{i + 1}.</span> {e.name}</div>
|
|
|
|
<div>{e.title}</div>
|
|
|
|
<div><a href={e.link}>{url.hostname}</a></div>
|
|
|
|
<div className="tag">{e.tag}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="delete" onClick={() => deleteEntity(e._id)}></div>
|
|
|
|
</div>
|
2022-04-22 07:13:22 -05:00
|
|
|
} catch (e) {
|
2022-05-26 11:15:07 -05:00
|
|
|
console.log(e);
|
2022-04-22 07:13:22 -05:00
|
|
|
}
|
2022-04-16 12:50:42 -05:00
|
|
|
})}
|
2022-05-26 11:15:07 -05:00
|
|
|
</div>
|
2022-04-16 12:50:42 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default List
|