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' ;
2- // import moment from 'moment';
6+ import moment from 'moment' ;
37import Typography from '@mui/material/Typography' ;
48import makeStyles from '@mui/styles/makeStyles' ;
5- // import DbContext from '@db/DbContext';
6- // import ddbh from '@utils/duckDbHelpers.js';
9+ import DbContext from '@db/DbContext' ;
10+ import 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 ,
@@ -17,33 +23,38 @@ const useStyles = makeStyles(theme => ({
1723function LastUpdated ( ) {
1824 const classes = useStyles ( ) ;
1925 const [ lastUpdated , setLastUpdated ] = useState ( '' ) ;
20- // const { conn } = useContext(DbContext);
26+ const { conn } = useContext ( DbContext ) ;
2127
2228 useEffect ( ( ) => {
23- // const getLastUpdated = async () => {
24- // const getLastUpdatedSQL = 'select max(createddate) from requests_2025;';
25-
26- // const lastUpdatedAsArrowTable = await conn.query(getLastUpdatedSQL);
27- // const results = ddbh.getTableData(lastUpdatedAsArrowTable);
29+ if ( DATA_SOURCE === 'SOCRATA' ) {
30+ setLastUpdated ( Date . now ( ) )
31+ }
32+ } , [ DATA_SOURCE ] )
2833
29- // if (!isEmpty(results)) {
30- // const lastUpdatedValue = results[0];
31- // setLastUpdated(lastUpdatedValue);
32- // }
33- // };
34-
35- // getLastUpdated(); // advice for Melissa: just fake this part
36- setLastUpdated ( Date . now ( ) ) // we will come up with a fix for this later
37- } , [ ] ) ;
34+ useEffect ( ( ) => {
35+ const getLastUpdated = async ( ) => {
36+ const getLastUpdatedSQL = 'select max(createddate) from requests_2025;' ;
37+
38+ const lastUpdatedAsArrowTable = await conn . query ( getLastUpdatedSQL ) ;
39+ const results = ddbh . getTableData ( lastUpdatedAsArrowTable ) ;
40+
41+ if ( ! isEmpty ( results ) ) {
42+ const lastUpdatedValue = results [ 0 ] ;
43+ setLastUpdated ( lastUpdatedValue ) ;
44+ }
45+ } ;
46+
47+ if ( DATA_SOURCE !== 'SOCRATA' && conn ) {
48+ getLastUpdated ( ) ;
49+ }
50+ } , [ conn , DATA_SOURCE ] ) ;
3851
3952 return (
4053 lastUpdated && (
4154 < div >
4255 < Typography variant = "body2" className = { classes . lastUpdated } >
4356 { toNonBreakingSpaces (
44- //* Quickfix - hard coded date last updated until 2025 data available
45- // `Data last updated ${moment(lastUpdated).format('MM/DD/YY')}`
46- `Data last updated 12/31/24`
57+ `Data last updated ${ moment ( lastUpdated ) . format ( 'MM/DD/YY' ) } `
4758 ) }
4859 </ Typography >
4960 </ div >
0 commit comments