From cc1b552302e4d5386cfc1be2afc68fc9747a8ee0 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 09:37:10 +0900 Subject: [PATCH 1/5] =?UTF-8?q?JRW=E3=83=86=E3=83=BC=E3=83=9E=E3=81=A7?= =?UTF-8?q?=E3=80=8C=E3=81=BE=E3=82=82=E3=81=AA=E3=81=8F=E3=80=8D=E3=81=AE?= =?UTF-8?q?=E6=99=82=E3=81=AB=E7=9F=A2=E5=8D=B0=E3=81=8C=E5=87=BA=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LineBoardWest.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/LineBoardWest.tsx b/src/components/LineBoardWest.tsx index 906b23616..faee8764a 100644 --- a/src/components/LineBoardWest.tsx +++ b/src/components/LineBoardWest.tsx @@ -434,7 +434,7 @@ const StationNameCell: React.FC = ({ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { const { selectedLine } = useRecoilValue(lineState) - const { arrived } = useRecoilValue(stationState) + const { arrived, approaching } = useRecoilValue(stationState) const isPassing = useIsPassing() const currentLine = useCurrentLine() @@ -450,11 +450,11 @@ const LineBoardWest: React.FC = ({ stations, lineColors }: Props) => { key={s.groupId} station={s} stations={stations} - arrived={!isPassing && arrived} + arrived={!isPassing && !approaching && arrived} index={i} /> ), - [arrived, isPassing, stations] + [approaching, arrived, isPassing, stations] ) const emptyArray = useMemo( From 4ffa391a51ce324d38582d86d83fb0885354c6bb Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 09:55:34 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=88=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=80=E3=83=BC=E3=82=92=E4=BD=BF=E3=81=88=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSavedRoutes.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useSavedRoutes.ts b/src/hooks/useSavedRoutes.ts index a109daac9..3cacd2bec 100644 --- a/src/hooks/useSavedRoutes.ts +++ b/src/hooks/useSavedRoutes.ts @@ -32,9 +32,10 @@ export const useSavedRoutes = () => { req.ids = route.stations.map((sta) => sta.id) const res = await grpcClient.getStationByIdList(req, {}) const stations = res?.stations ?? [] - return stations.map((sta, idx) => ({ + return stations.map((sta) => ({ ...sta, - stopCondition: route.stations[idx].stopCondition, + stopCondition: route.stations.find((rs) => rs.id === sta.id) + ?.stopCondition, trainType: route.trainType, })) }, []) From 332652c82690c94c65124a249e661fbf64a3eef1 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 10:22:35 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=88=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=80=E3=83=BC=E3=83=87=E3=83=BC=E3=82=BF=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=AEswr=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSavedRoutes.ts | 73 +++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/hooks/useSavedRoutes.ts b/src/hooks/useSavedRoutes.ts index 3cacd2bec..526a0c9c3 100644 --- a/src/hooks/useSavedRoutes.ts +++ b/src/hooks/useSavedRoutes.ts @@ -1,5 +1,6 @@ import firestore from '@react-native-firebase/firestore' -import { useCallback, useEffect, useState } from 'react' +import useSWR from 'swr' +import useSWRMutation from 'swr/dist/mutation' import { GetStationByIdListRequest } from '../../gen/proto/stationapi_pb' import { grpcClient } from '../lib/grpc' import { SavedRoute } from '../models/SavedRoute' @@ -7,38 +8,48 @@ import useCachedInitAnonymousUser from './useCachedAnonymousUser' export const useSavedRoutes = () => { useCachedInitAnonymousUser() - const [routes, setRoutes] = useState([]) - const [loading, setLoading] = useState(false) - useEffect(() => { - const fetchRoutesAsync = async () => { - setLoading(true) - const routesSnapshot = await firestore() - .collection('uploadedCommunityRoutes') - .orderBy('createdAt', 'desc') - .get() - const routes = routesSnapshot.docs.map((doc) => ({ - id: doc.id, - ...doc.data(), + const { + data: routes, + isLoading: isRoutesLoading, + error: fetchRoutesError, + } = useSWR('/firestore/uploadedCommunityRoutes', async () => { + const routesSnapshot = await firestore() + .collection('uploadedCommunityRoutes') + .orderBy('createdAt', 'desc') + .get() + + return routesSnapshot.docs.map((doc) => ({ + id: doc.id, + ...doc.data(), + })) as SavedRoute[] + }) + + const { + isMutating: isStationsLoading, + error: fetchStationsError, + trigger: fetchStationsByRoute, + } = useSWRMutation( + '/app.trainlcd.grpc/GetStationByIdListRequest', + async (_, { arg: route }: { arg: SavedRoute }) => { + const req = new GetStationByIdListRequest() + req.ids = route.stations.map((sta) => sta.id) + const res = await grpcClient.getStationByIdList(req, {}) + const stations = res?.stations ?? [] + + return stations.map((sta) => ({ + ...sta, + stopCondition: route.stations.find((rs) => rs.id === sta.id) + ?.stopCondition, + trainType: route.trainType, })) - setRoutes(routes as SavedRoute[]) - setLoading(false) } - fetchRoutesAsync() - }, []) - - const fetchStationsByRoute = useCallback(async (route: SavedRoute) => { - const req = new GetStationByIdListRequest() - req.ids = route.stations.map((sta) => sta.id) - const res = await grpcClient.getStationByIdList(req, {}) - const stations = res?.stations ?? [] - return stations.map((sta) => ({ - ...sta, - stopCondition: route.stations.find((rs) => rs.id === sta.id) - ?.stopCondition, - trainType: route.trainType, - })) - }, []) + ) - return { routes, loading, fetchStationsByRoute } + return { + routes, + loading: isRoutesLoading || isStationsLoading, + error: fetchRoutesError || fetchStationsError, + fetchStationsByRoute, + } } From 6584212dec1976c1b6ac3a99d01202a86bc6045b Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 23:25:23 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E7=B2=BE=E5=BA=A6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 28cddc2f2..3aa926593 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -16,7 +16,11 @@ export const useStartBackgroundLocationUpdates = () => { !(await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME)) ) { Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { - accuracy: Location.Accuracy.High, + // NOTE: BestForNavigationにしたら暴走時のCPU使用率が50%ほど低下した + accuracy: Location.Accuracy.BestForNavigation, + // NOTE: マップマッチが勝手に行われると電車での経路と大きく異なることがあるはずなので + // OtherNavigationは必須 + activityType: Location.ActivityType.OtherNavigation, distanceInterval: 250, foregroundService: { notificationTitle: translate('bgAlertTitle'), From 0eab70be9063d36cc6c1aff76fa56a67ce8173ae Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Fri, 16 Aug 2024 23:29:21 +0900 Subject: [PATCH 5/5] =?UTF-8?q?distanceInterval:=20100=E3=81=AB=E6=88=BB?= =?UTF-8?q?=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useStartBackgroundLocationUpdates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useStartBackgroundLocationUpdates.ts b/src/hooks/useStartBackgroundLocationUpdates.ts index 3aa926593..6738f7364 100644 --- a/src/hooks/useStartBackgroundLocationUpdates.ts +++ b/src/hooks/useStartBackgroundLocationUpdates.ts @@ -21,7 +21,7 @@ export const useStartBackgroundLocationUpdates = () => { // NOTE: マップマッチが勝手に行われると電車での経路と大きく異なることがあるはずなので // OtherNavigationは必須 activityType: Location.ActivityType.OtherNavigation, - distanceInterval: 250, + distanceInterval: 100, foregroundService: { notificationTitle: translate('bgAlertTitle'), notificationBody: translate('bgAlertContent'),