Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
frontend: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Mar 24, 2024
1 parent ccd676a commit 4754bc8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 38 deletions.
29 changes: 13 additions & 16 deletions frontend/src/common/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { type FetchBaseQueryError } from "@reduxjs/toolkit/query";
* A generic query object that represents the state of a data fetch. Generally follows
* the RTK query result type shape.
*/
export type Query<T, E = string> = SuccessQuery<T> | LoadingQuery | ErrorQuery<E>;
export type Query<T, E = string> =
| SuccessQuery<T>
| LoadingQuery
| ErrorQuery<E>;

export interface SuccessQuery<T> {
data: T;
Expand Down Expand Up @@ -61,9 +64,7 @@ export function loading(): LoadingQuery {
/**
* Create an error query with a given error.
*/
export function error<E>(
error: E,
): ErrorQuery<E> {
export function error<E>(error: E): ErrorQuery<E> {
return {
data: undefined,
isSuccess: false,
Expand All @@ -85,7 +86,7 @@ export const wrapReduxQuery = <T>(
} else if (query.isError as boolean) {
const err = query.error;
if (isFetchBaseQueryError(err)) {
const errMsg = 'error' in err ? err.error : JSON.stringify(err.data)
const errMsg = "error" in err ? err.error : JSON.stringify(err.data);
return error(errMsg);
} else if (isErrorWithMessage(err)) {
return error(err.message);
Expand All @@ -100,24 +101,20 @@ export const wrapReduxQuery = <T>(
/**
* Type predicate to narrow an unknown error to `FetchBaseQueryError`
*/
function isFetchBaseQueryError(
error: unknown,
): error is FetchBaseQueryError {
return typeof error === 'object' && error != null && 'status' in error
function isFetchBaseQueryError(error: unknown): error is FetchBaseQueryError {
return typeof error === "object" && error != null && "status" in error;
}

/**
* Type predicate to narrow an unknown error to an object with a string 'message' property
*/
function isErrorWithMessage(
error: unknown,
): error is { message: string } {
function isErrorWithMessage(error: unknown): error is { message: string } {
return (
typeof error === 'object' &&
typeof error === "object" &&
error != null &&
'message' in error &&
typeof (error as Record<string, unknown>).message === 'string'
)
"message" in error &&
typeof (error as Record<string, unknown>).message === "string"
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/landing/LandingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const LandingScreen = ({

const styles = StyleSheet.create({
container: {
padding: 8,
paddingHorizontal: 8,
},
header: {
marginBottom: 8,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/landing/RouteItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const RouteItem = ({
const stop = mapQuery(closestStop, (closestStop) => closestStop.value);
const arrivalEstimate: Query<number | undefined> = useArrivalEstimateQuery(
stop,
route
route,
);

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/location/locationSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface Closest<T> {

/**
* Use the closest coordinate from a list of objects that are coordinates. Will return
* an error if the location is not available, or if there is no data given.
* an error if the location is not available, or if there is no data given.
*/
export const useClosest = <T extends Coordinate>(
of: T[],
Expand Down Expand Up @@ -113,7 +113,7 @@ export const useClosestQuery = <T extends Coordinate>(
}

return success(closest);
}
};

/**
* Use the distance of the coordinate-line object from the current location. Will return
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/features/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Map = ({ insets, onStopPressed }: MapProps): React.JSX.Element => {
const mapRef = useRef<MapView>(null);
const [followingLocation, setFollowingLocation] = useState<boolean>(true);
const [lastLocation, setLastLocation] = useState<Coordinate | undefined>(
undefined
undefined,
);

const focus = useMapFocus();
Expand Down Expand Up @@ -211,6 +211,9 @@ const Map = ({ insets, onStopPressed }: MapProps): React.JSX.Element => {
zIndex={0 + (isRouteVisible(route) ? 1 : 0)}
key={route.id}
coordinates={route.waypoints}
// strokeColor={
// isRouteVisible(route) ? route.color : route.color + "40"
// }
strokeColor={route.color}
strokeWidth={4}
lineCap="round"
Expand All @@ -226,6 +229,7 @@ const Map = ({ insets, onStopPressed }: MapProps): React.JSX.Element => {
}}
zIndex={2 + (isStopVisible(stop) ? 1 : 0)}
coordinate={stop}
// opacity={isStopVisible(stop) ? 1 : 0.25}
tracksViewChanges={false}
anchor={{ x: 0.5, y: 0.5 }}
>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/routes/RouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { useClosest } from "../location/locationSlice";
import { changeMapFocus, type MapFocus } from "../map/mapSlice";
import { type Stop } from "../stops/stopsSlice";

import { RouteStopItem, RouteStopItemSkeleton } from "./RouteStopItem";
import { useGetRouteQuery, type ParentRoute } from "./routesSlice";
import { RouteStopItem, RouteStopItemSkeleton } from "./RouteStopItem";

export interface RouteScreenProps {
navigation: StackNavigationProp<InnerParamList, "Route">;
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/features/vans/arrivalSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ type ArrivalsResponse = Record<StopId, Record<RouteId, Seconds>>;
type ArrivalResult = ArrivalSuccess | ArrivalsError;

interface ArrivalSuccess {
type: "arrivals",
arrivals: ArrivalsResponse,
type: "arrivals";
arrivals: ArrivalsResponse;
}

interface ArrivalsError {
type: "error",
error: string,
};
type: "error";
error: string;
}

const initialState: ArrivalsState = {
subscribers: {},
Expand Down Expand Up @@ -91,7 +91,7 @@ export const arrivalsSlice = createSlice({
for (const handle in state.subscribers) {
state.times[handle] = error(action.payload);
}
}
},
},
});

Expand Down
20 changes: 10 additions & 10 deletions frontend/src/features/vans/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ export interface VanLocation {

interface VanLocationMessage {
include: string[];
query: VanLocationQuery
query: VanLocationQuery;
}

interface VanLocationQuery {
type: "vans" | "van",
guid?: number,
alive?: boolean,
routeIds?: number[],
type: "vans" | "van";
guid?: number;
alive?: boolean;
routeIds?: number[];
}

type VanLocationResponse = VanLocationSuccess | VanLocationError;

interface VanLocationSuccess {
type: "vans",
vans: VanLocation[],
type: "vans";
vans: VanLocation[];
}

interface VanLocationError {
type: "error",
error: string,
};
type: "error";
error: string;
}

/**
* Manage a van location websocket and get the resulting van locations from it.
Expand Down

0 comments on commit 4754bc8

Please sign in to comment.