From 9714e4cd0a7c98bb0c837e715855cc54f9570a43 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Thu, 24 Mar 2022 21:41:23 +0300 Subject: [PATCH] fix: frontpage json serialization --- src/backend/frontpage.ts | 4 ++-- src/pages/capture.js | 8 ++++++++ src/pages/index.tsx | 29 ++++++++--------------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/backend/frontpage.ts b/src/backend/frontpage.ts index 54c6b3d..c85f373 100644 --- a/src/backend/frontpage.ts +++ b/src/backend/frontpage.ts @@ -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() { diff --git a/src/pages/capture.js b/src/pages/capture.js index 6095d11..371ddb9 100644 --- a/src/pages/capture.js +++ b/src/pages/capture.js @@ -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: diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 20bd294..07af4d7 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -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,