Compare commits
	
		
			5 Commits
		
	
	
		
			0f16edd8cc
			...
			76643fcc62
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						76643fcc62
	
				 | 
					
					
						|||
| 
						
						
							
						
						8084040aef
	
				 | 
					
					
						|||
| 
						
						
							
						
						893e6a9e01
	
				 | 
					
					
						|||
| 
						
						
							
						
						3648454da4
	
				 | 
					
					
						|||
| 
						
						
							
						
						25ca687448
	
				 | 
					
					
						
@@ -9,6 +9,7 @@
 | 
			
		||||
    "userInterfaceStyle": "automatic",
 | 
			
		||||
    "newArchEnabled": true,
 | 
			
		||||
    "ios": {
 | 
			
		||||
      "bundleIdentifier": "traintrapemoi",
 | 
			
		||||
      "supportsTablet": true
 | 
			
		||||
    },
 | 
			
		||||
    "android": {
 | 
			
		||||
@@ -40,7 +41,6 @@
 | 
			
		||||
      "favicon": "./assets/images/favicon.png"
 | 
			
		||||
    },
 | 
			
		||||
    "plugins": [
 | 
			
		||||
      "expo-background-fetch",
 | 
			
		||||
      [
 | 
			
		||||
        "expo-location",
 | 
			
		||||
        {
 | 
			
		||||
@@ -52,6 +52,7 @@
 | 
			
		||||
      "expo-notifications",
 | 
			
		||||
      "expo-router",
 | 
			
		||||
      "expo-secure-store",
 | 
			
		||||
      "expo-share-extension",
 | 
			
		||||
      [
 | 
			
		||||
        "expo-splash-screen",
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,6 @@ 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'
 | 
			
		||||
@@ -27,7 +26,6 @@ const queryClient = new QueryClient({
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export default function RootLayout() {
 | 
			
		||||
  useStartBackgroundFetchServiceEffect()
 | 
			
		||||
  const colorScheme = useColorScheme()
 | 
			
		||||
 | 
			
		||||
  const navigationRef = useNavigationContainerRef()
 | 
			
		||||
 
 | 
			
		||||
@@ -16,19 +16,18 @@ export default function GeolocationProvider({ children }: { children: ReactNode
 | 
			
		||||
  const setLastPlayerLocations = useSetLastPlayerLocations()
 | 
			
		||||
  const geolocationMutation = useGeolocationMutation({
 | 
			
		||||
    auth,
 | 
			
		||||
    onPostSuccess: (data) => {
 | 
			
		||||
      unqueueLocation(data)
 | 
			
		||||
      geolocationMutation.reset()
 | 
			
		||||
    },
 | 
			
		||||
    onPostSuccess: (data) => unqueueLocation(data),
 | 
			
		||||
    onError: ({ response, error }) => { console.error(response, error) }
 | 
			
		||||
  })
 | 
			
		||||
  
 | 
			
		||||
  if (Platform.OS !== "web") {
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
    if (geolocationsQueue.length === 0 || geolocationMutation.isPending || Platform.OS === "web")
 | 
			
		||||
      return
 | 
			
		||||
    const locToSend = geolocationsQueue[0]
 | 
			
		||||
    geolocationMutation.mutate(locToSend)
 | 
			
		||||
  }, [auth, geolocationsQueue])
 | 
			
		||||
      if (geolocationsQueue.length === 0 || geolocationMutation.isPending || isAuthValid(auth))
 | 
			
		||||
        return
 | 
			
		||||
      const locToSend = geolocationsQueue[0]
 | 
			
		||||
      geolocationMutation.mutate(locToSend)
 | 
			
		||||
    }, [auth, geolocationMutation.status, geolocationsQueue])
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const lastLocationsQuery = useQuery({
 | 
			
		||||
    queryKey: ['get-last-locations', auth.token],
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1622
									
								
								client/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1622
									
								
								client/package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -4,8 +4,8 @@
 | 
			
		||||
  "version": "1.0.0",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "expo start",
 | 
			
		||||
    "android": "expo start --android",
 | 
			
		||||
    "ios": "expo start --ios",
 | 
			
		||||
    "android": "expo run:android",
 | 
			
		||||
    "ios": "expo run:ios",
 | 
			
		||||
    "web": "expo start --web",
 | 
			
		||||
    "test": "jest --watchAll",
 | 
			
		||||
    "lint": "expo lint"
 | 
			
		||||
@@ -17,8 +17,7 @@
 | 
			
		||||
    "@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-alpha.28",
 | 
			
		||||
    "@pchmn/expo-material3-theme": "github:pchmn/expo-material3-theme",
 | 
			
		||||
    "@maplibre/maplibre-react-native": "^10.0.0-beta.8",
 | 
			
		||||
    "@react-native-async-storage/async-storage": "1.23.1",
 | 
			
		||||
    "@react-navigation/bottom-tabs": "^7.0.0",
 | 
			
		||||
    "@react-navigation/native": "^7.0.0",
 | 
			
		||||
@@ -28,7 +27,6 @@
 | 
			
		||||
    "@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",
 | 
			
		||||
@@ -39,6 +37,7 @@
 | 
			
		||||
    "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",
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}, [])
 | 
			
		||||
		Reference in New Issue
	
	Block a user