-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(StopPageRedesign): get route patterns
use the router route's `loader` function to fetch the stop's route patterns
- Loading branch information
1 parent
c4c5aff
commit 5feb644
Showing
16 changed files
with
791 additions
and
836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import useSWR from "swr"; | ||
import { sortBy } from "lodash"; | ||
import { fetchJsonOrThrow } from "../helpers/fetch-json"; | ||
import { Route } from "../__v3api"; | ||
import { Polyline } from "../leaflet/components/__mapdata"; | ||
import { FetchState, FetchStatus } from "../helpers/use-fetch"; | ||
|
||
export type RouteWithPolylines = Route & { polylines: Polyline[] }; | ||
|
||
const fetchData = async (url: string): Promise<RouteWithPolylines[]> => | ||
const fetchData = async (url: string): Promise<Route[]> => | ||
fetchJsonOrThrow(url); | ||
|
||
const useRoutesByStop = (stopId: string): FetchState<RouteWithPolylines[]> => { | ||
const { data, error } = useSWR<RouteWithPolylines[]>( | ||
`/api/routes/by-stop/${stopId}`, | ||
const useRoutes = (routeIds: string[]): FetchState<Route[]> => { | ||
const { data, error } = useSWR<Route[]>( | ||
routeIds.length ? `/api/routes/${routeIds.join(",")}` : null, | ||
fetchData | ||
); | ||
if (error) { | ||
return { status: FetchStatus.Error }; | ||
} | ||
return { status: FetchStatus.Data, data }; | ||
const sortedRoutes = data ? sortBy(data, ["sort_order"]) : data; | ||
return { status: FetchStatus.Data, data: sortedRoutes }; | ||
}; | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { useRoutesByStop }; | ||
export { useRoutes }; |
Oops, something went wrong.