mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Front page forum
This commit is contained in:
parent
a09e9734da
commit
561aa21d93
15 changed files with 484 additions and 136 deletions
|
@ -6,6 +6,7 @@ import Link from 'next/link'
|
|||
import LoadingIndicator from '../components/LoadingIndicator'
|
||||
import Sleep from '../components/sleep'
|
||||
import NewsEntry from '../components/newsEntry'
|
||||
import Composer from '../components/composer'
|
||||
import DbSelector from '../components/dbSelector.js'
|
||||
|
||||
import styles from './index.module.css'
|
||||
|
@ -36,6 +37,72 @@ function fetchNews() {
|
|||
})
|
||||
}
|
||||
|
||||
function addPost(title, content) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(constants.apiUrl + 'addPost', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: title,
|
||||
content: content,
|
||||
}),
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function postFeedback(content, file) {
|
||||
return new Promise((resolve) => {
|
||||
const promises = [
|
||||
fetch(constants.apiUrl + 'postfeedback', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: content,
|
||||
}),
|
||||
}).then((res) => {
|
||||
return res.json()
|
||||
}),
|
||||
]
|
||||
|
||||
if (file) {
|
||||
console.log('FIEEEEEEEEEELE')
|
||||
const formData = new FormData() // eslint-disable-line
|
||||
formData.append('file', file)
|
||||
|
||||
promises.push(
|
||||
fetch(constants.apiUrl + 'postfeedbackfile', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: formData,
|
||||
}).then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
Promise.all(promises).then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default function Index({ globalData }) {
|
||||
const userId = globalData.userId
|
||||
const motd = globalData.motd
|
||||
|
@ -57,6 +124,25 @@ export default function Index({ globalData }) {
|
|||
let newsEntryData = news[key]
|
||||
return (
|
||||
<NewsEntry
|
||||
onPostDelete={() => {
|
||||
fetch(constants.apiUrl + 'rmPost', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
newsKey: key,
|
||||
}),
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
}}
|
||||
onReact={({ type, path, reaction, isDelete }) => {
|
||||
if (type === 'news') {
|
||||
fetch(constants.apiUrl + 'infos', {
|
||||
|
@ -71,12 +157,13 @@ export default function Index({ globalData }) {
|
|||
newsKey: key,
|
||||
isDelete: isDelete,
|
||||
}),
|
||||
}).then((res) => {
|
||||
// TODO: dont refetch news
|
||||
fetchNews().then((res) => {
|
||||
setNews(res)
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
} else if (type === 'comment') {
|
||||
fetch(constants.apiUrl + 'comment', {
|
||||
method: 'POST',
|
||||
|
@ -92,11 +179,13 @@ export default function Index({ globalData }) {
|
|||
reaction: reaction,
|
||||
isDelete: isDelete,
|
||||
}),
|
||||
}).then((res) => {
|
||||
fetchNews().then((res) => {
|
||||
setNews(res)
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
}
|
||||
}}
|
||||
onDelete={(path) => {
|
||||
|
@ -112,13 +201,15 @@ export default function Index({ globalData }) {
|
|||
path: path,
|
||||
newsKey: key,
|
||||
}),
|
||||
}).then(() => {
|
||||
fetchNews().then((res) => {
|
||||
setNews(res)
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
}}
|
||||
onComment={(path, text) => {
|
||||
onComment={(path, content) => {
|
||||
fetch(constants.apiUrl + 'comment', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
|
@ -129,14 +220,16 @@ export default function Index({ globalData }) {
|
|||
body: JSON.stringify({
|
||||
type: 'add',
|
||||
path: path,
|
||||
text: text,
|
||||
content: content,
|
||||
newsKey: key,
|
||||
}),
|
||||
}).then(() => {
|
||||
fetchNews().then((res) => {
|
||||
setNews(res)
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
return res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
}}
|
||||
uid={userId}
|
||||
key={key}
|
||||
|
@ -149,8 +242,31 @@ export default function Index({ globalData }) {
|
|||
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.title}>News</div>
|
||||
<div className={styles.title}>Forum</div>
|
||||
<hr />
|
||||
<Composer
|
||||
onSubmit={(type, title, content, file) => {
|
||||
if (!content) {
|
||||
alert('Üres a tartalom!')
|
||||
return
|
||||
}
|
||||
console.log(type, title, content, file)
|
||||
if (type === 'private') {
|
||||
postFeedback(content, file).then((res) => {
|
||||
console.log(res)
|
||||
alert('Privát visszajelzés elküldve!')
|
||||
})
|
||||
} else {
|
||||
if (!title) {
|
||||
alert('Üres a téma!')
|
||||
return
|
||||
}
|
||||
addPost(title, content).then((res) => {
|
||||
setNews(res.news)
|
||||
})
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<hr />
|
||||
<div>{newsItems}</div>
|
||||
</div>
|
||||
|
@ -165,7 +281,6 @@ export default function Index({ globalData }) {
|
|||
<div>
|
||||
<div className={styles.title}>MOTD</div>
|
||||
<hr />
|
||||
<hr />
|
||||
{motd ? (
|
||||
<div
|
||||
className={styles.motd}
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
}
|
||||
|
||||
.clickable:hover {
|
||||
background-color: #666666;
|
||||
background-color: var(--hoover-color);
|
||||
}
|
||||
|
||||
.clickable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue