Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
root: true,
extends: ['@react-native-community', 'prettier'],
extends: ['@react-native-community'],
rules: {
'prettier/prettier': 'error',
'prettier/prettier': 0,
'no-shadow': [
'error',
{ builtinGlobals: true, hoist: 'functions', allow: ['tripId'] },
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@reduxjs/toolkit": "^1.6.2",
"@turf/turf": "^6.5.0",
"graphql": "^16.0.1",
"lodash": "^4.17.21",
"react": "17.0.2",
"react-native": "0.66.3",
"react-native-dotenv": "^3.3.0",
Expand All @@ -30,6 +31,7 @@
"@expo/config-plugins": "^4.0.11",
"@react-native-community/eslint-config": "^2.0.0",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.178",
"@types/react-native": "^0.66.4",
"@types/react-native-dotenv": "^0.2.0",
"@types/react-redux": "^7.1.20",
Expand Down
9 changes: 7 additions & 2 deletions src/apollo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const authMiddleware = new ApolloLink((operation, forward) => {
'x-api-key': GTFS_API_GATEWAY_KEY,
},
}));
return forward(operation);
return forward(operation).map(result => {
// console.info(operation.getContext().response);
return result;
});
});

const client = new ApolloClient({
Expand All @@ -27,7 +30,9 @@ const client = new ApolloClient({
},
Stop: {
keyFields: Stop =>
`${Stop.__typename}:${Stop.feedIndex}:${Stop.stopId}`,
`${Stop.__typename}:${Stop.feedIndex}:${
Stop.parentStation || Stop.stopId
}`,
},
Trip: {
keyFields: Trip =>
Expand Down
6 changes: 1 addition & 5 deletions src/apollo/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const STOP_FIELDS = gql`
feedIndex
stopId
stopName
parentStation
geom {
coordinates
}
Expand Down Expand Up @@ -44,10 +43,7 @@ export const TRIP_FIELDS = gql`
stop {
feedIndex
stopId
stopName
geom {
coordinates
}
parentStation
}
}
}
Expand Down
25 changes: 23 additions & 2 deletions src/apollo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,38 @@ export const GET_FEEDS = gql`
}
`;

export const GET_STATIONS = gql`
${STOP_FIELDS}
query GetStations($feedIndex: Int!, $stationIds: [String!]) {
stations(feedIndex: $feedIndex, stationIds: $stationIds) {
...StopFields
}
}
`;

export const GET_STOPS_BY_LOCATION = gql`
${STOP_FIELDS}
query GetStopsByLocation($latitude: Float!, $longitude: Float!, $radius: Float!) {
stopsByLocation(
location: [$latitude, $longitude]
radius: $radius
) {
...StopFields
}
}
`;

export const GET_TRIPS = gql`
${TRIP_FIELDS}
${STOP_FIELDS}
query GetNextTrips($feedIndex: Int!, $routeId: String!) {
nextTrips(feedIndex: $feedIndex, routeId: $routeId) {
...TripFields
stopTimes {
stopSequence
departure
stop {
...StopFields
stopId
parentStation
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ErrorView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { FC } from 'react';
import { StyleProp, Text, View } from 'react-native';

type Props = {
interface Props {
message?: string;
styles?: StyleProp<any>;
};
}

const ErrorView: FC<Props> = ({ message, styles = {} }) => {
return (
Expand All @@ -16,4 +16,4 @@ const ErrorView: FC<Props> = ({ message, styles = {} }) => {
);
};

export default ErrorView;
export default React.memo(ErrorView);
6 changes: 3 additions & 3 deletions src/components/LoadingView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { FC } from 'react';
import { StyleProp, Text, View } from 'react-native';

type Props = {
interface Props {
message?: string;
styles?: StyleProp<any>;
};
}

const LoadingView: FC<Props> = ({ message, styles = {} }) => {
return (
Expand All @@ -14,4 +14,4 @@ const LoadingView: FC<Props> = ({ message, styles = {} }) => {
);
};

export default LoadingView;
export default React.memo(LoadingView);
8 changes: 4 additions & 4 deletions src/components/MapView.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, { FC } from 'react';
import React, { FC, ReactNode } from 'react';
import { GestureResponderEvent, StyleSheet } from 'react-native';
import MapboxGL, { RegionPayload } from '@react-native-mapbox-gl/maps';
import { Feature, Point, Position } from '@turf/turf';
import { MAPBOX_ACCESS_TOKEN, MAPBOX_STYLE_URL } from '@env';

type Props = {
interface Props {
centerCoordinate: Position;
zoomLevel: number;
pitch: number;
children: any;
children: ReactNode;
onRegionWillChange?: (feature: Feature<Point, RegionPayload>) => void;
onRegionDidChange?: (feature: Feature<Point, RegionPayload>) => void;
onTouchStart?: (e: GestureResponderEvent) => void;
onTouchEnd?: (e: GestureResponderEvent) => void;
onLongPress?: (
feature: Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>,
) => void;
};
}

MapboxGL.setAccessToken(MAPBOX_ACCESS_TOKEN);

Expand Down
18 changes: 12 additions & 6 deletions src/components/StopMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ import { SvgProps } from 'react-native-svg';
import { Position } from '@turf/turf';
import Pin from 'assets/pin.svg';

type Props = {
interface Props {
feedIndex: number;
stopId: string;
coordinates: Position;
};
svgProps?: SvgProps;
}

const svgProps: SvgProps = {
const svgDefaultProps: SvgProps = {
width: 50,
height: 50,
fill: '#cc0000',
};

const StopMarker: FC<Props> = ({ feedIndex, stopId, coordinates }) => (
const StopMarker: FC<Props> = ({
feedIndex,
stopId,
coordinates,
svgProps = {},
}) => (
<MapboxGL.MarkerView
id={`marker-${feedIndex}:${stopId}`}
coordinate={coordinates}
anchor={{ x: 0.5, y: 1.0 }}>
<Pin nativeID={stopId} {...svgProps} />
<Pin nativeID={stopId} {...svgDefaultProps} {...svgProps} />
</MapboxGL.MarkerView>
);

export default StopMarker;
export default React.memo(StopMarker);
10 changes: 5 additions & 5 deletions src/components/StopShape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import MapboxGL, { CircleLayerStyle } from '@react-native-mapbox-gl/maps';
import { point, Position } from '@turf/turf';
import { StopTimeCallback } from './StopTimeButton';

type Props = {
interface Props {
feedIndex: number;
tripId: string;
stopId: string;
coordinates: Position;
color?: string;
isActive?: boolean;
aboveLayerId: string;
aboveLayerId?: string;
onPress: StopTimeCallback;
};
}

const getCircleStyles = (
color: string,
isActive: boolean,
): CircleLayerStyle => ({
circleRadius: isActive ? 16 : 6,
circleColor: `#${isActive ? 'ddd' : color || 'ddd'}`,
circleStrokeColor: `#ddd`,
circleStrokeColor: '#ddd',
circleStrokeWidth: 2,
circlePitchScale: 'map',
circlePitchAlignment: 'map',
Expand Down Expand Up @@ -61,4 +61,4 @@ const StopShape: FC<Props> = ({
);
};

export default StopShape;
export default React.memo(StopShape);
6 changes: 3 additions & 3 deletions src/components/StopTimeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IStopTimeStyles {
departure?: StyleProp<TextStyle>;
}

type Props = {
interface Props {
feedIndex: number;
tripId: string;
stopId: string;
Expand All @@ -29,7 +29,7 @@ type Props = {
labelStyles?: StyleProp<TextStyle>;
departureStyles?: StyleProp<TextStyle>;
onPress: StopTimeCallback;
};
}

const StopTimeButton: FC<Props> = ({
feedIndex,
Expand All @@ -52,4 +52,4 @@ const StopTimeButton: FC<Props> = ({
);
};

export default StopTimeButton;
export default React.memo(StopTimeButton);
15 changes: 9 additions & 6 deletions src/components/TripList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import StopTimeButton, {
} from 'components/StopTimeButton';
import { IStopTime } from 'interfaces';

type Props = {
interface Props {
tripId: string;
stopTimes: IStopTime[];
styles?: IStopTimeStyles;
onPress: StopTimeCallback;
};
}

const getRenderItem = (
tripId: string,
Expand All @@ -20,12 +20,12 @@ const getRenderItem = (
onPress: StopTimeCallback,
) => {
const { stop, departure } = stopTime;
const { feedIndex, stopId, stopName } = stop;
const { feedIndex, stopId, parentStation, stopName } = stop;
return (
<StopTimeButton
feedIndex={feedIndex}
tripId={tripId}
stopId={stopId}
stopId={parentStation || stopId}
stopName={stopName}
departure={departure}
buttonStyles={styles.button}
Expand All @@ -43,9 +43,12 @@ const TripList: FC<Props> = ({ tripId, stopTimes, styles = {}, onPress }) => {
renderItem={({ item }: ListRenderItemInfo<IStopTime>) =>
getRenderItem(tripId, item, styles, onPress)
}
keyExtractor={(stopTime: IStopTime) => stopTime.stop.stopId}
keyExtractor={(stopTime: IStopTime) => {
const { feedIndex, stopId, parentStation } = stopTime.stop;
return `${feedIndex}:${parentStation || stopId}`;
}}
/>
);
};

export default TripList;
export default React.memo(TripList);
6 changes: 3 additions & 3 deletions src/components/TripShape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import MapboxGL, { LineLayerStyle } from '@react-native-mapbox-gl/maps';
import { lineString, Position } from '@turf/turf';
import React, { FC } from 'react';

type Props = {
interface Props {
shapeSourceId: string;
layerId: string;
color?: string;
coordinates?: Position[];
};
}

const getLineStyles = (color?: string): LineLayerStyle => ({
lineColor: `#${color ? color : 'ddd'}`,
Expand All @@ -30,4 +30,4 @@ const TripShape: FC<Props> = ({
);
};

export default TripShape;
export default React.memo(TripShape);
2 changes: 1 addition & 1 deletion src/navigation/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const withProviders =
store: any,
client: any,
): FC<P & Props> =>
(props: P & Props): ReactElement =>
(props: P & Props): ReactElement =>
(
<NavigationProvider value={{ componentId: props.componentId }}>
<Provider store={store}>
Expand Down
6 changes: 2 additions & 4 deletions src/screens/dashboard/DashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import styles from './styles';

const DashboardScreen: FC = () => {
const { push } = useNavigation();

const { loading, error, data } = useQuery<{ feeds: IFeed[] }>(GET_FEEDS);

if (loading) <LoadingView message="Loading feeds" />;
if (error) <ErrorView message={error.message} />;

const { feeds } = data || {};

const renderItem = ({ item }: ListRenderItemInfo<IFeed>) => (
Expand All @@ -40,6 +36,8 @@ const DashboardScreen: FC = () => {
<View style={styles.root}>
<View style={styles.heading}>
<Text style={styles.header}>Dashboard</Text>
{loading && <LoadingView message="Loading feeds" />}
{error && <ErrorView message={error.message} />}
</View>
<FlatList
data={feeds}
Expand Down
Loading