Compare commits

..

No commits in common. "76643fcc624219bd48f31f81f73423ca67f838b2" and "0f16edd8cc4553550c185f87f21f8bcc36649e71" have entirely different histories.

6 changed files with 905 additions and 786 deletions

View File

@ -9,7 +9,6 @@
"userInterfaceStyle": "automatic",
"newArchEnabled": true,
"ios": {
"bundleIdentifier": "traintrapemoi",
"supportsTablet": true
},
"android": {
@ -41,6 +40,7 @@
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-background-fetch",
[
"expo-location",
{
@ -52,7 +52,6 @@
"expo-notifications",
"expo-router",
"expo-secure-store",
"expo-share-extension",
[
"expo-splash-screen",
{

View File

@ -11,6 +11,7 @@ import { useReactNavigationDevTools } from '@dev-plugins/react-navigation'
import { useReactQueryDevTools } from '@dev-plugins/react-query'
import { useColorScheme } from '@/hooks/useColorScheme'
import store from '@/utils/store'
import { useStartBackgroundFetchServiceEffect } from '@/utils/background'
import LoginProvider from '@/components/LoginProvider'
import GeolocationProvider from '@/components/GeolocationProvider'
import GameProvider from '@/components/GameProvider'
@ -26,6 +27,7 @@ const queryClient = new QueryClient({
})
export default function RootLayout() {
useStartBackgroundFetchServiceEffect()
const colorScheme = useColorScheme()
const navigationRef = useNavigationContainerRef()

View File

@ -16,18 +16,19 @@ export default function GeolocationProvider({ children }: { children: ReactNode
const setLastPlayerLocations = useSetLastPlayerLocations()
const geolocationMutation = useGeolocationMutation({
auth,
onPostSuccess: (data) => unqueueLocation(data),
onPostSuccess: (data) => {
unqueueLocation(data)
geolocationMutation.reset()
},
onError: ({ response, error }) => { console.error(response, error) }
})
if (Platform.OS !== "web") {
useEffect(() => {
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || isAuthValid(auth))
return
const locToSend = geolocationsQueue[0]
geolocationMutation.mutate(locToSend)
}, [auth, geolocationMutation.status, geolocationsQueue])
}
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || Platform.OS === "web")
return
const locToSend = geolocationsQueue[0]
geolocationMutation.mutate(locToSend)
}, [auth, geolocationsQueue])
const lastLocationsQuery = useQuery({
queryKey: ['get-last-locations', auth.token],

1620
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
"version": "1.0.0",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint"
@ -17,7 +17,8 @@
"@dev-plugins/react-navigation": "^0.1.0",
"@dev-plugins/react-query": "^0.1.0",
"@expo/vector-icons": "^14.0.2",
"@maplibre/maplibre-react-native": "^10.0.0-beta.8",
"@maplibre/maplibre-react-native": "^10.0.0-alpha.28",
"@pchmn/expo-material3-theme": "github:pchmn/expo-material3-theme",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-navigation/bottom-tabs": "^7.0.0",
"@react-navigation/native": "^7.0.0",
@ -27,6 +28,7 @@
"@tanstack/react-query-persist-client": "^5.62.7",
"@turf/circle": "^7.1.0",
"expo": "~52.0.11",
"expo-background-fetch": "~13.0.3",
"expo-blur": "~14.0.1",
"expo-constants": "~17.0.3",
"expo-dev-client": "~5.0.4",
@ -37,7 +39,6 @@
"expo-notifications": "~0.29.11",
"expo-router": "~4.0.9",
"expo-secure-store": "~14.0.0",
"expo-share-extension": "^2.0.1",
"expo-splash-screen": "~0.29.13",
"expo-status-bar": "~2.0.0",
"expo-symbols": "~0.2.0",

View File

@ -0,0 +1,40 @@
import * as BackgroundFetch from 'expo-background-fetch'
import * as TaskManager from 'expo-task-manager'
import { Platform } from 'react-native'
import { useEffect } from 'react'
const BACKGROUND_FETCH_TASK = "background-fetch"
const BACKGROUND_FETCH_INTERVAL = 60000
async function backgroundUpdate() {
const now = Date.now()
console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`)
// Be sure to return the successful result type!
return BackgroundFetch.BackgroundFetchResult.NewData
}
TaskManager.defineTask(BACKGROUND_FETCH_TASK, backgroundUpdate)
export async function startBackgroundFetchService(): Promise<void | (() => void)> {
if (Platform.OS === "web") {
const interval = setInterval(backgroundUpdate, BACKGROUND_FETCH_INTERVAL)
return () => clearInterval(interval)
}
if (await TaskManager.isTaskRegisteredAsync(BACKGROUND_FETCH_TASK))
return async () => await BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK)
await BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
minimumInterval: BACKGROUND_FETCH_INTERVAL,
stopOnTerminate: false,
startOnBoot: true,
})
return async () => await BackgroundFetch.unregisterTaskAsync(BACKGROUND_FETCH_TASK)
}
export const useStartBackgroundFetchServiceEffect = () => useEffect(() => {
let cleanup: void | (() => void) = () => {}
startBackgroundFetchService().then(result => cleanup = result)
return cleanup
}, [])