@@ -5,7 +5,7 @@ import { CreatePerson } from "../../components";
55import { type PersonInterface } from "@churchapps/helpers" ;
66import { PersonHelper , Loading , ApiHelper , ArrayHelper , Locale , PersonAvatar } from "@churchapps/apphelper" ;
77import { Table , TableBody , TableRow , TableCell , TableHead , Tooltip , Icon , IconButton , Typography , Stack , Box , Chip , Card } from "@mui/material" ;
8- import { Email as EmailIcon , Phone as PhoneIcon } from "@mui/icons-material" ;
8+ import { Email as EmailIcon , KeyboardArrowDown as KeyboardArrowDownIcon , KeyboardArrowUp as KeyboardArrowUpIcon , Phone as PhoneIcon } from "@mui/icons-material" ;
99
1010interface Props {
1111 people : PersonInterface [ ] ;
@@ -315,20 +315,58 @@ const PeopleSearchResults = memo(function PeopleSearchResults(props: Props) {
315315 ) ;
316316 } , [ people , getColumns , navigate ] ) ;
317317
318+ const getSortArrows = useCallback (
319+ ( isActive : boolean ) => (
320+ < Box
321+ component = "span"
322+ sx = { {
323+ display : "inline-flex" ,
324+ flexDirection : "column" ,
325+ alignItems : "center" ,
326+ justifyContent : "center" ,
327+ ml : 0.5 ,
328+ flexShrink : 0 ,
329+ lineHeight : 0 ,
330+ color : isActive ? "var(--text-main)" : "var(--text-muted)"
331+ } } >
332+ < KeyboardArrowUpIcon
333+ sx = { {
334+ fontSize : 16 ,
335+ mb : "-6px" ,
336+ opacity : isActive && sortDirection ? 1 : 0.45
337+ } }
338+ />
339+ < KeyboardArrowDownIcon
340+ sx = { {
341+ fontSize : 16 ,
342+ opacity : isActive && ! sortDirection ? 1 : 0.45
343+ } }
344+ />
345+ </ Box >
346+ ) ,
347+ [ sortDirection ]
348+ ) ;
349+
318350 const headers = useMemo ( ( ) => {
319351 const result : JSX . Element [ ] = [ ] ;
320352 columns . forEach ( ( c ) => {
321353 if ( selectedColumns . indexOf ( c . key ) > - 1 ) {
354+ const isSortable = c . key !== "photo" && c . key !== "deleteOption" ;
355+ const isActive = currentSortedCol === c . key ;
322356 result . push (
323- < th key = { c . key } onClick = { ( ) => sortTableByKey ( c . key ) } >
324- < span style = { { float : "left" } } > { c . shortName } </ span >
325- { c . key !== "photo" && c . key !== "deleteOption" && (
326- < div style = { { display : "flex" } } >
327- < div style = { { marginTop : "5px" } } className = { `${ sortDirection && currentSortedCol === c . key ? "sortAscActive" : "sortAsc" } ` } > </ div >
328- < div style = { { marginTop : "14px" } } className = { `${ ! sortDirection && currentSortedCol === c . key ? "sortDescActive" : "sortDesc" } ` } > </ div >
329- </ div >
330- ) }
331- </ th >
357+ < TableCell
358+ key = { c . key }
359+ onClick = { isSortable ? ( ) => sortTableByKey ( c . key ) : undefined }
360+ sx = { {
361+ whiteSpace : "nowrap" ,
362+ minWidth : c . key === "photo" ? 88 : 160 ,
363+ cursor : isSortable ? "pointer" : "default"
364+ } } >
365+ < Box component = "span" sx = { { display : "inline-flex" , alignItems : "center" , verticalAlign : "middle" } } >
366+ < Box component = "span" > { c . shortName } </ Box >
367+ { isSortable && getSortArrows ( isActive ) }
368+ </ Box >
369+ </ TableCell >
332370 ) ;
333371 }
334372 } ) ;
@@ -337,14 +375,21 @@ const PeopleSearchResults = memo(function PeopleSearchResults(props: Props) {
337375 optionalColumns . forEach ( ( c ) => {
338376 const key = c . id ;
339377 if ( selectedColumns . indexOf ( key ) > - 1 ) {
378+ const isActive = currentSortedCol === key ;
340379 result . push (
341- < th key = { key } onClick = { ( ) => sortTableByKey ( key ) } >
342- < span style = { { float : "left" } } > { c . title } </ span >
343- < div style = { { display : "flex" } } >
344- < div style = { { marginTop : "5px" } } className = { `${ sortDirection && currentSortedCol === key ? "sortAscActive" : "sortAsc" } ` } > </ div >
345- < div style = { { marginTop : "14px" } } className = { `${ ! sortDirection && currentSortedCol === key ? "sortDescActive" : "sortDesc" } ` } > </ div >
346- </ div >
347- </ th >
380+ < TableCell
381+ key = { key }
382+ onClick = { ( ) => sortTableByKey ( key ) }
383+ sx = { {
384+ whiteSpace : "nowrap" ,
385+ minWidth : 160 ,
386+ cursor : "pointer"
387+ } } >
388+ < Box component = "span" sx = { { display : "inline-flex" , alignItems : "center" , verticalAlign : "middle" } } >
389+ < Box component = "span" > { c . title } </ Box >
390+ { getSortArrows ( isActive ) }
391+ </ Box >
392+ </ TableCell >
348393 ) ;
349394 }
350395 } ) ;
@@ -355,7 +400,7 @@ const PeopleSearchResults = memo(function PeopleSearchResults(props: Props) {
355400 < TableRow > { result } </ TableRow >
356401 </ TableHead >
357402 ) ;
358- } , [ columns , selectedColumns , optionalColumns , sortDirection , currentSortedCol , sortTableByKey ] ) ;
403+ } , [ columns , selectedColumns , optionalColumns , currentSortedCol , sortTableByKey , getSortArrows ] ) ;
359404
360405 const getResults = ( ) => {
361406 if ( people . length === 0 ) {
@@ -369,21 +414,39 @@ const PeopleSearchResults = memo(function PeopleSearchResults(props: Props) {
369414 }
370415
371416 return (
372- < Table
373- id = "peopleTable"
417+ < Box
374418 sx = { {
375- "& .MuiTableCell-root" : {
376- borderBottom : "1px solid var(--border-light)" ,
377- py : 2
378- } ,
379- "& .MuiTableHead-root .MuiTableCell-root" : {
380- backgroundColor : "var(--bg-sub)" ,
381- fontWeight : 600
382- }
419+ width : "100%" ,
420+ overflowX : "auto" ,
421+ overflowY : "hidden" ,
422+ WebkitOverflowScrolling : "touch"
383423 } } >
384- { headers }
385- < TableBody > { rows } </ TableBody >
386- </ Table >
424+ < Table
425+ id = "peopleTable"
426+ sx = { {
427+ width : "max-content" ,
428+ minWidth : "100%" ,
429+ tableLayout : "auto" ,
430+ "& .MuiTableCell-root" : {
431+ borderBottom : "1px solid var(--border-light)" ,
432+ py : 2 ,
433+ px : 2 ,
434+ verticalAlign : "top" ,
435+ whiteSpace : "nowrap"
436+ } ,
437+ "& .MuiTableHead-root .MuiTableCell-root" : {
438+ backgroundColor : "var(--bg-sub)" ,
439+ fontWeight : 600 ,
440+ color : "var(--text-main)" ,
441+ "&:hover" : { color : "var(--text-main)" } ,
442+ "&:active" : { color : "var(--text-main)" } ,
443+ "& span" : { color : "inherit" }
444+ }
445+ } } >
446+ { headers }
447+ < TableBody > { rows } </ TableBody >
448+ </ Table >
449+ </ Box >
387450 ) ;
388451 } ;
389452
0 commit comments