11"use client"
2- import { Tab , Tabs , Box , CardHeader , Typography } from "@mui/material"
2+
3+ import Link from "next/link"
4+ import {
5+ Tab ,
6+ Tabs ,
7+ Box ,
8+ Card ,
9+ CardHeader ,
10+ CardActionArea ,
11+ Typography
12+ } from "@mui/material"
313import React from "react"
414import { SearchResponse } from "@/utils/api"
515
@@ -10,6 +20,23 @@ type SearchResultsProps = {
1020 updateTab : ( val : number ) => void
1121}
1222
23+ const getResultHref = ( result : SearchResponse ) => {
24+ switch ( result . content_type ) {
25+ case "Officer" :
26+ return `/officer/${ result . uid } `
27+ case "Agency" :
28+ return `/agency/${ result . uid } `
29+ case "Unit" :
30+ return `/unit/${ result . uid } `
31+ case "Complaint" :
32+ return `/complaint/${ result . uid } `
33+ case "Litigation" :
34+ return `/litigation/${ result . uid } `
35+ default :
36+ return "#"
37+ }
38+ }
39+
1340const SearchResults = ( { total, results, tab, updateTab } : SearchResultsProps ) => {
1441 return (
1542 < >
@@ -31,51 +58,80 @@ const SearchResults = ({ total, results, tab, updateTab }: SearchResultsProps) =
3158 < Tab key = "litigation" label = "Litigation" />
3259 </ Tabs >
3360 </ Box >
61+
3462 < Box sx = { { p : 3 } } >
35- < Typography sx = { { marginBottom : "1rem" , fontWeight : "bold" } } > { total } results</ Typography >
63+ < Typography sx = { { mb : 2 , fontWeight : "bold" } } > { total } results</ Typography >
64+
3665 < CustomTabPanel value = { tab } index = { tab } >
37- { results . map ( ( result ) => (
38- < CardHeader
66+ { results . map ( ( result , idx ) => (
67+ < Card
3968 key = { result . uid }
40- title = { result . title }
41- subheader = { result . subtitle }
42- slotProps = { { subheader : { fontWeight : "bold" , color : "#000" } } }
43- action = {
44- < Box >
45- < Box sx = { { display : "flex" , gap : "1rem" } } >
46- < span style = { { fontSize : "14px" , color : "#454C54" , margin : "0 0 1rem 0" } } >
47- { result . details }
48- </ span >
49- </ Box >
50- < Box sx = { { display : "flex" , gap : "1rem" } } >
51- < span style = { { fontSize : "12px" , color : "#666" } } > { result . content_type } </ span >
52- < span style = { { fontSize : "12px" , color : "#666" } } > { result . source } </ span >
53- < span style = { { fontSize : "12px" , color : "#666" } } > { result . last_updated } </ span >
54- </ Box >
55- </ Box >
56- }
69+ variant = "outlined"
5770 sx = { {
58- flexDirection : "column" ,
59- alignItems : "flex-start" ,
60- gap : "0.5rem" ,
61- border : "1px solid #ddd" ,
62- borderBottom : "none" ,
63- ":first-of-type" : {
64- borderTopLeftRadius : "4px" ,
65- borderTopRightRadius : "4px"
66- } ,
67- ":last-of-type" : {
68- borderBottomLeftRadius : "4px" ,
69- borderBottomRightRadius : "4px" ,
70- borderBottom : "1px solid #ddd"
71- } ,
72- "& .MuiCardHeader-content" : {
73- overflow : "hidden"
74- } ,
75- paddingInline : "4.5rem" ,
76- paddingBlock : "2rem"
71+ borderBottomLeftRadius : idx === results . length - 1 ? "4px" : 0 ,
72+ borderBottomRightRadius : idx === results . length - 1 ? "4px" : 0 ,
73+ borderTopLeftRadius : idx === 0 ? "4px" : 0 ,
74+ borderTopRightRadius : idx === 0 ? "4px" : 0 ,
75+ borderBottom : idx === results . length - 1 ? undefined : "none"
7776 } }
78- />
77+ >
78+ < CardActionArea
79+ component = { Link }
80+ href = { getResultHref ( result ) }
81+ sx = { {
82+ display : "block" ,
83+ textAlign : "left" ,
84+ "&:hover" : {
85+ backgroundColor : "#f8f8f8"
86+ }
87+ } }
88+ >
89+ < CardHeader
90+ title = { result . title }
91+ subheader = { result . subtitle }
92+ slotProps = { { subheader : { fontWeight : "bold" , color : "#000" } } }
93+ action = {
94+ < Box >
95+ < Box sx = { { display : "flex" , gap : "1rem" } } >
96+ < span
97+ style = { {
98+ fontSize : "14px" ,
99+ color : "#454C54" ,
100+ margin : "0 0 1rem 0"
101+ } }
102+ >
103+ { Array . isArray ( result . details )
104+ ? result . details . join ( ", " )
105+ : result . details }
106+ </ span >
107+ </ Box >
108+
109+ < Box sx = { { display : "flex" , gap : "1rem" } } >
110+ < span style = { { fontSize : "12px" , color : "#566" } } >
111+ { result . content_type } ``
112+ </ span >
113+ < span style = { { fontSize : "12px" , color : "#566" } } >
114+ { result . source }
115+ </ span >
116+ < span style = { { fontSize : "12px" , color : "#566" } } >
117+ { result . last_updated }
118+ </ span >
119+ </ Box >
120+ </ Box >
121+ }
122+ sx = { {
123+ flexDirection : "column" ,
124+ alignItems : "flex-start" ,
125+ gap : "0.5rem" ,
126+ "& .MuiCardHeader-content" : {
127+ overflow : "hidden"
128+ } ,
129+ paddingInline : "4.5rem" ,
130+ paddingBlock : "2rem"
131+ } }
132+ />
133+ </ CardActionArea >
134+ </ Card >
79135 ) ) }
80136 </ CustomTabPanel >
81137 </ Box >
@@ -102,4 +158,5 @@ const CustomTabPanel = ({ children, value, index, ...other }: TabPanelProps) =>
102158 </ div >
103159 )
104160}
105- export default SearchResults
161+
162+ export default SearchResults
0 commit comments