Compare commits

...

5 Commits

6 changed files with 787 additions and 906 deletions

View File

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

View File

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

View File

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

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

View File

@ -1,40 +0,0 @@
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
}, [])