Skip to content

Commit

Permalink
Merge pull request #3706 from TrainLCD/dev
Browse files Browse the repository at this point in the history
v7.7.2追加対応
  • Loading branch information
TinyKitten authored Aug 16, 2024
2 parents 4172248 + 8fb397b commit a16d0c8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/components/LineBoardWest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const StationNameCell: React.FC<StationNameCellProps> = ({

const LineBoardWest: React.FC<Props> = ({ stations, lineColors }: Props) => {
const { selectedLine } = useRecoilValue(lineState)
const { arrived } = useRecoilValue(stationState)
const { arrived, approaching } = useRecoilValue(stationState)

const isPassing = useIsPassing()
const currentLine = useCurrentLine()
Expand All @@ -450,11 +450,11 @@ const LineBoardWest: React.FC<Props> = ({ 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(
Expand Down
72 changes: 42 additions & 30 deletions src/hooks/useSavedRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
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'
import useCachedInitAnonymousUser from './useCachedAnonymousUser'

export const useSavedRoutes = () => {
useCachedInitAnonymousUser()
const [routes, setRoutes] = useState<SavedRoute[]>([])
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<SavedRoute[]>('/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, idx) => ({
...sta,
stopCondition: route.stations[idx].stopCondition,
trainType: route.trainType,
}))
}, [])
)

return { routes, loading, fetchStationsByRoute }
return {
routes,
loading: isRoutesLoading || isStationsLoading,
error: fetchRoutesError || fetchStationsError,
fetchStationsByRoute,
}
}
8 changes: 6 additions & 2 deletions src/hooks/useStartBackgroundLocationUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ export const useStartBackgroundLocationUpdates = () => {
!(await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME))
) {
Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.High,
distanceInterval: 250,
// NOTE: BestForNavigationにしたら暴走時のCPU使用率が50%ほど低下した
accuracy: Location.Accuracy.BestForNavigation,
// NOTE: マップマッチが勝手に行われると電車での経路と大きく異なることがあるはずなので
// OtherNavigationは必須
activityType: Location.ActivityType.OtherNavigation,
distanceInterval: 100,
foregroundService: {
notificationTitle: translate('bgAlertTitle'),
notificationBody: translate('bgAlertContent'),
Expand Down

0 comments on commit a16d0c8

Please sign in to comment.