From 278b4435dbcc7e72ee0cf0283fb12704eeb6556e Mon Sep 17 00:00:00 2001 From: Matt E Date: Sat, 29 Jun 2024 21:47:59 -0700 Subject: [PATCH 1/7] PR: Call function implemented for stop IDs --- frontend/src/TransitPredictionsPage.js | 81 +++++++++++++++----------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/frontend/src/TransitPredictionsPage.js b/frontend/src/TransitPredictionsPage.js index aadde15..30f1449 100644 --- a/frontend/src/TransitPredictionsPage.js +++ b/frontend/src/TransitPredictionsPage.js @@ -29,11 +29,6 @@ export default function TransitPredictionsPage() { getSCEtaPredictions(); }, []); - // this does three things - // 1. replace all non alpha numeric chars in the stop name with dashes - // 2. replace the character "&" with "and" if it appears - // 3. convert all characters in the stop to lowercase. - // for example "Santa Clara & 6th" becomes "santa-clara-and-6th" function encode(stopName) { return stopName.replace(/\s+/g, '-') .replace(/&/g, 'and') @@ -42,38 +37,34 @@ export default function TransitPredictionsPage() { .toLowerCase(); } - // get stopOptions useEffect(() => { let uniqueStops = {}; if (busData) { - // get unique stop options busData.forEach((stop) => { let encodedHash = encode(stop.name); - if (!uniqueStops.hasOwnProperty(encodedHash)) { - uniqueStops[encodedHash] = stop.name; - } + uniqueStops[encodedHash] = { + name: stop.name, + ids: Array.isArray(stop.ids) ? stop.ids : [], + }; }); - // if URL hash exists, set the tab to the encoded stop - // otherwise, set tab to the first unique stop + add URL hash if (!selectedStop && Object.keys(uniqueStops).length > 0) { - let hash = window.location.hash.replace(/^#/, '') + let hash = window.location.hash.replace(/^#/, ''); if (uniqueStops.hasOwnProperty(hash)) { - setSelectedStop(uniqueStops[hash]) + setSelectedStop(uniqueStops[hash].name); } else { let firstStop = Object.keys(uniqueStops)[0]; - setSelectedStop(uniqueStops[firstStop]); - window.location.hash = firstStop + setSelectedStop(uniqueStops[firstStop].name); + window.location.hash = firstStop; } } - } setStopOptions(Object.values(uniqueStops)); }, [busData, selectedStop]); const changeTab = (newStop) => { setSelectedStop(newStop); - window.location.hash = encode(newStop) + window.location.hash = encode(newStop); }; function maybeRenderCallButton(stopId) { @@ -91,7 +82,6 @@ export default function TransitPredictionsPage() { ); } - //set default marker icon delete L.Icon.Default.prototype._getIconUrl; L.Icon.Default.mergeOptions({ @@ -124,33 +114,55 @@ export default function TransitPredictionsPage() {

SCEta's Transit Predictions

Below predictions are up-to-date as of {timeAtMount}

