diff --git a/.eslintrc.js b/.eslintrc.js index f6f0ace..c0b6c84 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,10 @@ module.exports = { extends: ['@react-native-community', 'prettier'], rules: { 'prettier/prettier': 'error', + 'no-shadow': [ + 'error', + { builtinGlobals: true, hoist: 'functions', allow: ['tripId'] }, + ], }, plugins: ['prettier'], }; diff --git a/README.md b/README.md index d135aea..ed9834e 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,11 @@ npx react-native run-ios Read more about the frameworks and libraries this app utilizes at the links below: - [React-Native](https://reactnative.dev/) -- [React Native Navigation](https://wix.github.io/react-native-navigation/docs/before-you-start/) -- [React Native Navigation Hooks](https://underscopeio.github.io/react-native-navigation-hooks/docs/before-you-start/) -- [TypeScript](https://www.typescriptlang.org/) +- [React Native Navigation](https://wix.github.io/react-native-navigation/) +- [React Native Navigation Hooks](https://underscopeio.github.io/react-native-navigation-hooks/) +- [React Native MapboxGL](https://github.com/react-native-mapbox-gl/) - [MapBox](https://www.mapbox.com/) +- [TypeScript](https://www.typescriptlang.org/) - [ApolloClient](https://www.apollographql.com/docs/react/) - [Redux Toolkit](https://redux-toolkit.js.org/) - [Turfjs](https://github.com/Turfjs/turf) diff --git a/src/components/Error.tsx b/src/components/ErrorView.tsx similarity index 78% rename from src/components/Error.tsx rename to src/components/ErrorView.tsx index 6908657..d895393 100644 --- a/src/components/Error.tsx +++ b/src/components/ErrorView.tsx @@ -6,7 +6,7 @@ type Props = { styles?: StyleProp; }; -const Error: FC = ({ message, styles = {} }) => { +const ErrorView: FC = ({ message, styles = {} }) => { return ( @@ -16,4 +16,4 @@ const Error: FC = ({ message, styles = {} }) => { ); }; -export default Error; +export default ErrorView; diff --git a/src/components/Loading.tsx b/src/components/LoadingView.tsx similarity index 74% rename from src/components/Loading.tsx rename to src/components/LoadingView.tsx index d69ad80..b0628b3 100644 --- a/src/components/Loading.tsx +++ b/src/components/LoadingView.tsx @@ -6,7 +6,7 @@ type Props = { styles?: StyleProp; }; -const Loading: FC = ({ message, styles = {} }) => { +const LoadingView: FC = ({ message, styles = {} }) => { return ( {message || 'Loading...'} @@ -14,4 +14,4 @@ const Loading: FC = ({ message, styles = {} }) => { ); }; -export default Loading; +export default LoadingView; diff --git a/src/components/Map.tsx b/src/components/MapView.tsx similarity index 96% rename from src/components/Map.tsx rename to src/components/MapView.tsx index f1d956c..bbb62eb 100644 --- a/src/components/Map.tsx +++ b/src/components/MapView.tsx @@ -27,7 +27,7 @@ const styles = StyleSheet.create({ }, }); -const Map: FC = ({ +const MapView: FC = ({ centerCoordinate, zoomLevel, pitch, @@ -62,4 +62,4 @@ const Map: FC = ({ ); }; -export default Map; +export default MapView; diff --git a/src/components/Stop.tsx b/src/components/StopShape.tsx similarity index 92% rename from src/components/Stop.tsx rename to src/components/StopShape.tsx index be1845d..f165792 100644 --- a/src/components/Stop.tsx +++ b/src/components/StopShape.tsx @@ -1,7 +1,7 @@ import React, { FC } from 'react'; import MapboxGL, { CircleLayerStyle } from '@react-native-mapbox-gl/maps'; import { point, Position } from '@turf/turf'; -import { StopTimeCallback } from './StopTime'; +import { StopTimeCallback } from './StopTimeButton'; type Props = { feedIndex: number; @@ -34,7 +34,7 @@ const getCircleStyles = ( }, }); -const Stop: FC = ({ +const StopShape: FC = ({ feedIndex, tripId, stopId, @@ -61,4 +61,4 @@ const Stop: FC = ({ ); }; -export default Stop; +export default StopShape; diff --git a/src/components/StopTime.tsx b/src/components/StopTimeButton.tsx similarity index 93% rename from src/components/StopTime.tsx rename to src/components/StopTimeButton.tsx index 03128b2..cb378ee 100644 --- a/src/components/StopTime.tsx +++ b/src/components/StopTimeButton.tsx @@ -31,7 +31,7 @@ type Props = { onPress: StopTimeCallback; }; -const StopTime: FC = ({ +const StopTimeButton: FC = ({ feedIndex, tripId, stopId, @@ -52,4 +52,4 @@ const StopTime: FC = ({ ); }; -export default StopTime; +export default StopTimeButton; diff --git a/src/components/Trip.tsx b/src/components/TripList.tsx similarity index 85% rename from src/components/Trip.tsx rename to src/components/TripList.tsx index ea613a2..4779032 100644 --- a/src/components/Trip.tsx +++ b/src/components/TripList.tsx @@ -1,9 +1,9 @@ import React, { FC } from 'react'; import { FlatList, ListRenderItemInfo } from 'react-native'; -import StopTime, { +import StopTimeButton, { IStopTimeStyles, StopTimeCallback, -} from 'components/StopTime'; +} from 'components/StopTimeButton'; import { IStopTime } from 'interfaces'; type Props = { @@ -22,7 +22,7 @@ const getRenderItem = ( const { stop, departure } = stopTime; const { feedIndex, stopId, stopName } = stop; return ( - = ({ tripId, stopTimes, styles = {}, onPress }) => { +const TripList: FC = ({ tripId, stopTimes, styles = {}, onPress }) => { return ( = ({ tripId, stopTimes, styles = {}, onPress }) => { ); }; -export default Trip; +export default TripList; diff --git a/src/screens/dashboard/DashboardScreen.tsx b/src/screens/dashboard/DashboardScreen.tsx index 785b5bd..b45e4db 100644 --- a/src/screens/dashboard/DashboardScreen.tsx +++ b/src/screens/dashboard/DashboardScreen.tsx @@ -9,8 +9,8 @@ import { import { useNavigation } from 'react-native-navigation-hooks'; import { useQuery } from '@apollo/client'; import { GET_FEEDS } from 'apollo/queries'; -import Loading from 'components/Loading'; -import Error from 'components/Error'; +import LoadingView from 'components/LoadingView'; +import ErrorView from 'components/ErrorView'; import { Screens } from 'navigation/screens'; import { IFeed } from 'interfaces'; import config from 'config'; @@ -21,8 +21,8 @@ const DashboardScreen: FC = () => { const { loading, error, data } = useQuery<{ feeds: IFeed[] }>(GET_FEEDS); - if (loading) ; - if (error) ; + if (loading) ; + if (error) ; const { feeds } = data || {}; diff --git a/src/screens/map/MapScreen.tsx b/src/screens/map/MapScreen.tsx index be6fda4..c38dc1f 100644 --- a/src/screens/map/MapScreen.tsx +++ b/src/screens/map/MapScreen.tsx @@ -6,15 +6,16 @@ import { RegionPayload } from '@react-native-mapbox-gl/maps'; import { Navigation } from 'react-native-navigation'; import { NavigationContext } from 'react-native-navigation-hooks'; import { useAppDispatch, useAppSelector } from 'store/hooks'; -import Map from 'components/Map'; +import MapView from 'components/MapView'; import TripShape from 'components/TripShape'; -import Stop from 'components/Stop'; +import StopShape from 'components/StopShape'; import StopMarker from 'components/StopMarker'; -import { StopTimeCallback } from 'components/StopTime'; +import { StopTimeCallback } from 'components/StopTimeButton'; import { setActiveStop } from 'slices/stops'; import { GET_SHAPE } from 'apollo/queries'; import { ROUTE_FIELDS, STOP_FIELDS, TRIP_FIELDS } from 'apollo/fragments'; import { IRoute, IShape, IStop, IStopTime, ITrip } from 'interfaces'; +// import { getRadiusByZoomLat } from 'util/'; import styles from './styles'; const DEFAULT_COORD: Position = [-73.94594865587045, 40.7227534777328]; @@ -31,7 +32,7 @@ const MapScreen: FC = () => { const client = useApolloClient(); const { componentId = '' } = useContext(NavigationContext); - const [isMarkerVisible, setMarkerVisible] = useState(true); + const [isMarkerVisible, setMarkerVisible] = useState(false); const [cameraState, setCameraState] = useState({ zoomLevel: DEFAULT_ZOOM, centerCoordinate: DEFAULT_COORD, @@ -87,6 +88,19 @@ const MapScreen: FC = () => { })); }, [componentId, stop]); + // useEffect(() => { + // const radius = getRadiusByZoomLat( + // cameraState.zoomLevel, + // cameraState.centerCoordinate[0], + // ); + + // console.log({ + // location: cameraState.centerCoordinate, + // radius, + // pitch: cameraState.pitch, + // }); + // }, [cameraState]); + const onStopPress = useCallback( ({ stopId, tripId, feedIndex }) => { setMarkerVisible(false); @@ -108,10 +122,11 @@ const MapScreen: FC = () => { const onRegionDidChange = useCallback( (feature: Feature) => { setMarkerVisible(true); - setCameraState(state => ({ - ...state, + setCameraState({ + centerCoordinate: feature.geometry.coordinates, pitch: feature.properties.pitch, - })); + zoomLevel: feature.properties.zoomLevel, + }); }, [], ); @@ -135,7 +150,7 @@ const MapScreen: FC = () => { return ( - { )} {trip?.stopTimes && trip?.stopTimes.map((st: IStopTime) => ( - { onPress={onStopPress} /> ))} - + ); diff --git a/src/screens/routes/RoutesScreen.tsx b/src/screens/routes/RoutesScreen.tsx index 5265a39..39eede4 100644 --- a/src/screens/routes/RoutesScreen.tsx +++ b/src/screens/routes/RoutesScreen.tsx @@ -15,8 +15,8 @@ import { gql, useApolloClient, useQuery } from '@apollo/client'; import { GET_ROUTES } from 'apollo/queries'; import { FEED_FIELDS } from 'apollo/fragments'; import { Screens } from 'navigation/screens'; -import Error from 'components/Error'; -import Loading from 'components/Loading'; +import ErrorView from 'components/ErrorView'; +import LoadingView from 'components/LoadingView'; import { IFeed, IRoute } from 'interfaces'; import styles from './styles'; @@ -80,8 +80,8 @@ const RoutesScreen: FC = ({ feedIndex }) => { ); - if (loading) return ; - if (error) return ; + if (loading) return ; + if (error) return ; return ( diff --git a/src/screens/trip/TripScreen.tsx b/src/screens/trip/TripScreen.tsx index 9759e35..ea20bc9 100644 --- a/src/screens/trip/TripScreen.tsx +++ b/src/screens/trip/TripScreen.tsx @@ -5,8 +5,8 @@ import { Navigation } from 'react-native-navigation'; import { NavigationContext } from 'react-native-navigation-hooks'; import { useAppDispatch } from 'store'; import { setActiveStop } from 'slices/stops'; -import Trip from 'components/Trip'; -import { StopTimeCallback } from 'components/StopTime'; +import TripList from 'components/TripList'; +import { StopTimeCallback } from 'components/StopTimeButton'; import { TRIP_FIELDS } from 'apollo/fragments'; import { IRoute, ITrip } from 'interfaces'; import styles from './styles'; @@ -41,7 +41,6 @@ const TripScreen: FC = ({ tripId, route }) => { }, [componentId, trip]); const goToStop = useCallback( - // eslint-disable-next-line no-shadow ({ stopId, tripId, feedIndex }) => { dispatch( setActiveStop({ @@ -71,7 +70,7 @@ const TripScreen: FC = ({ tripId, route }) => { {trip.tripHeadsign} -{trip.directionId ? 'Inbound' : 'Outbound'} - = ({ route }) => { Available Trips - {loading && } + {loading && } {!loading && !data && No upcoming trips could be found} - {error && } + {error && } {data && ( ) => { state.activeStop = action.payload; }, + setTransfers: (state, action: PayloadAction) => { + const { stopId, transfers } = action.payload; + + if (!(stopId in state.transfers)) { + state.transfers[stopId] = transfers; + } + }, }, }); diff --git a/src/util/index.ts b/src/util/index.ts new file mode 100644 index 0000000..f469535 --- /dev/null +++ b/src/util/index.ts @@ -0,0 +1,10 @@ +/** + * Calculate radius within which to fetch stops + * @param zoom + * @param lat + * @returns {number} + */ +export const getRadiusByZoomLat = (zoom: number, lat: number): number => { + const CIRCUMFERENCE = 40075016.686; + return (CIRCUMFERENCE * Math.cos(lat)) / 2 ** zoom / 100000; +}; diff --git a/src/util/package.json b/src/util/package.json new file mode 100644 index 0000000..e43ca57 --- /dev/null +++ b/src/util/package.json @@ -0,0 +1,3 @@ +{ + "name": "util" +} \ No newline at end of file