el.xwx.moe/src/componets/List.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

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
const List = ({data, reFetch}) => {
2022-04-27 07:19:47 -05:00
function deleteEntity(id) {
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)})
.then(() => reFetch())
2022-04-26 01:20:42 -05:00
}
2022-04-16 12:50:42 -05:00
return (
<div className="list">
2022-04-16 12:50:42 -05:00
{data.map((e, i) => {
2022-04-22 07:13:22 -05:00
try {
const url = new URL(e.link);
const favicon = 'http://www.google.com/s2/favicons?domain=' + url.hostname;
return <div key={i} className="list-row">
<div className="img-content-grp">
<img src={favicon} />
<div className="list-entity-content">
<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)}>&#xf2ed;</div>
</div>
2022-04-22 07:13:22 -05:00
} catch (e) {
console.log(e);
2022-04-22 07:13:22 -05:00
}
2022-04-16 12:50:42 -05:00
})}
</div>
2022-04-16 12:50:42 -05:00
)
}
export default List