|
|
@ -15,18 +15,32 @@ import {
|
|
|
|
QUESTION_TYPES,
|
|
|
|
QUESTION_TYPES,
|
|
|
|
SAMPLE_QUESTION,
|
|
|
|
SAMPLE_QUESTION,
|
|
|
|
} from '~/utils/questions/constants';
|
|
|
|
} from '~/utils/questions/constants';
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
|
|
useSearchFilter,
|
|
|
|
|
|
|
|
useSearchFilterSingle,
|
|
|
|
|
|
|
|
} from '~/utils/questions/useSearchFilter';
|
|
|
|
|
|
|
|
|
|
|
|
export default function QuestionsHomePage() {
|
|
|
|
export default function QuestionsHomePage() {
|
|
|
|
const router = useRouter();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedCompanies, setSelectedCompanies] = useState<Array<string>>([]);
|
|
|
|
const [selectedCompanies, setSelectedCompanies, areCompaniesInitialized] =
|
|
|
|
|
|
|
|
useSearchFilter('companies');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [
|
|
|
|
|
|
|
|
selectedQuestionTypes,
|
|
|
|
|
|
|
|
setSelectedQuestionTypes,
|
|
|
|
|
|
|
|
areQuestionTypesInitialized,
|
|
|
|
|
|
|
|
] = useSearchFilter('questionTypes');
|
|
|
|
|
|
|
|
const [
|
|
|
|
|
|
|
|
selectedQuestionAge,
|
|
|
|
|
|
|
|
setSelectedQuestionAge,
|
|
|
|
|
|
|
|
isQuestionAgeInitialized,
|
|
|
|
|
|
|
|
] = useSearchFilterSingle('questionAge', 'all');
|
|
|
|
|
|
|
|
const [selectedLocations, setSelectedLocations, areLocationsInitialized] =
|
|
|
|
|
|
|
|
useSearchFilter('locations');
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedQuestionTypes, setSelectedQuestionTypes] = useState<
|
|
|
|
|
|
|
|
Array<string>
|
|
|
|
|
|
|
|
>([]);
|
|
|
|
|
|
|
|
const [selectedQuestionAge, setSelectedQuestionAge] = useState<string>('all');
|
|
|
|
|
|
|
|
const [selectedLocations, setSelectedLocations] = useState<Array<string>>([]);
|
|
|
|
|
|
|
|
const [hasLanded, setHasLanded] = useState(false);
|
|
|
|
const [hasLanded, setHasLanded] = useState(false);
|
|
|
|
|
|
|
|
// Const [loaded, setLoaded] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
const companyFilterOptions = useMemo(() => {
|
|
|
|
const companyFilterOptions = useMemo(() => {
|
|
|
|
return COMPANIES.map((company) => ({
|
|
|
|
return COMPANIES.map((company) => ({
|
|
|
@ -64,30 +78,22 @@ export default function QuestionsHomePage() {
|
|
|
|
setHasLanded(true);
|
|
|
|
setHasLanded(true);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const paramToArray = (
|
|
|
|
const areFiltersInitialized = useMemo(() => {
|
|
|
|
param: Array<string> | string | undefined,
|
|
|
|
return (
|
|
|
|
): Array<string> => {
|
|
|
|
areCompaniesInitialized &&
|
|
|
|
if (typeof param === 'string') {
|
|
|
|
areQuestionTypesInitialized &&
|
|
|
|
return [param];
|
|
|
|
isQuestionAgeInitialized &&
|
|
|
|
}
|
|
|
|
areLocationsInitialized
|
|
|
|
return param ?? [];
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}, [
|
|
|
|
|
|
|
|
areCompaniesInitialized,
|
|
|
|
const [isSearchInitialized, setIsSearchInitialized] = useState(false);
|
|
|
|
areQuestionTypesInitialized,
|
|
|
|
|
|
|
|
isQuestionAgeInitialized,
|
|
|
|
|
|
|
|
areLocationsInitialized,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
// Set url query params
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (router.isReady && !isSearchInitialized) {
|
|
|
|
if (areFiltersInitialized) {
|
|
|
|
const paramQuestionAge = router.query.questionAge;
|
|
|
|
|
|
|
|
const questionAge = Array.isArray(paramQuestionAge)
|
|
|
|
|
|
|
|
? paramQuestionAge[0]
|
|
|
|
|
|
|
|
: paramQuestionAge ?? 'all';
|
|
|
|
|
|
|
|
setSelectedCompanies(paramToArray(router.query.companies));
|
|
|
|
|
|
|
|
setSelectedQuestionTypes(paramToArray(router.query.questionTypes));
|
|
|
|
|
|
|
|
setSelectedQuestionAge(questionAge);
|
|
|
|
|
|
|
|
setSelectedLocations(paramToArray(router.query.locations));
|
|
|
|
|
|
|
|
setIsSearchInitialized(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hasFilter =
|
|
|
|
const hasFilter =
|
|
|
|
router.query.companies ||
|
|
|
|
router.query.companies ||
|
|
|
|
router.query.questionTypes ||
|
|
|
|
router.query.questionTypes ||
|
|
|
@ -96,21 +102,14 @@ export default function QuestionsHomePage() {
|
|
|
|
if (hasFilter) {
|
|
|
|
if (hasFilter) {
|
|
|
|
setHasLanded(true);
|
|
|
|
setHasLanded(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Console.log('shit');
|
|
|
|
|
|
|
|
// setLoaded(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
}, [areFiltersInitialized, router.query]);
|
|
|
|
router.isReady,
|
|
|
|
|
|
|
|
router.query,
|
|
|
|
|
|
|
|
isSearchInitialized,
|
|
|
|
|
|
|
|
hasLanded,
|
|
|
|
|
|
|
|
selectedCompanies,
|
|
|
|
|
|
|
|
selectedQuestionTypes,
|
|
|
|
|
|
|
|
selectedQuestionAge,
|
|
|
|
|
|
|
|
selectedLocations,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update url query params
|
|
|
|
// Update url query params
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (router.isReady && isSearchInitialized) {
|
|
|
|
if (router.isReady && areFiltersInitialized) {
|
|
|
|
router.replace(
|
|
|
|
router.replace(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
query: {
|
|
|
|
query: {
|
|
|
@ -135,9 +134,13 @@ export default function QuestionsHomePage() {
|
|
|
|
selectedLocations,
|
|
|
|
selectedLocations,
|
|
|
|
router,
|
|
|
|
router,
|
|
|
|
router.isReady,
|
|
|
|
router.isReady,
|
|
|
|
isSearchInitialized,
|
|
|
|
areFiltersInitialized,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If (!loaded) {
|
|
|
|
|
|
|
|
// return <div>hi</div>;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
return !hasLanded ? (
|
|
|
|
return !hasLanded ? (
|
|
|
|
<LandingComponent onLanded={handleLandingQuery}></LandingComponent>
|
|
|
|
<LandingComponent onLanded={handleLandingQuery}></LandingComponent>
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
@ -152,10 +155,12 @@ export default function QuestionsHomePage() {
|
|
|
|
searchPlaceholder="Add company filter"
|
|
|
|
searchPlaceholder="Add company filter"
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
if (checked) {
|
|
|
|
if (checked) {
|
|
|
|
setSelectedCompanies((prev) => [...prev, optionValue]);
|
|
|
|
setSelectedCompanies([...selectedCompanies, optionValue]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setSelectedCompanies((prev) =>
|
|
|
|
setSelectedCompanies(
|
|
|
|
prev.filter((company) => company !== optionValue),
|
|
|
|
selectedCompanies.filter(
|
|
|
|
|
|
|
|
(company) => company !== optionValue,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}}
|
|
|
@ -166,10 +171,15 @@ export default function QuestionsHomePage() {
|
|
|
|
showAll={true}
|
|
|
|
showAll={true}
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
if (checked) {
|
|
|
|
if (checked) {
|
|
|
|
setSelectedQuestionTypes((prev) => [...prev, optionValue]);
|
|
|
|
setSelectedQuestionTypes([
|
|
|
|
|
|
|
|
...selectedQuestionTypes,
|
|
|
|
|
|
|
|
optionValue,
|
|
|
|
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setSelectedQuestionTypes((prev) =>
|
|
|
|
setSelectedQuestionTypes(
|
|
|
|
prev.filter((questionType) => questionType !== optionValue),
|
|
|
|
selectedQuestionTypes.filter(
|
|
|
|
|
|
|
|
(questionType) => questionType !== optionValue,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}}
|
|
|
@ -189,10 +199,12 @@ export default function QuestionsHomePage() {
|
|
|
|
searchPlaceholder="Add location filter"
|
|
|
|
searchPlaceholder="Add location filter"
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
onOptionChange={(optionValue, checked) => {
|
|
|
|
if (checked) {
|
|
|
|
if (checked) {
|
|
|
|
setSelectedLocations((prev) => [...prev, optionValue]);
|
|
|
|
setSelectedLocations([...selectedLocations, optionValue]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setSelectedLocations((prev) =>
|
|
|
|
setSelectedLocations(
|
|
|
|
prev.filter((location) => location !== optionValue),
|
|
|
|
selectedLocations.filter(
|
|
|
|
|
|
|
|
(location) => location !== optionValue,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|