diff --git a/src/pages/index.js b/src/pages/index.js
index 2a99960..ddcf724 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -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