|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { View, StyleSheet, Platform } from 'react-native';
|
|
|
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
|
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
|
|
@ -13,10 +13,91 @@ import MessagingNavigation from './MessagingNavigation';
|
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
|
import { GraphicalCharterDark } from '../assets/GraphicalCharterDark';
|
|
|
|
|
import { GraphicalCharterLight } from '../assets/GraphicalCharterLight';
|
|
|
|
|
import { getCurrentUserMusic } from '../redux/thunk/spotThunk';
|
|
|
|
|
import { getCurrentUserMusic, getSpotList } from '../redux/thunk/spotThunk';
|
|
|
|
|
import SpotifyService from '../services/spotify/spotify.service';
|
|
|
|
|
import * as SecureStore from 'expo-secure-store';
|
|
|
|
|
import { MY_SECURE_AUTH_STATE_KEY } from '../screens/Register';
|
|
|
|
|
import * as Location from 'expo-location';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import qs from 'qs';
|
|
|
|
|
|
|
|
|
|
export default function Navigation() {
|
|
|
|
|
const [setErrorMsg] = useState('');
|
|
|
|
|
const [location, setLocation] = useState<Location.LocationObject>();
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const tokenSend: string = useSelector(state => state.userReducer.userFladToken);
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const currentMusic: Music = useSelector(state => state.appReducer.userCurrentMusic);
|
|
|
|
|
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
const requestLocationPermission = async () => {
|
|
|
|
|
const { status } = await Location.requestForegroundPermissionsAsync();
|
|
|
|
|
if (status !== 'granted') {
|
|
|
|
|
console.log('Permission to access location was denied');
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Permission to access location was granted');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
requestLocationPermission();
|
|
|
|
|
const sendLocationUpdate = async () => {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
let tmpKey: string = await SecureStore.getItemAsync(MY_SECURE_AUTH_STATE_KEY) ;
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
dispatch(getCurrentUserMusic(new SpotifyService(tmpKey)))
|
|
|
|
|
let { status } = await Location.requestForegroundPermissionsAsync();
|
|
|
|
|
if (status == 'granted') {
|
|
|
|
|
// should app is ready
|
|
|
|
|
const locationresp = await Location.getCurrentPositionAsync({});
|
|
|
|
|
// send location to server
|
|
|
|
|
if(currentMusic){
|
|
|
|
|
|
|
|
|
|
const body: Record<string, string | boolean | number | (string | boolean | number)[]> = {
|
|
|
|
|
longitude: locationresp.coords.longitude,
|
|
|
|
|
latitude: locationresp.coords.latitude,
|
|
|
|
|
currentMusic: currentMusic.id
|
|
|
|
|
}
|
|
|
|
|
const resp = await axios({
|
|
|
|
|
url: 'https://flad-api-production.up.railway.app/api/users/nextTo?' + qs.stringify(body),
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${tokenSend}`,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const datat: Record<string, string> = resp.data.listUser2;
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
dispatch(getSpotList(datat, new SpotifyService(tmpKey)))
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
let {status} = Location.requestForegroundPermissionsAsync();
|
|
|
|
|
if (status !== 'granted') {
|
|
|
|
|
setErrorMsg('Permission to access location was denied');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const interval = setInterval(sendLocationUpdate, 5000);
|
|
|
|
|
return () => {
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
};
|
|
|
|
|
}, [currentMusic]);
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const isDark = useSelector(state => state.userReducer.dark);
|
|
|
|
|
const style = isDark ? GraphicalCharterDark : GraphicalCharterLight;
|
|
|
|
|
const BottomTabNavigator = createBottomTabNavigator();
|
|
|
|
@ -31,16 +112,6 @@ export default function Navigation() {
|
|
|
|
|
};
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const favoritesMusicLength: number = useSelector(state => state.appReducer.favoriteMusic.length);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const token = "BQBNdaYRkD3GAOFASk8uc-l72zVwQeQ0sFB4GJnkBGudsJHnuAXd4eIWb78gbFLKZeBoHrWpHxMeSmqvHk75Utg9fsOJp7XyJfm-tAlgGhUQ-xiUM8rXTpa9k3M40BMSnujPDrap_O1ChCyGhBWYVHDd2t67qY0NVDvCJ4Qz7LucJJdgu1BN838qXTScQV90zriO8lp6Rjx6SsWov_fMZTyadzxebYIiQ-VDQDs63gUordThas-jFlAHLgJlqPhVOHJ1WaZt-_oLhgY3fk4bhORkyeAFZVRTnjw38A70b0eZU3ziQkOYW6w7kN__tzgP5gis0Y8mEIiUyTnyuQ"
|
|
|
|
|
const sheet = async () => {
|
|
|
|
|
const service = new SpotifyService(token)
|
|
|
|
|
dispatch(getCurrentUserMusic(service))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
sheet()
|
|
|
|
|
}, []);
|
|
|
|
|
return (
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
<NavigationContainer theme={MyTheme}>
|
|
|
|
|