Refactor to store
This commit is contained in:
parent
e3a2251898
commit
b619fe34f8
9 changed files with 177 additions and 70 deletions
|
@ -10,13 +10,13 @@ import { Colors } from '@/constants/Colors';
|
|||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
import List from '@/components/List';
|
||||
import { Request } from '@/services/request';
|
||||
import { useToken } from '@/context/AppProvider';
|
||||
import { useIsFocused } from '@react-navigation/core';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
export default function MapScreen() {
|
||||
const colorScheme = useColorScheme() ?? 'light';
|
||||
const { token, isLoading } = useToken();
|
||||
const isFocused = useIsFocused();
|
||||
const session = useSelector((state: any) => state.data.session);
|
||||
|
||||
const [ types, setTypes ] = useState<any>( [] );
|
||||
const [ coordinates, setCoordinates ] = useState<any>( [] );
|
||||
|
@ -24,17 +24,8 @@ export default function MapScreen() {
|
|||
|
||||
// Load session
|
||||
useEffect( () => {
|
||||
if (token) {
|
||||
Request.post( 'sessions/get', { token: token } ).then( (response) => {
|
||||
console.log('session', response);
|
||||
if (response.success) {
|
||||
const { session } = response;
|
||||
|
||||
setCoordinates([session.coordinates.longitude, session.coordinates.latitude]);
|
||||
}
|
||||
} )
|
||||
}
|
||||
}, [isFocused]);
|
||||
setCoordinates([session.coordinates.longitude, session.coordinates.latitude]);
|
||||
}, [session, isFocused]);
|
||||
|
||||
// Load markers and types
|
||||
useEffect( () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue