metaforecast/src/pages/secretEmbed.tsx
Vyacheslav Matyukhin b481212721
feat: more ts, fix tailwind
- rename more files to .ts/.tsx
- update tailwind config to use .tsx files from all dirs
- merge css files into a single main.css to avoid import order
  dependencies
- minor cleanups due to ts complaints
2022-03-26 03:36:50 +03:00

69 lines
1.7 KiB
TypeScript

/* Imports */
import React from 'react';
import { displayForecast } from '../web/display/displayForecasts';
import { platformsWithLabels } from '../web/platforms';
import searchAccordingToQueryData from '../web/worker/searchAccordingToQueryData';
/* Helper functions */
export async function getServerSideProps(context) {
let urlQuery = context.query; // this is an object, not a string which I have to parse!!
let initialQueryParameters = {
query: "",
starsThreshold: 2,
forecastsThreshold: 0,
forecastingPlatforms: platformsWithLabels, // weird key value format,
...urlQuery,
};
let results;
switch (initialQueryParameters.query != "") {
case true:
results = await searchAccordingToQueryData(initialQueryParameters);
break;
default:
results = [];
break;
}
return {
props: {
results: results,
},
};
}
/* Body */
export default function Home({ results }) {
/* Final return */
let result = results ? results[0] : null;
return (
<>
<div className="mb-4 mt-8 flex flex-row justify-center items-center ">
<div className="w-6/12 place-self-center">
<div>
<div id="secretEmbed">
{result
? displayForecast({
...result.item,
score: result.score,
showTimeStamp: true,
expandFooterToFullWidth: true,
})
: null}
</div>
<br></br>
<div id="secretObject">
{result ? JSON.stringify(result.item, null, 4) : null}
</div>
</div>
</div>
</div>
</>
);
}