Added comments to news items

This commit is contained in:
mrfry 2021-03-04 21:31:32 +01:00
parent 64697efc96
commit 71911063b0
9 changed files with 357 additions and 22 deletions

View file

@ -57,9 +57,50 @@ export default function Index({ globalData }) {
let newsEntryData = news[key]
return (
<NewsEntry
onReact={(reaction, isDelete) => {
console.log(reaction, isDelete)
fetch(constants.apiUrl + 'infos', {
onReact={({ type, path, reaction, isDelete }) => {
if (type === 'news') {
fetch(constants.apiUrl + 'infos', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
react: reaction,
newsKey: key,
isDelete: isDelete,
}),
}).then((res) => {
// TODO: dont refetch news
fetchNews().then((res) => {
setNews(res)
})
})
} else if (type === 'comment') {
fetch(constants.apiUrl + 'comment', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'reaction',
newsKey: key,
path: path,
reaction: reaction,
isDelete: isDelete,
}),
}).then((res) => {
fetchNews().then((res) => {
setNews(res)
})
})
}
}}
onDelete={(path) => {
fetch(constants.apiUrl + 'comment', {
method: 'POST',
credentials: 'include',
headers: {
@ -67,11 +108,31 @@ export default function Index({ globalData }) {
'Content-Type': 'application/json',
},
body: JSON.stringify({
react: reaction,
type: 'delete',
path: path,
newsKey: key,
isDelete: isDelete,
}),
}).then((res) => {
}).then(() => {
fetchNews().then((res) => {
setNews(res)
})
})
}}
onComment={(path, text) => {
fetch(constants.apiUrl + 'comment', {
method: 'POST',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'add',
path: path,
text: text,
newsKey: key,
}),
}).then(() => {
fetchNews().then((res) => {
setNews(res)
})