This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
/
index.js
107 lines (97 loc) · 2.88 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Imports */
// React
import React from "react";
// Utilities
import searchAccordingToQueryData from "../lib/worker/searchAccordingToQueryData.js";
import { displayForecastsWrapperForSearch } from "../lib/display/displayForecastsWrappers.js";
import CommonDisplay from "../lib/display/commonDisplay.js";
import Layout from "./layout.js";
// Data
import { platformsWithLabels } from "../lib/platforms.js";
import { getFrontpage } from "../lib/worker/getFrontpage.js";
/* get Props */
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,
numDisplay: 21, // 20
forecastsThreshold: 0,
forecastingPlatforms: platformsWithLabels, // weird key value format,
...urlQuery,
};
let frontPageForecasts = await getFrontpage();
let initialResults;
let props;
switch (
!!initialQueryParameters &&
initialQueryParameters.query != "" &&
initialQueryParameters.query != undefined
) {
case true:
initialResults = await searchAccordingToQueryData(initialQueryParameters);
props = {
initialQueryParameters: initialQueryParameters,
initialResults: initialResults,
defaultResults: frontPageForecasts, // different from initialResults!
urlQuery: urlQuery,
};
break;
default:
initialResults = frontPageForecasts;
props = {
initialQueryParameters: initialQueryParameters,
initialResults: initialResults,
defaultResults: frontPageForecasts, // different from initialResults!
urlQuery: urlQuery,
};
break;
}
return {
props: props,
};
}
/* 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,
defaultResults,
initialQueryParameters,
}) {
return (
<Layout key="index" page={"search"}>
<CommonDisplay
initialResults={initialResults}
defaultResults={defaultResults}
initialQueryParameters={initialQueryParameters}
pageName={"search"}
hasSearchbar={true}
hasCapture={false}
hasAdvancedOptions={true}
placeholder={"Find forecasts about..."}
setHasDisplayBeenCapturedOnChangeSearchInputs={() => null}
displaySeeMoreHint={true}
displayForecastsWrapper={displayForecastsWrapperForSearch}
/>
</Layout>
);
}