-
Notifications
You must be signed in to change notification settings - Fork 7
Fix ESLint configuration, fix errors, add as GitHub action #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bdab6c4
7c03b77
dd5acb3
1cd3610
1ca7d1c
f881109
e865dc1
5d3adaa
9e09bb4
3e17928
427fc7a
f11003d
1b985a6
874db79
3b978d6
cd500a5
a361887
dba64f0
5aac8c9
99328e5
250f1e2
bdcb707
d497ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Run Build and Lint Typescript | ||
|
|
||
| on: | ||
| push: | ||
|
|
||
| jobs: | ||
| build-and-lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| # Run build first to ensure all files exist | ||
| - name: Build frontend | ||
| run: npm ci && npm run build | ||
|
|
||
| # Run ESLint + TypeScript checks | ||
| - name: Run lint | ||
| run: npm run lint | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,6 @@ import ShuttleIcon from "./ShuttleIcon"; | |
| import type { ShuttleRouteData, ShuttleStopData } from "../ts/types/route"; | ||
| import '../styles/MapKitMap.css'; | ||
| import type { VehicleInformationMap } from "../ts/types/vehicleLocation"; | ||
| import type { Route } from "../ts/types/schedule"; | ||
| import { log } from "../ts/logger"; | ||
|
|
||
| async function generateRoutePolylines(updatedRouteData: ShuttleRouteData) { | ||
| // Use MapKit Directions API to generate polylines for each route segment | ||
|
|
@@ -106,16 +104,15 @@ type MapKitMapProps = { | |
| // @ts-expect-error selectedRoutes is never used | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export default function MapKitMap({ routeData, vehicles, generateRoutes = false, selectedRoute, setSelectedRoute, isFullscreen = false }: MapKitMapProps) { | ||
| const mapRef = useRef(null); | ||
| const mapContainerRef = useRef<HTMLDivElement | null>(null); | ||
| const mapRef = useRef<mapkit.Map | null>(null); | ||
| const [mapLoaded, setMapLoaded] = useState(false); | ||
| const token = import.meta.env.VITE_MAPKIT_KEY; | ||
| const [map, setMap] = useState<(mapkit.Map | null)>(null); | ||
| const token = (import.meta.env.VITE_MAPKIT_KEY || '') as string; | ||
| const vehicleOverlays = useRef<Record<string, mapkit.ShuttleAnnotation>>({}); | ||
|
|
||
|
|
||
| const circleWidth = 15; | ||
| const selectedMarkerRef = useRef<mapkit.MarkerAnnotation | null>(null); | ||
| const overlays: mapkit.Overlay[] = []; | ||
|
|
||
| // source: https://developer.apple.com/documentation/mapkitjs/loading-the-latest-version-of-mapkit-js | ||
| const setupMapKitJs = async () => { | ||
|
|
@@ -138,11 +135,11 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| setMapLoaded(true); | ||
| }; | ||
| mapkitScript(); | ||
| }, []); | ||
| }, [token]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since token never changes, we shouldnt
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change. I pass
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eslint github actions doesnt fail on warnings i thought?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think by default it doesn't, but if you pass
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to enforce 0 warnings? I feel like sometimes the warnings are fine as react dependency arrays don't really need some of the dependencies eslint is hinting at |
||
|
|
||
| // create the map | ||
| useEffect(() => { | ||
| if (mapLoaded) { | ||
| if (mapContainerRef.current && mapLoaded) { | ||
|
|
||
| // center on RPI | ||
| const center = new mapkit.Coordinate(42.730216, -73.675690); | ||
|
|
@@ -161,7 +158,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| }; | ||
|
|
||
| // create the map | ||
| const thisMap = new mapkit.Map(mapRef.current!, mapOptions); | ||
| const thisMap = new mapkit.Map(mapContainerRef.current, mapOptions); | ||
| // set zoom and boundary limits | ||
| thisMap.setCameraZoomRangeAnimated( | ||
| new mapkit.CameraZoomRange(200, 3000), | ||
|
|
@@ -289,22 +286,23 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| // thisMap.element.removeEventListener('mousemove', _); | ||
| }; | ||
|
|
||
| setMap(thisMap); | ||
| mapRef.current = thisMap; | ||
| } | ||
|
|
||
| // Cleanup on component unmount | ||
| return () => { | ||
| if (map && map._hoverCleanup) { | ||
| map._hoverCleanup(); | ||
| if (mapRef.current && mapRef.current._hoverCleanup) { | ||
| mapRef.current._hoverCleanup(); | ||
| } | ||
| }; | ||
| }, [mapLoaded]); | ||
| }, [mapLoaded, setSelectedRoute]); | ||
|
|
||
| // add fixed details to the map | ||
| // includes routes and stops | ||
| useEffect(() => { | ||
| if (!map || !routeData) return; | ||
| if (!mapLoaded || !mapRef.current || !routeData) return; | ||
|
|
||
| const overlays: mapkit.Overlay[] = []; | ||
|
|
||
| // display stop overlays | ||
| for (const [route, thisRouteData] of Object.entries(routeData)) { | ||
|
|
@@ -337,7 +335,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
|
|
||
| function displayRouteOverlays(routeData: ShuttleRouteData) { | ||
| // display route overlays | ||
| for (const [_route, thisRouteData] of Object.entries(routeData)) { | ||
| for (const [_, thisRouteData] of Object.entries(routeData)) { | ||
| // for route (WEST, NORTH) | ||
| const routePolylines = thisRouteData.ROUTES?.map( | ||
| // for segment (STOP1 -> STOP2, STOP2 -> STOP3, ...) | ||
|
|
@@ -360,22 +358,25 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
|
|
||
| if (generateRoutes) { | ||
| // generate polylines for routes | ||
| const routeDataCopy = JSON.parse(JSON.stringify(routeData)); // deep copy to avoid mutating original | ||
| const routeDataCopy = JSON.parse(JSON.stringify(routeData)) as ShuttleRouteData; | ||
| generateRoutePolylines(routeDataCopy).then((updatedRouteData) => { | ||
| displayRouteOverlays(updatedRouteData); | ||
| map.addOverlays(overlays); | ||
| if (mapRef.current) { | ||
| mapRef.current.addOverlays(overlays); | ||
| } | ||
| }); | ||
| } else { | ||
| // use pre-generated polylines | ||
| displayRouteOverlays(routeData); | ||
| map.addOverlays(overlays); | ||
| mapRef.current.addOverlays(overlays); | ||
| } | ||
|
|
||
| }, [map, routeData]); | ||
| }, [routeData, generateRoutes, mapLoaded]); | ||
|
|
||
| // display vehicles on map | ||
| useEffect(() => { | ||
| if (!map || !vehicles) return; | ||
| if (!mapRef.current || !vehicles) return; | ||
| const map = mapRef.current; | ||
|
|
||
| Object.keys(vehicles).forEach((key) => { | ||
| const vehicle = vehicles[key]; | ||
|
|
@@ -391,7 +392,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| const routeKey = vehicle.route_name as keyof typeof routeData; | ||
| const info = routeData[routeKey] as { COLOR?: string }; | ||
| return info.COLOR ?? "#444444"; | ||
|
|
||
| })(); | ||
|
|
||
| // Render ShuttleIcon JSX to a static SVG string | ||
|
|
@@ -405,7 +406,7 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| existingAnnotation.subtitle = `${vehicle.speed_mph.toFixed(1)} mph`; | ||
|
|
||
| // Handle route status updates | ||
| // If shuttle does not have a route null | ||
| // If shuttle does not have a route null | ||
| if (vehicle.route_name === null) { | ||
| // shuttle off-route (exiting) | ||
| if (existingAnnotation.lockedRoute) { | ||
|
|
@@ -448,14 +449,14 @@ export default function MapKitMap({ routeData, vehicles, generateRoutes = false, | |
| delete vehicleOverlays.current[key]; | ||
| } | ||
| }); | ||
| }, [map, vehicles, routeData]); | ||
| }, [vehicles, routeData]); | ||
|
|
||
|
|
||
|
|
||
| return ( | ||
| <div | ||
| className={isFullscreen ? 'map-fullscreen' : 'map'} | ||
| ref={mapRef} | ||
| ref={mapContainerRef} | ||
| > | ||
| </div> | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.