1- import { Children , Fragment , useEffect } from "react" ;
1+ import { Children , Fragment , useEffect , useState } from "react" ;
22import Head from "next/head" ;
33import { TagIcon } from "@heroicons/react/outline" ;
44import ArticlePreview from "../../components/ArticlePreview/ArticlePreview" ;
@@ -10,6 +10,7 @@ import { useRouter } from "next/router";
1010import Link from "next/link" ;
1111import Image from "next/image" ;
1212import challenge from "../../public/images/announcements/challenge.png" ;
13+ import SearchBar from "../../components/ArticleSearch/SearchBar" ;
1314
1415// Needs to be added to DB but testing with hardcoding
1516const tagsToShow = [
@@ -29,7 +30,7 @@ const ArticlesPage = () => {
2930
3031 const { filter, tag : dirtyTag } = router . query ;
3132 const tag = typeof dirtyTag === "string" ? dirtyTag . toLowerCase ( ) : null ;
32-
33+ const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
3334 type Filter = "newest" | "oldest" | "top" ;
3435 const filters : Filter [ ] = [ "newest" , "oldest" , "top" ] ;
3536
@@ -45,7 +46,7 @@ const ArticlesPage = () => {
4546
4647 const { status, data, isFetchingNextPage, fetchNextPage, hasNextPage } =
4748 trpc . post . all . useInfiniteQuery (
48- { limit : 15 , sort : selectedSortFilter , tag } ,
49+ { limit : 15 , sort : selectedSortFilter , tag, searchTerm } ,
4950 {
5051 getNextPageParam : ( lastPage ) => lastPage . nextCursor ,
5152 }
@@ -97,7 +98,8 @@ const ArticlesPage = () => {
9798 "Articles"
9899 ) }
99100 </ h1 >
100- < div >
101+ < SearchBar searchTerm = { searchTerm } setSearchTerm = { setSearchTerm } />
102+ < div className = 'min-w-fit' >
101103 < label htmlFor = "filter" className = "sr-only" >
102104 Location
103105 </ label >
0 commit comments