fix: secretEmbed

This commit is contained in:
Vyacheslav Matyukhin 2022-04-02 01:38:39 +03:00
parent 72db637972
commit 1461002070
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
3 changed files with 49 additions and 45 deletions

View File

@ -1,20 +1,27 @@
/* Imports */ /* Imports */
import { GetServerSideProps, NextPage } from "next";
import React from "react"; import React from "react";
import { displayForecast } from "../web/display/displayForecasts"; import { platforms } from "../backend/platforms";
import { DisplayForecast } from "../web/display/displayForecasts";
import { FrontendForecast } from "../web/platforms"; import { FrontendForecast } from "../web/platforms";
import searchAccordingToQueryData from "../web/worker/searchAccordingToQueryData"; import searchAccordingToQueryData from "../web/worker/searchAccordingToQueryData";
/* Helper functions */ interface Props {
results: FrontendForecast[];
}
export async function getServerSideProps(context) { export const getServerSideProps: GetServerSideProps<Props> = async (
context
) => {
let urlQuery = context.query; // this is an object, not a string which I have to parse!! let urlQuery = context.query; // this is an object, not a string which I have to parse!!
let initialQueryParameters = { let initialQueryParameters = {
query: "", query: "",
starsThreshold: 2, starsThreshold: 2,
forecastsThreshold: 0, forecastsThreshold: 0,
forecastingPlatforms: platforms.map((platform) => platform.name),
...urlQuery, ...urlQuery,
}; };
@ -28,34 +35,32 @@ export async function getServerSideProps(context) {
results: results, results: results,
}, },
}; };
} };
/* Body */ const SecretEmbedPage: NextPage<Props> = ({ results }) => {
export default function Home({ results }) { let result = results.length ? results[0] : null;
/* Final return */
let result = results ? results[0] : null;
return ( return (
<> <div className="mb-4 mt-8 flex flex-row justify-center items-center">
<div className="mb-4 mt-8 flex flex-row justify-center items-center "> <div className="w-6/12 place-self-center">
<div className="w-6/12 place-self-center"> <div>
<div> <div id="secretEmbed">
<div id="secretEmbed"> {result ? (
{result <DisplayForecast
? displayForecast({ forecast={result}
...result, showTimeStamp={true}
showTimeStamp: true, expandFooterToFullWidth={true}
expandFooterToFullWidth: true, />
}) ) : null}
: null} </div>
</div> <br></br>
<br></br> <div id="secretObject">
<div id="secretObject"> {result ? JSON.stringify(result, null, 4) : null}
{result ? JSON.stringify(result.item, null, 4) : null}
</div>
</div> </div>
</div> </div>
</div> </div>
</> </div>
); );
} };
export default SecretEmbedPage;

View File

@ -581,7 +581,7 @@ interface SingleProps {
showIdToggle?: boolean; showIdToggle?: boolean;
} }
export const displayForecast: React.FC<SingleProps> = ({ export const DisplayForecast: React.FC<SingleProps> = ({
forecast: { forecast: {
id, id,
title, title,
@ -760,20 +760,19 @@ const DisplayForecasts: React.FC<Props> = ({
} }
return ( return (
<> <>
{results.slice(0, numDisplay).map((result) => { {results.slice(0, numDisplay).map((result) => (
/*let displayWithMetaculusCapture = /*let displayWithMetaculusCapture =
fuseSearchResult.item.platform == "Metaculus" fuseSearchResult.item.platform == "Metaculus"
? metaculusEmbed(fuseSearchResult.item) ? metaculusEmbed(fuseSearchResult.item)
: displayForecast({ ...fuseSearchResult.item }); : displayForecast({ ...fuseSearchResult.item });
*/ */
const display = displayForecast({ <DisplayForecast
forecast: result, forecast={result}
showTimeStamp: false, showTimeStamp={false}
expandFooterToFullWidth: false, expandFooterToFullWidth={false}
showIdToggle, showIdToggle={showIdToggle}
}); />
return display; ))}
})}
</> </>
); );
}; };

View File

@ -4,18 +4,18 @@ import { CopyToClipboard } from "react-copy-to-clipboard";
import { FrontendForecast } from "../platforms"; import { FrontendForecast } from "../platforms";
import { uploadToImgur } from "../worker/uploadToImgur"; import { uploadToImgur } from "../worker/uploadToImgur";
import { displayForecast } from "./displayForecasts"; import { DisplayForecast } from "./displayForecasts";
function displayOneForecastInner(result: FrontendForecast, containerRef) { function displayOneForecastInner(result: FrontendForecast, containerRef) {
return ( return (
<div ref={containerRef}> <div ref={containerRef}>
{result {result ? (
? displayForecast({ <DisplayForecast
forecast: result, forecast={result}
showTimeStamp: true, showTimeStamp={true}
expandFooterToFullWidth: true, expandFooterToFullWidth={true}
}) />
: null} ) : null}
</div> </div>
); );
} }