Prototype envoi géolocalisations
This commit is contained in:
@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import * as SecureStore from '@/utils/SecureStore'
|
||||
import { Platform } from 'react-native'
|
||||
|
||||
interface AuthState {
|
||||
export interface AuthState {
|
||||
loggedIn: boolean,
|
||||
name: string | null,
|
||||
token: string | null,
|
||||
|
@ -1,24 +1,37 @@
|
||||
import { Constants } from '@/constants/Constants'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { LocationObject } from 'expo-location'
|
||||
|
||||
interface LocationState {
|
||||
location: LocationObject | null
|
||||
lastOwnLocation: LocationObject | null
|
||||
lastSentLocation: LocationObject | null
|
||||
queuedLocations: LocationObject[]
|
||||
}
|
||||
|
||||
const initialState: LocationState = {
|
||||
location: null
|
||||
lastOwnLocation: null,
|
||||
lastSentLocation: null,
|
||||
queuedLocations: []
|
||||
}
|
||||
|
||||
export const locationSlice = createSlice({
|
||||
name: 'location',
|
||||
initialState: initialState,
|
||||
reducers: {
|
||||
setLocation: (state, action: PayloadAction<LocationObject>) => {
|
||||
state.location = action.payload
|
||||
setLastLocation: (state, action: PayloadAction<LocationObject>) => {
|
||||
const location: LocationObject = action.payload
|
||||
state.lastOwnLocation = location
|
||||
if (state.lastSentLocation === null || (location.timestamp - state.lastSentLocation.timestamp) >= Constants.MIN_DELAY_LOCATION_SENT * 1000) {
|
||||
state.lastSentLocation = location
|
||||
state.queuedLocations.push(location)
|
||||
}
|
||||
},
|
||||
unqueueLocation: (state, action: PayloadAction<LocationObject>) => {
|
||||
state.queuedLocations.pop()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const { setLocation } = locationSlice.actions
|
||||
export const { setLastLocation, unqueueLocation } = locationSlice.actions
|
||||
|
||||
export default locationSlice.reducer
|
||||
|
Reference in New Issue
Block a user