Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Jun 4, 2024
2 parents 1edfa6e + da11a28 commit 0a5d17e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
"import/order": "error",
"import/newline-after-import": "error",
"import/no-unused-modules": ["warn", { unusedExports: true }],
"@typescript-eslint/no-explicit-any": "warn",
"import/no-useless-path-segments": [
"error",
{
Expand Down
12 changes: 7 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { MapContainer, TileLayer } from "react-leaflet";
import "./App.css";
import polyline from "@mapbox/polyline";
Expand All @@ -22,13 +22,14 @@ function App() {
const { data: shapeData } = useShapeData(tripData);
const { data: routeData } = useRouteData(busData);
const { data: stopData } = useStopData(busData);
const [zoom, setZoom] = useState(14);

const { status, routeId, stopName } = getInfo(busData, routeData, stopData);

const formattedPolyline = useMemo(() => {
if (shapeData?.data) {
const decodedPolyline = polyline.decode(
shapeData.data.attributes.polyline
shapeData.data.attributes.polyline,
);
const totalLength = decodedPolyline.length;

Expand All @@ -55,28 +56,29 @@ function App() {
busData?.data.attributes.latitude,
busData?.data.attributes.longitude,
busStatus,
]
],
);

return (
<>
<Title />
<div className="flex h-screen flex-col bg-stone-100">
<MapContainer
zoom={14}
zoom={zoom}
center={center}
scrollWheelZoom={false}
style={{ height: "100%", width: "100%" }}
dragging={true}
>
<ChangeView center={center} zoom={14} />
<ChangeView center={center} zoom={zoom} />
<Element name="center">
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{busStatus === "success" && busData.data && (
<MapLayers
setZoom={setZoom}
formattedPolyline={formattedPolyline}
position={[
busData?.data.attributes.latitude,
Expand Down
13 changes: 11 additions & 2 deletions src/MapLayers.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { LatLngTuple } from "leaflet";
import { useEffect } from "react";
import { useMap } from "react-leaflet";
import { useMap, useMapEvent } from "react-leaflet";
import { Hotline } from "react-leaflet-hotline";
import { MarkerLayer, Marker } from "react-leaflet-marker";

interface MapLayersProps {
formattedPolyline: [{ lat: string; lng: string; value: number }];
position: LatLngTuple;
setZoom: (zoom: number) => void;
}

export const MapLayers = ({ formattedPolyline, position }: MapLayersProps) => {
export const MapLayers = ({
formattedPolyline,
position,
setZoom,
}: MapLayersProps) => {
const map = useMap();

useMapEvent("zoom", (event) => {
setZoom(event.target.getZoom());
});

useEffect(() => {
// Create a custom pane with a high zIndex
const pane = map.createPane("markerPane");
Expand Down
10 changes: 5 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useDataQuery = (
key: string,
id: string | undefined,
endpoint: string,
enabled: boolean = true
enabled: boolean = true,
) =>
useQuery({
queryKey: [key, id],
Expand All @@ -37,29 +37,29 @@ export const useTripData = (busData: any) =>
"trips",
busData?.data?.relationships?.trip?.data?.id,
"trip",
!!busData?.data
!!busData?.data,
);

export const useRouteData = (busData: any) =>
useDataQuery(
"route",
busData?.data?.relationships?.route?.data?.id,
"route",
!!busData?.data
!!busData?.data,
);

export const useStopData = (busData: any) =>
useDataQuery(
"stop",
busData?.data?.relationships?.stop?.data?.id,
"stop",
!!busData?.data
!!busData?.data,
);

export const useShapeData = (tripData: any) =>
useDataQuery(
"shapes",
tripData?.data?.relationships?.shape?.data?.id,
"shape",
!!tripData?.data
!!tripData?.data,
);
2 changes: 1 addition & 1 deletion src/components/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Link } from "react-scroll";

export const Title = () => {
return (
<div className=" flex h-screen w-full flex-col items-center justify-center gap-4 bg-stone-100 bg-gradient">
<div className="flex h-screen w-full flex-col items-center justify-center gap-4 bg-stone-100 bg-gradient p-4">
<h1 className="text-center text-3xl font-bold uppercase italic text-grey-100 sm:text-5xl lg:text-6xl">
Mbta <span className="gradient-text drop-shadow-2xl">pride</span> bus
tracker
Expand Down

0 comments on commit 0a5d17e

Please sign in to comment.