feat: always search on client side
This commit is contained in:
parent
c92d131ae3
commit
98c7c31a0f
|
@ -1,16 +1,22 @@
|
||||||
import { GetServerSideProps } from 'next';
|
import { GetServerSideProps, NextPage } from 'next';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { getFrontpage } from '../backend/frontpage';
|
import { getFrontpage } from '../backend/frontpage';
|
||||||
import CommonDisplay, { QueryParameters } from '../web/display/commonDisplay';
|
import CommonDisplay, { QueryParameters } from '../web/display/commonDisplay';
|
||||||
import { displayForecastsWrapperForCapture } from '../web/display/displayForecastsWrappers';
|
import { displayForecastsWrapperForCapture } from '../web/display/displayForecastsWrappers';
|
||||||
import { platformsWithLabels } from '../web/platforms';
|
import { platformsWithLabels } from '../web/platforms';
|
||||||
import searchAccordingToQueryData from '../web/worker/searchAccordingToQueryData';
|
|
||||||
import Layout from './layout';
|
import Layout from './layout';
|
||||||
|
|
||||||
/* get Props */
|
/* get Props */
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
interface Props {
|
||||||
|
initialQueryParameters: QueryParameters;
|
||||||
|
defaultResults: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getServerSideProps: GetServerSideProps<Props> = async (
|
||||||
|
context
|
||||||
|
) => {
|
||||||
let urlQuery = context.query;
|
let urlQuery = context.query;
|
||||||
|
|
||||||
let initialQueryParameters: QueryParameters = {
|
let initialQueryParameters: QueryParameters = {
|
||||||
|
@ -31,33 +37,19 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let initialResults =
|
|
||||||
initialQueryParameters.query != ""
|
|
||||||
? await searchAccordingToQueryData(initialQueryParameters)
|
|
||||||
: frontPageForecasts;
|
|
||||||
|
|
||||||
let props = {
|
|
||||||
initialQueryParameters: initialQueryParameters,
|
|
||||||
initialResults: initialResults,
|
|
||||||
defaultResults: frontPageForecasts,
|
|
||||||
urlQuery: urlQuery,
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: props,
|
props: {
|
||||||
|
initialQueryParameters: initialQueryParameters,
|
||||||
|
defaultResults: frontPageForecasts,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Body */
|
/* Body */
|
||||||
export default function Home({
|
const Home: NextPage<Props> = ({ defaultResults, initialQueryParameters }) => {
|
||||||
initialResults,
|
|
||||||
defaultResults,
|
|
||||||
initialQueryParameters,
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<Layout page={"capture"}>
|
<Layout page={"capture"}>
|
||||||
<CommonDisplay
|
<CommonDisplay
|
||||||
initialResults={initialResults}
|
|
||||||
defaultResults={defaultResults}
|
defaultResults={defaultResults}
|
||||||
initialQueryParameters={initialQueryParameters}
|
initialQueryParameters={initialQueryParameters}
|
||||||
hasSearchbar={true}
|
hasSearchbar={true}
|
||||||
|
@ -69,4 +61,6 @@ export default function Home({
|
||||||
/>
|
/>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Home;
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
import { GetServerSideProps } from 'next';
|
import { GetServerSideProps, NextPage } from 'next';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { getFrontpage } from '../backend/frontpage';
|
import { getFrontpage } from '../backend/frontpage';
|
||||||
import CommonDisplay from '../web/display/commonDisplay';
|
import CommonDisplay, { QueryParameters } from '../web/display/commonDisplay';
|
||||||
import { displayForecastsWrapperForSearch } from '../web/display/displayForecastsWrappers';
|
import { displayForecastsWrapperForSearch } from '../web/display/displayForecastsWrappers';
|
||||||
import { platformsWithLabels } from '../web/platforms';
|
import { platformsWithLabels } from '../web/platforms';
|
||||||
import searchAccordingToQueryData from '../web/worker/searchAccordingToQueryData';
|
|
||||||
import Layout from './layout';
|
import Layout from './layout';
|
||||||
|
|
||||||
/* get Props */
|
/* get Props */
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
interface Props {
|
||||||
|
initialQueryParameters: QueryParameters;
|
||||||
|
defaultResults: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getServerSideProps: GetServerSideProps<Props> = async (
|
||||||
|
context
|
||||||
|
) => {
|
||||||
let urlQuery = context.query;
|
let urlQuery = context.query;
|
||||||
|
|
||||||
let initialQueryParameters = {
|
let initialQueryParameters: QueryParameters = {
|
||||||
query: "",
|
query: "",
|
||||||
numDisplay: 21,
|
numDisplay: 21,
|
||||||
starsThreshold: 2,
|
starsThreshold: 2,
|
||||||
|
@ -31,33 +37,19 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let initialResults =
|
|
||||||
!!initialQueryParameters &&
|
|
||||||
initialQueryParameters.query != "" &&
|
|
||||||
initialQueryParameters.query != undefined
|
|
||||||
? await searchAccordingToQueryData(initialQueryParameters)
|
|
||||||
: frontPageForecasts;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
initialQueryParameters: initialQueryParameters,
|
initialQueryParameters: initialQueryParameters,
|
||||||
initialResults: initialResults,
|
defaultResults: frontPageForecasts,
|
||||||
defaultResults: frontPageForecasts, // different from initialResults!
|
|
||||||
urlQuery: urlQuery,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Body */
|
/* Body */
|
||||||
export default function Home({
|
const Home: NextPage<Props> = ({ defaultResults, initialQueryParameters }) => {
|
||||||
initialResults,
|
|
||||||
defaultResults,
|
|
||||||
initialQueryParameters,
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<Layout page={"search"}>
|
<Layout page={"search"}>
|
||||||
<CommonDisplay
|
<CommonDisplay
|
||||||
initialResults={initialResults}
|
|
||||||
defaultResults={defaultResults}
|
defaultResults={defaultResults}
|
||||||
initialQueryParameters={initialQueryParameters}
|
initialQueryParameters={initialQueryParameters}
|
||||||
hasSearchbar={true}
|
hasSearchbar={true}
|
||||||
|
@ -69,4 +61,6 @@ export default function Home({
|
||||||
/>
|
/>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Home;
|
||||||
|
|
|
@ -19,7 +19,6 @@ export interface QueryParameters extends QueryParametersWithoutNum {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
initialResults: any;
|
|
||||||
defaultResults: any;
|
defaultResults: any;
|
||||||
initialQueryParameters: QueryParameters;
|
initialQueryParameters: QueryParameters;
|
||||||
hasSearchbar: boolean;
|
hasSearchbar: boolean;
|
||||||
|
@ -55,7 +54,6 @@ let transformObjectIntoUrlSlug = (obj: QueryParameters) => {
|
||||||
|
|
||||||
/* Body */
|
/* Body */
|
||||||
const CommonDisplay: React.FC<Props> = ({
|
const CommonDisplay: React.FC<Props> = ({
|
||||||
initialResults,
|
|
||||||
defaultResults,
|
defaultResults,
|
||||||
initialQueryParameters,
|
initialQueryParameters,
|
||||||
hasSearchbar,
|
hasSearchbar,
|
||||||
|
@ -74,7 +72,7 @@ const CommonDisplay: React.FC<Props> = ({
|
||||||
initialQueryParameters.numDisplay || 21
|
initialQueryParameters.numDisplay || 21
|
||||||
);
|
);
|
||||||
|
|
||||||
const [results, setResults] = useState(initialResults);
|
const [results, setResults] = useState([]);
|
||||||
const [advancedOptions, showAdvancedOptions] = useState(false);
|
const [advancedOptions, showAdvancedOptions] = useState(false);
|
||||||
const [whichResultToDisplayAndCapture, setWhichResultToDisplayAndCapture] =
|
const [whichResultToDisplayAndCapture, setWhichResultToDisplayAndCapture] =
|
||||||
useState(0);
|
useState(0);
|
||||||
|
@ -114,7 +112,7 @@ const CommonDisplay: React.FC<Props> = ({
|
||||||
!queryData || queryData.query == "" || queryData.query == undefined;
|
!queryData || queryData.query == "" || queryData.query == undefined;
|
||||||
|
|
||||||
let results = queryIsEmpty
|
let results = queryIsEmpty
|
||||||
? filterManually(queryData, defaultResults || initialResults)
|
? filterManually(queryData, defaultResults)
|
||||||
: await searchAccordingToQueryData(queryData);
|
: await searchAccordingToQueryData(queryData);
|
||||||
|
|
||||||
setResults(results);
|
setResults(results);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user