From 62826ec55269a0fdbcae140dcc398310c96035f5 Mon Sep 17 00:00:00 2001 From: amirhouieh Date: Mon, 15 May 2023 09:41:44 +0200 Subject: [PATCH] add dynamic filters to search page --- src/components/Hero/Hero.tsx | 12 ++---------- src/components/Searchbar/Searchbar.tsx | 4 ++-- src/pages/search.tsx | 12 +++++++++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/components/Hero/Hero.tsx b/src/components/Hero/Hero.tsx index 733e13d..6a2ef89 100644 --- a/src/components/Hero/Hero.tsx +++ b/src/components/Hero/Hero.tsx @@ -4,16 +4,8 @@ import styled from '@emotion/styled' export default function Hero() { return ( - - LOGOS →{' '} - <Title - style={{ whiteSpace: 'nowrap' }} - genericFontFamily="serif" - component="span" - variant="h2" - > - PRESS ENGINE - + + LOGOS → PRESS ENGINE Blog with media written by Logos members diff --git a/src/components/Searchbar/Searchbar.tsx b/src/components/Searchbar/Searchbar.tsx index 14ac4c6..f75df1c 100644 --- a/src/components/Searchbar/Searchbar.tsx +++ b/src/components/Searchbar/Searchbar.tsx @@ -34,7 +34,7 @@ export type SearchbarProps = { export default function Searchbar(props: SearchbarProps) { const { onSearch, onReset } = props - const { resultsNumber, resultsHelperText } = useSearchBarContext() + const { resultsNumber, resultsHelperText, tags } = useSearchBarContext() const [searchScope, setSearchScope] = useState( props.searchScope || ESearchScope.GLOBAL, @@ -178,7 +178,7 @@ export default function Searchbar(props: SearchbarProps) { {!isArticlePage && ( diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 351f4f3..ecf1b37 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -17,20 +17,28 @@ import { SearchLayout } from '@/layouts/SearchLayout' import { RelatedArticles } from '@/components/RelatedArticles' import { RelatedContent } from '@/components/RelatedContent' import { Section } from '@/components/Section/Section' +import api from '@/services/unbody.service' +import { useSearchBarContext } from '@/context/searchbar.context' interface SearchPageProps { articles: SearchResultItem[] blocks: SearchResultItem[] + topics: string[] } export default function SearchPage({ articles: initialArticles = [], blocks: initialBlocks = [], + topics: allTopics = [], }: SearchPageProps) { + const { setTags } = useSearchBarContext() const router = useRouter() - const hasUpdated = useRef(false) const [mounted, setMounted] = useState(false) + useEffect(() => { + setTags(allTopics) + }, [setTags, allTopics]) + const { query: { query = '', topics = [] }, } = router @@ -81,11 +89,13 @@ SearchPage.getLayout = function getLayout(page: ReactNode) { export async function getStaticProps() { const { data: articles = [] } = await unbodyApi.searchArticles() const { data: blocks = [] } = await unbodyApi.serachBlocks() + const { data: topics, errors: topicErrors } = await api.getTopics() return { props: { articles, blocks, + topics, }, } }