1+ /*
2+ Component to show the date of the last data update in the footer which assumes data is available in conn from DbContext,
3+ which is no longer a valid assumption if using Socrata or in new codebase structure
4+ */
15import React , { useContext , useEffect , useState } from 'react' ;
26import moment from 'moment' ;
37import Typography from '@mui/material/Typography' ;
@@ -6,6 +10,8 @@ import DbContext from '@db/DbContext';
610import ddbh from '@utils/duckDbHelpers.js' ;
711import { isEmpty , toNonBreakingSpaces } from '@utils' ;
812
13+ const DATA_SOURCE = import . meta. env . VITE_DATA_SOURCE ;
14+
915const useStyles = makeStyles ( theme => ( {
1016 lastUpdated : {
1117 fontWeight : theme . typography . fontWeightMedium ,
@@ -19,30 +25,36 @@ function LastUpdated() {
1925 const [ lastUpdated , setLastUpdated ] = useState ( '' ) ;
2026 const { conn } = useContext ( DbContext ) ;
2127
28+ useEffect ( ( ) => {
29+ if ( DATA_SOURCE === 'SOCRATA' ) {
30+ setLastUpdated ( Date . now ( ) )
31+ }
32+ } , [ DATA_SOURCE ] )
33+
2234 useEffect ( ( ) => {
2335 const getLastUpdated = async ( ) => {
2436 const getLastUpdatedSQL = 'select max(createddate) from requests_2025;' ;
25-
37+
2638 const lastUpdatedAsArrowTable = await conn . query ( getLastUpdatedSQL ) ;
2739 const results = ddbh . getTableData ( lastUpdatedAsArrowTable ) ;
28-
40+
2941 if ( ! isEmpty ( results ) ) {
3042 const lastUpdatedValue = results [ 0 ] ;
3143 setLastUpdated ( lastUpdatedValue ) ;
3244 }
3345 } ;
34-
35- getLastUpdated ( ) ;
36- } , [ conn ] ) ;
46+
47+ if ( DATA_SOURCE !== 'SOCRATA' && conn ) {
48+ getLastUpdated ( ) ;
49+ }
50+ } , [ conn , DATA_SOURCE ] ) ;
3751
3852 return (
3953 lastUpdated && (
4054 < div >
4155 < Typography variant = "body2" className = { classes . lastUpdated } >
4256 { toNonBreakingSpaces (
43- //* Quickfix - hard coded date last updated until 2025 data available
44- // `Data last updated ${moment(lastUpdated).format('MM/DD/YY')}`
45- `Data last updated 12/31/24`
57+ `Data last updated ${ moment ( lastUpdated ) . format ( 'MM/DD/YY' ) } `
4658 ) }
4759 </ Typography >
4860 </ div >
0 commit comments