- {/* Dropdown for smaller screens */}
- {/* Tabs for larger screens */} + + {/* Dropdown for smaller screens */}
- {stopOptions.map((stopName) => ( - ))}
+ + {/* Tabs for larger screens */}
{!!busData.length && busData.map((stop) => ( stop.name === selectedStop && -
-
{stop.name}
+
+ +
+ {stop.name} +
+
+ {stop.ids.length > 0 ? ( + <> + {stop.ids.some(id => !isNaN(id)) ? ( + !isNaN(id))}`} + className="inline-block px-2 py-1 ml-2 text-white bg-blue-600 border border-blue-600 rounded hover:bg-blue-700" + > + CLICK TO CALL + + ) : ( + NO CALL AVAILABLE + )} + + ) : ( + No IDs + )} +
{stop.predictions.length === 0 ? ( No predictions available at this time ) : ( @@ -165,11 +177,13 @@ export default function TransitPredictionsPage() { destinations={prediction.destinations} useDestinationAsName={stop.use_destination_as_name} timeAtMount={timeAtMount} - /> + /> ))}
)}
+ + ))} {!!busData.length && busData.map((stop) => ( stop.name === selectedStop && @@ -185,7 +199,6 @@ export default function TransitPredictionsPage() {
))} - From d00f5793439ec36f4fe1d5bb0763120c8e988500 Mon Sep 17 00:00:00 2001 From: Matt E Date: Sat, 29 Jun 2024 21:56:02 -0700 Subject: [PATCH 2/7] minor update for comments --- frontend/src/TransitPredictionsPage.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/TransitPredictionsPage.js b/frontend/src/TransitPredictionsPage.js index 30f1449..ef58b36 100644 --- a/frontend/src/TransitPredictionsPage.js +++ b/frontend/src/TransitPredictionsPage.js @@ -29,6 +29,11 @@ export default function TransitPredictionsPage() { getSCEtaPredictions(); }, []); + // this does three things + // 1. replace all non alpha numeric chars in the stop name with dashes + // 2. replace the character "&" with "and" if it appears + // 3. convert all characters in the stop to lowercase. + // for example "Santa Clara & 6th" becomes "santa-clara-and-6th" function encode(stopName) { return stopName.replace(/\s+/g, '-') .replace(/&/g, 'and') @@ -37,9 +42,11 @@ export default function TransitPredictionsPage() { .toLowerCase(); } + // get stopOptions useEffect(() => { let uniqueStops = {}; if (busData) { + // get unique stop options busData.forEach((stop) => { let encodedHash = encode(stop.name); uniqueStops[encodedHash] = { @@ -48,6 +55,8 @@ export default function TransitPredictionsPage() { }; }); + // if URL hash exists, set the tab to the encoded stop + // otherwise, set tab to the first unique stop + add URL hash if (!selectedStop && Object.keys(uniqueStops).length > 0) { let hash = window.location.hash.replace(/^#/, ''); if (uniqueStops.hasOwnProperty(hash)) { @@ -67,6 +76,7 @@ export default function TransitPredictionsPage() { window.location.hash = encode(newStop); }; + //set default marker icon function maybeRenderCallButton(stopId) { if (Number.isNaN(Number.parseInt(stopId))) { return <> @@ -114,6 +124,7 @@ export default function TransitPredictionsPage() {

SCEta's Transit Predictions

Below predictions are up-to-date as of {timeAtMount}

+ {/* Dropdown for smaller screens */}
- - {/* Dropdown for smaller screens */} + {/* Tabs for larger screens */}
{stopOptions.map((stop) => ( ))}
-
{!!busData.length && busData.map((stop) => ( stop.name === selectedStop && -
- -
- {stop.name} -
- - -
- { - <> - {stop.ids.some(id => !isNaN(id)) && ( - !isNaN(id))}`} - className="inline-block px-2 py-1 ml-2 text-white bg-blue-600 border border-blue-600 rounded hover:bg-blue-700" - > - CLICK TO CALL - - )} - - } -
- - +
+
{stop.name}
{stop.predictions.length === 0 ? ( No predictions available at this time ) : ( @@ -189,13 +181,11 @@ export default function TransitPredictionsPage() { destinations={prediction.destinations} useDestinationAsName={stop.use_destination_as_name} timeAtMount={timeAtMount} - /> + /> ))}
)}
- - ))} {!!busData.length && busData.map((stop) => ( stop.name === selectedStop && @@ -211,8 +201,9 @@ export default function TransitPredictionsPage() {
))} + ); -} +} \ No newline at end of file diff --git a/server/app.py b/server/app.py index 11a526a..233bb7d 100644 --- a/server/app.py +++ b/server/app.py @@ -259,4 +259,4 @@ def get_debug(): if __name__ == '__main__': logging.info(f"running on {args.host}, listening on port {args.port}") - uvicorn.run("app:app", host=args.host, port=args.port, reload=True) + uvicorn.run("app:app", host=args.host, port=args.port, reload=True) \ No newline at end of file From 597d16d1575551293aa6b88a6f3da59e97b9b2b6 Mon Sep 17 00:00:00 2001 From: Matt E Date: Fri, 19 Jul 2024 01:34:07 -0700 Subject: [PATCH 6/7] Final updates --- frontend/src/TransitPredictionsPage.js | 2 +- server/app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/TransitPredictionsPage.js b/frontend/src/TransitPredictionsPage.js index 87261df..d301852 100644 --- a/frontend/src/TransitPredictionsPage.js +++ b/frontend/src/TransitPredictionsPage.js @@ -206,4 +206,4 @@ export default function TransitPredictionsPage() { ); -} \ No newline at end of file +} diff --git a/server/app.py b/server/app.py index 233bb7d..11a526a 100644 --- a/server/app.py +++ b/server/app.py @@ -259,4 +259,4 @@ def get_debug(): if __name__ == '__main__': logging.info(f"running on {args.host}, listening on port {args.port}") - uvicorn.run("app:app", host=args.host, port=args.port, reload=True) \ No newline at end of file + uvicorn.run("app:app", host=args.host, port=args.port, reload=True) From 615d6cfd7dbc78ae6ab5220c1f3f5f6de00f7855 Mon Sep 17 00:00:00 2001 From: Matt E Date: Mon, 29 Jul 2024 13:47:36 -0700 Subject: [PATCH 7/7] Call button only for mobile --- frontend/src/TransitPredictionsPage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/TransitPredictionsPage.js b/frontend/src/TransitPredictionsPage.js index d301852..50b5443 100644 --- a/frontend/src/TransitPredictionsPage.js +++ b/frontend/src/TransitPredictionsPage.js @@ -171,7 +171,9 @@ export default function TransitPredictionsPage() { No predictions available at this time ) : (
- {maybeRenderCallButton(stop.id)} +
+ {maybeRenderCallButton(stop.id)} +
{stop.predictions .sort((a, b) => a.route.localeCompare(b.route)) .map((prediction, predictionIndex) => (