mirror of
https://gitlab.com/MrFry/qmining-page
synced 2025-04-01 20:23:44 +02:00
Fixed opening not loaded posts
This commit is contained in:
parent
ce63911b68
commit
f0d6daf753
1 changed files with 48 additions and 8 deletions
|
@ -87,6 +87,23 @@ function fetchLeaderboard() {
|
|||
return data || []
|
||||
}
|
||||
|
||||
function fetchEntry(postKey) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(
|
||||
`${constants.apiUrl}forumEntry?forumName=${frontpageForumName}&postKey=${postKey}`,
|
||||
{
|
||||
credentials: 'include',
|
||||
}
|
||||
)
|
||||
.then((resp) => {
|
||||
return resp.json()
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fetchForum(from) {
|
||||
return new Promise((resolve) => {
|
||||
fetch(
|
||||
|
@ -172,10 +189,37 @@ const NewsEntryContainer = ({
|
|||
newsEntryData,
|
||||
onTitleClick,
|
||||
}) => {
|
||||
const [error, setError] = useState(false)
|
||||
if (!newsEntryData && !error) {
|
||||
fetchEntry(postKey)
|
||||
.then((res) => {
|
||||
const { success, entry, msg } = res
|
||||
if (success) {
|
||||
setNews({ [postKey]: entry, ...news })
|
||||
} else {
|
||||
alert(msg)
|
||||
setError(true)
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
setError(true)
|
||||
})
|
||||
return <LoadingIndicator />
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div>Lil fuckup</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<NewsEntry
|
||||
showUpDownVote
|
||||
onTitleClick={onTitleClick}
|
||||
uid={userId}
|
||||
key={postKey}
|
||||
newsKey={postKey}
|
||||
newsItem={newsEntryData}
|
||||
onPostDelete={() => {
|
||||
fetch(constants.apiUrl + 'rmPost', {
|
||||
method: 'POST',
|
||||
|
@ -318,10 +362,6 @@ const NewsEntryContainer = ({
|
|||
}
|
||||
})
|
||||
}}
|
||||
uid={userId}
|
||||
key={postKey}
|
||||
newsKey={postKey}
|
||||
newsItem={newsEntryData}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
@ -369,13 +409,13 @@ export default function Memes({
|
|||
|
||||
const renderNews = () => {
|
||||
if (news) {
|
||||
let newsItems = Object.keys(news).map((postKey) => {
|
||||
let newsEntryData = news[postKey]
|
||||
const newsItems = Object.keys(news).map((postKey) => {
|
||||
const newsEntryData = news[postKey]
|
||||
return (
|
||||
<NewsEntryContainer
|
||||
onTitleClick={() => {
|
||||
setPostInModalKey(postKey)
|
||||
router.push(
|
||||
router.replace(
|
||||
`${router.pathname}?postKey=${encodeURIComponent(postKey)}`,
|
||||
undefined,
|
||||
{ shallow: true }
|
||||
|
@ -489,7 +529,7 @@ export default function Memes({
|
|||
<Modal
|
||||
closeClick={() => {
|
||||
setPostInModalKey(undefined)
|
||||
router.back({ shallow: true })
|
||||
router.replace(router.pathname, undefined, { shallow: true })
|
||||
}}
|
||||
>
|
||||
{news ? (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue