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

57 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-04-22 07:13:22 -05:00
import '../styles/List.css';
2022-06-01 16:18:21 -05:00
import config from '../config';
2022-05-27 08:03:01 -05:00
import LazyLoad from 'react-lazyload';
2022-04-16 12:50:42 -05:00
const List = ({data, reFetch}) => {
2022-04-27 07:19:47 -05:00
function deleteEntity(id) {
2022-06-01 16:18:21 -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)})
.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;
2022-05-27 08:03:01 -05:00
return <LazyLoad key={i} height={200} offset={200}>
<div className="list-row">
<div className="img-content-grp">
<img src={favicon} />
<div className="list-entity-content">
2022-05-27 11:41:51 -05:00
<div className='row-name'><span className="num">{i + 1}.</span> {e.name} <a target="_blank" href={e.link}>({url.hostname})</a></div>
2022-05-27 08:03:01 -05:00
<div>{e.title}</div>
2022-05-27 11:41:51 -05:00
<div className="tags">
{e.tag.map((e, i) => {
return <div key={i}>{e}</div>
})}
</div>
2022-05-27 08:03:01 -05:00
</div>
</div>
2022-05-27 08:03:01 -05:00
<div className="delete" onClick={() => deleteEntity(e._id)}>&#xf2ed;</div>
</div>
2022-05-27 08:03:01 -05:00
</LazyLoad>
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