fix: frontpage json serialization

This commit is contained in:
Vyacheslav Matyukhin 2022-03-24 21:41:23 +03:00
parent 796d227537
commit 9714e4cd0a
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
3 changed files with 18 additions and 23 deletions

View File

@ -10,8 +10,8 @@ export async function getFrontpageRaw() {
AND JSON_ARRAY_LENGTH(options) > 0
ORDER BY RANDOM() LIMIT 50
`);
if (!res.rows.length) return [];
return res.rows[0].frontpage_sliced;
return res.rows;
}
export async function getFrontpageFullRaw() {

View File

@ -23,6 +23,14 @@ export async function getServerSideProps(context) {
};
let frontPageForecasts = await getFrontpage();
frontPageForecasts = frontPageForecasts.map((forecast) => ({
...forecast,
item: {
...forecast.item,
timestamp: forecast.item.timestamp.toJSON(),
},
}));
let initialResults;
switch (initialQueryParameters.query != "") {
case true:

View File

@ -24,6 +24,14 @@ export async function getServerSideProps(context) {
};
let frontPageForecasts = await getFrontpage();
frontPageForecasts = frontPageForecasts.map((forecast) => ({
...forecast,
item: {
...forecast.item,
timestamp: forecast.item.timestamp.toJSON(),
},
}));
let initialResults;
let props;
switch (
@ -56,27 +64,6 @@ export async function getServerSideProps(context) {
};
}
/* Alternative: getStaticProps
export async function getStaticProps() {
// get frontPageForecasts somehow.
let lastUpdated = calculateLastUpdate(); // metaforecasts.find(forecast => forecast.platform == "Good Judgment Open").timestamp
let initialQueryParameters = {
query: "",
processedUrlYet: false,
starsThreshold: 2,
numDisplay: 21, // 20
forecastsThreshold: 0,
forecastingPlatforms: platforms,
};
return {
props: {
frontPageForecasts,
lastUpdated,
},
};
}
*/
/* Body */
export default function Home({
initialResults,