From 0c385bd686e3e3b293003de2abc3a8b1442649da Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Mon, 10 Oct 2022 15:08:50 +0800 Subject: [PATCH] [questions][ui] improve mobile styling --- .../questions/ContributeQuestionCard.tsx | 2 +- .../questions/ContributeQuestionDialog.tsx | 4 +- .../questions/QuestionSearchBar.tsx | 19 +- apps/portal/src/pages/questions/index.tsx | 185 ++++++++++-------- 4 files changed, 124 insertions(+), 86 deletions(-) diff --git a/apps/portal/src/components/questions/ContributeQuestionCard.tsx b/apps/portal/src/components/questions/ContributeQuestionCard.tsx index fa11f098..73faba27 100644 --- a/apps/portal/src/components/questions/ContributeQuestionCard.tsx +++ b/apps/portal/src/components/questions/ContributeQuestionCard.tsx @@ -40,7 +40,7 @@ export default function ContributeQuestionCard({ placeholder="Contribute a question" onChange={handleOpenContribute} /> -
+
-
+
-
+
diff --git a/apps/portal/src/components/questions/QuestionSearchBar.tsx b/apps/portal/src/components/questions/QuestionSearchBar.tsx index d72ee69f..a27f043b 100644 --- a/apps/portal/src/components/questions/QuestionSearchBar.tsx +++ b/apps/portal/src/components/questions/QuestionSearchBar.tsx @@ -1,5 +1,8 @@ -import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'; -import { Select, TextInput } from '@tih/ui'; +import { + AdjustmentsHorizontalIcon, + MagnifyingGlassIcon, +} from '@heroicons/react/24/outline'; +import { Button, Select, TextInput } from '@tih/ui'; export type SortOption = { label: string; @@ -7,6 +10,7 @@ export type SortOption = { }; export type QuestionSearchBarProps> = { + onFilterOptionsToggle: () => void; onSortChange?: (sortValue: SortOptions[number]['value']) => void; sortOptions: SortOptions; sortValue: SortOptions[number]['value']; @@ -18,6 +22,7 @@ export default function QuestionSearchBar< onSortChange, sortOptions, sortValue, + onFilterOptionsToggle, }: QuestionSearchBarProps) { return (
@@ -39,7 +44,15 @@ export default function QuestionSearchBar< label="Sort by" options={sortOptions} value={sortValue} - onChange={onSortChange}> + onChange={onSortChange} + /> +
); } diff --git a/apps/portal/src/pages/questions/index.tsx b/apps/portal/src/pages/questions/index.tsx index 5ca513fe..d7558bb0 100644 --- a/apps/portal/src/pages/questions/index.tsx +++ b/apps/portal/src/pages/questions/index.tsx @@ -1,7 +1,9 @@ import { subMonths, subYears } from 'date-fns'; import { useRouter } from 'next/router'; import { useEffect, useMemo, useState } from 'react'; +import { NoSymbolIcon } from '@heroicons/react/24/outline'; import type { QuestionsQuestionType } from '@prisma/client'; +import { SlideOut } from '@tih/ui'; import QuestionOverviewCard from '~/components/questions/card/QuestionOverviewCard'; import ContributeQuestionCard from '~/components/questions/ContributeQuestionCard'; @@ -59,17 +61,22 @@ export default function QuestionsHomePage() { : undefined; }, [selectedQuestionAge]); - const { data: questions } = trpc.useQuery([ - 'questions.questions.getQuestionsByFilter', + const { data: questions } = trpc.useQuery( + [ + 'questions.questions.getQuestionsByFilter', + { + companies: selectedCompanies, + endDate: today, + locations: selectedLocations, + questionTypes: selectedQuestionTypes, + roles: [], + startDate, + }, + ], { - companies: selectedCompanies, - endDate: today, - locations: selectedLocations, - questionTypes: selectedQuestionTypes, - roles: [], - startDate, + keepPreviousData: true, }, - ]); + ); const utils = trpc.useContext(); const { mutate: createQuestion } = trpc.useMutation( @@ -83,6 +90,7 @@ export default function QuestionsHomePage() { const [hasLanded, setHasLanded] = useState(false); const [loaded, setLoaded] = useState(false); + const [filterDrawerOpen, setFilterDrawerOpen] = useState(false); const companyFilterOptions = useMemo(() => { return COMPANIES.map((company) => ({ @@ -153,79 +161,72 @@ export default function QuestionsHomePage() { return null; } + const filterSidebar = ( +
+ { + if (checked) { + setSelectedCompanies([...selectedCompanies, optionValue]); + } else { + setSelectedCompanies( + selectedCompanies.filter((company) => company !== optionValue), + ); + } + }} + /> + { + if (checked) { + setSelectedQuestionTypes([...selectedQuestionTypes, optionValue]); + } else { + setSelectedQuestionTypes( + selectedQuestionTypes.filter( + (questionType) => questionType !== optionValue, + ), + ); + } + }} + /> + { + setSelectedQuestionAge(optionValue); + }} + /> + { + if (checked) { + setSelectedLocations([...selectedLocations, optionValue]); + } else { + setSelectedLocations( + selectedLocations.filter((location) => location !== optionValue), + ); + } + }} + /> +
+ ); + return !hasLanded ? ( ) : ( -
-
- -
-
-
+
+
+
+
+
{ createQuestion({ @@ -250,6 +251,9 @@ export default function QuestionsHomePage() { }, ]} sortValue="most-recent" + onFilterOptionsToggle={() => { + setFilterDrawerOpen(!filterDrawerOpen); + }} onSortChange={(value) => { // eslint-disable-next-line no-console console.log(value); @@ -257,7 +261,6 @@ export default function QuestionsHomePage() { /> {(questions ?? []).map((question) => ( ))} + {(questions ?? []).length === 0 && ( +
+ +

Nothing found. Try changing your search filters.

+
+ )}
+ +
+ { + setFilterDrawerOpen(false); + }}> + {filterSidebar} + +
);