Skip to content

Commit

Permalink
t puMerge branch 'main' of https://github.com/hackforla/311-data
Browse files Browse the repository at this point in the history
  • Loading branch information
bphan002 committed May 30, 2024
2 parents d4a48bb + 564aac7 commit c39a430
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { pointsWithinGeo, getNcByLngLatv2 } from './geoUtils';
import RequestsLayer from './layers/RequestsLayer';
import BoundaryLayer from './layers/BoundaryLayer';
import AddressLayer from './layers/AddressLayer';
import DbContext from '@db/DbContext';

// import MapOverview from './controls/MapOverview';

Expand Down Expand Up @@ -103,6 +104,9 @@ const hoverables = ['nc-fills', 'cc-fills'];
const featureLayers = ['request-circles', ...hoverables];

class Map extends React.Component {
// Note: 'this.context' is defined using the static contextType property
// static contextType assignment allows Map to access values provided by DbContext.Provider
static contextType = DbContext;
constructor(props) {
super(props);

Expand Down Expand Up @@ -172,9 +176,19 @@ class Map extends React.Component {
}

componentDidUpdate(prevProps, prevState) {
const entireMapLoadTime = () => {
if (this.map.isSourceLoaded('requests')) {
const { dbStartTime } = this.context;
const pinLoadEndTime = performance.now()
console.log(`Pin load time: ${Math.floor(pinLoadEndTime - dbStartTime)} ms`)
this.map.off('idle', entireMapLoadTime);
}
}

if (this.props.requests != prevProps.requests) {
if (this.state.mapReady) {
this.setState({ requests: this.props.requests });
this.map.on('idle', entireMapLoadTime)
// this.map.once('idle', this.setFilteredRequestCounts);
} else {
this.map.once('idle', () => {
Expand Down
4 changes: 2 additions & 2 deletions components/Map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MapContainer extends React.Component {

createRequestsTable = async () => {
this.setState({ isTableLoading: true });
const { conn, tableNameByYear } = this.context;
const { conn, tableNameByYear, setDbStartTime } = this.context;
const startDate = this.props.startDate; // directly use the startDate prop transformed for redux store
const year = moment(startDate).year(); // extrac the year
const datasetFileName = `requests${year}.parquet`;
Expand All @@ -78,6 +78,7 @@ class MapContainer extends React.Component {
`CREATE TABLE IF NOT EXISTS ${tableNameByYear} AS SELECT * FROM "${datasetFileName}"`; // query from parquet

const startTime = performance.now(); // start the time tracker
setDbStartTime(startTime)

try {
await conn.query(createSQL);
Expand All @@ -99,7 +100,6 @@ class MapContainer extends React.Component {

async componentDidUpdate(prevProps) {
const { activeMode, pins, startDate, endDate } = this.props;

// create conditions to check if year or startDate or endDate changed
const yearChanged = moment(prevProps.startDate).year() !== moment(startDate).year();
const startDateChanged = prevProps.startDate !== startDate;
Expand Down
1 change: 1 addition & 0 deletions components/db/DbContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const DbContext = React.createContext({
conn: null,
worker: null,
tableNameByYear: '',
startTime: null,
});

export default DbContext;
8 changes: 7 additions & 1 deletion components/db/DbProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function DbProvider({ children, startDate }) {
const [conn, setConn] = useState(null);
const [worker, setWorker] = useState(null);
const [tableNameByYear, setTableNameByYear] = useState('');
const [dbStartTime, setDbStartTime] = useState(null);

useEffect(() => {
const dbInitialize = async () => {
Expand Down Expand Up @@ -127,7 +128,12 @@ function DbProvider({ children, startDate }) {

return (
<DbContext.Provider value={{
db, conn, worker, tableNameByYear,
db,
conn,
worker,
tableNameByYear,
dbStartTime,
setDbStartTime,
}}
>
{children}
Expand Down

0 comments on commit c39a430

Please sign in to comment.