@@ -17,6 +17,10 @@ function SearchModal({ isOpen, setOpen, circleId }: SearchModalProps) {
1717 const { getAccessToken } = authContext ;
1818
1919 const [ results , setResults ] = useState < any [ ] > ( [ ] ) ;
20+ const [ totalMatches , setTotalMatches ] = useState ( 0 ) ;
21+ const [ averageLength , setAverageLength ] = useState ( 0 ) ;
22+ const [ mostFoundAuthor , setMostFoundAuthor ] = useState ( "" ) ;
23+
2024 async function handleSubmit ( e : React . FormEvent < HTMLFormElement > ) {
2125 e . preventDefault ( ) ;
2226 const token = await getAccessToken ( ) ;
@@ -35,12 +39,17 @@ function SearchModal({ isOpen, setOpen, circleId }: SearchModalProps) {
3539 } )
3640 . then ( async ( response ) => {
3741 const data = await response . json ( ) ;
38- const mappedResults = data . map ( ( result : any ) => ( {
42+ const mappedResults = data . results . map ( ( result : any ) => ( {
3943 content : result . content ,
4044 created_at : result . created_at ,
4145 author : result . author_username
4246 } ) ) ;
4347 setResults ( mappedResults ) ;
48+ setTotalMatches ( data . stats . total_matches ) ;
49+ setAverageLength ( data . stats . average_length ) ;
50+ setMostFoundAuthor ( data . stats . most_found_author
51+ ? data . stats . most_found_author
52+ : "No author found" ) ;
4453 if ( ! response . ok ) {
4554 console . log ( "Error:" , data ) ;
4655 }
@@ -84,6 +93,11 @@ function SearchModal({ isOpen, setOpen, circleId }: SearchModalProps) {
8493 </ div >
8594 ) ) }
8695 </ div >
96+ < div className = "search-stats" >
97+ Total matches: { totalMatches ? totalMatches : "N/A" } < br />
98+ Average match length: { averageLength ? averageLength : "N/A" } < br />
99+ Most found author: { mostFoundAuthor ? mostFoundAuthor : "N/A" }
100+ </ div >
87101 </ div >
88102 ) ;
89103}
0 commit comments