diff --git a/src/FLAD/App.tsx b/src/FLAD/App.tsx
index b26e99f..4169edb 100644
--- a/src/FLAD/App.tsx
+++ b/src/FLAD/App.tsx
@@ -2,6 +2,9 @@ import { StyleSheet } from 'react-native';
import { Provider } from 'react-redux';
import store from './redux/store';
import AuthNavigation from './navigation/AuthNavigation';
+import * as SplashScreen from 'expo-splash-screen';
+
+SplashScreen.preventAutoHideAsync();
export default function App() {
diff --git a/src/FLAD/app.json b/src/FLAD/app.json
index 8db8416..2ada30e 100644
--- a/src/FLAD/app.json
+++ b/src/FLAD/app.json
@@ -39,7 +39,7 @@
[
"expo-location",
{
- "locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location."
+ "locationAlwaysAndWhenInUsePermission": "Allow Flad to use your location."
}
]
]
diff --git a/src/FLAD/assets/icons/icons/Vector.png b/src/FLAD/assets/icons/icons/Vector.png
new file mode 100644
index 0000000..34364fb
Binary files /dev/null and b/src/FLAD/assets/icons/icons/Vector.png differ
diff --git a/src/FLAD/assets/icons/icons/icon_bookmark.svg b/src/FLAD/assets/icons/icons/icon_bookmark.svg
new file mode 100644
index 0000000..694cf08
--- /dev/null
+++ b/src/FLAD/assets/icons/icons/icon_bookmark.svg
@@ -0,0 +1,3 @@
+
diff --git a/src/FLAD/navigation/AuthNavigation.tsx b/src/FLAD/navigation/AuthNavigation.tsx
index 6f171fc..ee8d9ee 100644
--- a/src/FLAD/navigation/AuthNavigation.tsx
+++ b/src/FLAD/navigation/AuthNavigation.tsx
@@ -4,58 +4,128 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import StartNavigation from './StartNavigation';
import { Provider, useDispatch, useSelector } from 'react-redux';
import store from '../redux/store';
-import { useCallback, useEffect } from 'react';
+import { useCallback, useEffect, useState } from 'react';
import * as SplashScreen from 'expo-splash-screen';
import { View } from 'react-native';
import { getRefreshToken } from '../redux/thunk/authThunk';
+import * as Location from 'expo-location';
-SplashScreen.preventAutoHideAsync();
+// const LOCATION_TASK_NAME = 'flad-background-location-task';
export default function AuthNavigation() {
//@ts-ignore
- const appIsReady : boolean = useSelector(state => state.userReducer.loading);
+ const tokenProcesed : boolean = useSelector(state => state.userReducer.loading);
//@ts-ignore
const isLogin : boolean = useSelector(state => state.userReducer.isLogedIn);
// const userToken : string = useSelector(state => state.userReducer.userFladToken);
-
+ const [appIsReady, setAppIsReady] = useState(false);
const dispatch = useDispatch();
+ const [location, setLocation] = useState({});
+ const [errorMsg, setErrorMsg] = useState('');
+
+
+// // seems background task but not optimized
+// TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
+// if (error) {
+// console.log(error);
+// return;
+// }
+// if (data) {
+// const { locations } = data;
+// // send location updates to server
+// console.log(locations);
+// }
+// });
+ // const startLocationUpdates = async () => {
+ // try {
+ // await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
+ // accuracy: Location.Accuracy.Balanced,
+ // timeInterval: 5000, // send location updates every 5 seconds
+ // foregroundService: {
+ // notificationTitle: 'Location tracking',
+ // notificationBody: 'Location tracking is active.',
+ // },
+ // });
+ // } catch (error) {
+ // console.log(error);
+ // }
+ // };
+ // useEffect(() => {
+ // startLocationUpdates();
+ // return () => {
+ // Location.stopLocationUpdatesAsync(LOCATION_TASK_NAME);
+ // };
+ // }, []);
+
+
+
useEffect(() => {
async function prepare() {
- console.log(appIsReady, "1 AuthNav")
-
//@ts-ignore
await dispatch(getRefreshToken())
- if (appIsReady) {
- console.log("++++++++++++++++++++++++++++++++++++++jsiuis con +++++++++++++++++++++++++++++3");
+ if (tokenProcesed && appIsReady ) {
await SplashScreen.hideAsync();
} // await SplashScreen.hideAsync();
}
prepare();
- }, [appIsReady]);
+ }, [appIsReady,tokenProcesed]);
// const onStackRootView = useCallback(async () => {
// }, [appIsReady]);
-
- if (appIsReady == false) {
- console.log(appIsReady, "T9 AuthNav")
+ // useEffect(() => {
+ // const sendLocationUpdate = async () => {
+ // try {
+ // let { status } = await Location.requestForegroundPermissionsAsync();
+ // console.log('Sending location update ================================###############');
+ // if (status === 'granted') {
+ // console.log(appIsReady)
+ // if (true) {// should app is ready
+ // // see deeper the documentation
+ // // const [status, requestPermission] = Location.useBackgroundPermissions();
+ // const locationresp = await Location.getCurrentPositionAsync({});
+ // setLocation(locationresp);
+ // // send location to server
+ // console.log(locationresp);
+ // if(locationresp !=location ){
+
+ // }
+ // console.log(location);
+ // }
+ // }
+ // else{
+ // console.log(`Sending location update with error ${status} ================================###############`);
+ // setErrorMsg('Permission to access location was denied');
+ // return;
+ // }
+ // } catch (error) {
+ // console.log(error);
+ // }
+ // };
+ // const interval = setInterval(sendLocationUpdate, 5000); // send location updates every 5 seconds
+ // return () => {
+ // clearInterval(interval);
+ // };
+ // }, []);
+ if (tokenProcesed == false) {
return null;
}
- console.log(appIsReady, "k9 AuthNav")
// console.log(userToken, "k9 AuthNav")
return (
<>
{isLogin ? (
/* {userToken != null ? ( */
-
+ // should set the reference to the function in Navigation to realy perform an on ready
+ // test purpose
+ setAppIsReady(true)}>
) :
-
-
+ setAppIsReady(true)}>
+
}
>
diff --git a/src/FLAD/redux/reducers/userReducer.tsx b/src/FLAD/redux/reducers/userReducer.tsx
index 6dd6793..64b2212 100644
--- a/src/FLAD/redux/reducers/userReducer.tsx
+++ b/src/FLAD/redux/reducers/userReducer.tsx
@@ -41,12 +41,15 @@ const initialState = {
user :action.playload,
isLogedIn: true
};
- // case USER_SIGNUP:
- // return {...state, nounours: action.payload};
case userTypes.USER_LOGOUT:
return {...state,
user :null,
isLogedIn: false }
+ case userTypes.SAVE_SPOTIFY:
+ return {
+ ...state,
+ userSpotifyToken : action.playload,
+ };
default:
return state;
}
diff --git a/src/FLAD/redux/types/userTypes.tsx b/src/FLAD/redux/types/userTypes.tsx
index cdea161..081682f 100644
--- a/src/FLAD/redux/types/userTypes.tsx
+++ b/src/FLAD/redux/types/userTypes.tsx
@@ -2,6 +2,7 @@
export const userTypes = {
LOGIN: 'LOGIN',
SIGNUP: 'SIGNUP',
+ SAVE_SPOTIFY :'SAVE_SPOTIFY',
UPDATE_USER: 'UPDATE_USER',
UPDATE_PROFILE_PICTURE: 'UPDATE_PROFILE_PICTURE',
USER_LOGOUT : 'USER_LOGOUT',
diff --git a/src/FLAD/screens/MusicDetail.tsx b/src/FLAD/screens/MusicDetail.tsx
index b176ffb..867bb1d 100644
--- a/src/FLAD/screens/MusicDetail.tsx
+++ b/src/FLAD/screens/MusicDetail.tsx
@@ -23,233 +23,100 @@ import { LittleCard } from "../components/littleCard";
import normalize from "../components/Normalize";
import { Circle } from "react-native-svg";
import { AntDesign } from '@expo/vector-icons';
+import * as SecureStore from 'expo-secure-store';
const halfPi = Math.PI/2;
+
//@ts-ignore
const MusicDetail = ({ route }) => {
const music : Music = route.params.music;
- const [currentspot, setCurrentspot] = useState(music);
- const [sound, setSound] = useState(null);
- const [simularMusic, setSimularMusic] = useState([] as Music []);
+ const [currentspot] = useState(music);
+ const [simularMusic, setSimularMusic] = useState([]);
const [isPlaying, setIsPlaying] = useState(false);
- const loader = useSharedValue(0);
- useEffect(() => {
- loader.value = isPlaying ? 1 : 0
- }, [isPlaying,loader ]);
-
- const transition = useDerivedValue(()=>{
- return withTiming(loader.value, {duration : 1000})
- }
- )
-
-
- // const styleAniamatedButton = useAnimatedStyle(() => {
- // const verticalAxis =interpolate(
- // transition.value,
- // [0,1],
- // [circumference, 0]
- // )
-
- // return {
- // top : withSpring( verticalAxis),
- // left : withSpring(horizontalAxis),
- // };
-
- // })
-
-
- const playTrackPreview = async () => {
- console.log("===============================================================================================================");
-
- console.log('get in Sound');
-
- const { sound } = await Audio.Sound.createAsync({uri :music.trackPreviewUrl});
- //@ts-ignore
- setSound(sound);
- console.log('Playing Sound');
- await sound.playAsync();
- setIsPlaying(true);
-
+ const [sound, setSound] = useState(null);
+
+ const navigator = useNavigation();
+
+ const [testtoken, setTesttoken] = useState('')
- // const soundObject = new Audio.Sound();
- // try {
- // await soundObject.loadAsync({ uri: trackPreviewUrl });
- // await soundObject.playAsync();
- // setIsPlaying(true);
- // } catch (error) {
- // console.log('Error loading sound:', error);
- // }
- };
-
- const handlePlaySound = async () => {
- if (sound === null) {
- const { sound: newSound } = await Audio.Sound.createAsync(
- { uri: music.trackPreviewUrl },
- { shouldPlay: true }
- );
- setSound(newSound);
- setIsPlaying(true);
-
- } else {
- setIsPlaying(true);
- //@ts-ignore
- await sound.playAsync();
+ const sheet = async () => {
+ const data = await SecureStore.getItemAsync('MySecureAuthStateKey');
+ setTesttoken(data)
}
- };
-
- const handleStopSound = async () => {
- if (sound !== null) {
- setIsPlaying(false);
+ sheet();
- //@ts-ignore
- await sound.stopAsync();
- }
- else{
- }
- };
- useEffect(() => {
- return sound ? () => {
- console.log('Unloading Sound');
- //@ts-ignore
- sound.unloadAsync();
+ const getSimilarTrack = async () => {
+ const service = new SpotifyService(testtoken);
+ var simularMusic = await service.getSimilarTrack(currentspot.id, 5, 'FR');
+ try {
+ Promise.all(simularMusic).then((resolvedMusic) => {
+ setSimularMusic(resolvedMusic);
+ });
+ } catch (error) {
+ console.log(error.message);
}
- : undefined;
- }, [sound]);
- // useEffect(() => {
- // if(isPlaying){
-
- // }
- // })
-
- const sensor = useAnimatedSensor(SensorType.ROTATION);
- const styleAniamatedImage = useAnimatedStyle(() => {
- const {yaw, pitch, roll} = sensor.sensor.value;
- const verticalAxis =interpolate(
- pitch,
- [-halfPi*2,halfPi*2],
- [-45, 45]
- )
- const horizontalAxis =interpolate(
- roll,
- [-halfPi*2,halfPi*2],
- [-45, 45]
- )
- return {
- top : withSpring( verticalAxis),
- left : withSpring(horizontalAxis),
- };
-
- })
- // const CLIENT_ID = "1f1e34e4b6ba48b388469dba80202b10";
- // const CLIENT_SECRET = "779371c6d4994a68b8dd6e84b0873c82";
- // const spotify = "BQA2IAFZ-7ta4-_4_Uqdcdrqi_peE6Hlf1jwxFqjXTbwes0z8xgVGx0rE3zv4cQlusd1ILJhRwkxzPsL1YakzSvCxaTI1P7kOzBrrMqlkDgk4vlFvzLjScB0hBLULbpZyn3ylgx4RyZBEWfmc24wZPQOsrJU58AYCveA52UxYVSIc_Frr7LZyRmwjzGB68MPZeBD"
- // var authOptions = {
- // method: 'GET',
- // url: 'https://api.spotify.com/v1/me/player/currently-playing',
-
- // headers: {
- // 'Authorization': 'Bearer ' + spotify,
- // 'Content-Type' : 'application/json',
- // 'market' : 'FR',
- // },
- // json: true
- // };
-
- // var id = '0cFS3AMF9Lhj3CNoFvwjvY'
- // const requestor = new RequestHandler()
-
- // const getCurrentTrack = async () => {
- // try {
- // const opt : FetchRequest ={headers : Record}
- // requestor.spotifyFetch(`tracks${id}`,)
-
- // // var GetTrackOptions = {
- // // method: 'GET',
- // // url: 'https://api.spotify.com/v1/tracks/'+id,
-
- // // headers: {
- // // 'Authorization': 'Bearer ' + spotify,
- // // 'Content-Type' : 'application/json',
- // // 'market' : 'FR',
- // // },
- // // json: true
- // // };
- // // const resp = await axios(GetTrackOptions)
- // // console.log("============");
- // // console.log(resp.data.href);
- // // console.log("================================"+resp.data.album.images[0].url+ "================================");
- // // var tmp = currentspot;
-
- // // tmp.sourceUrl = resp.data.album.images[0].url;
- // // setCurrentspot(tmp);
- // // await axios(authOptions).then(async (response) =>{
- // // console.log(response.data.item.preview_url);
- // // const id = response.data.item.id;
- // // var GetTrackOptions = {
- // // method: 'GET',
- // // url: 'https://api.spotify.com/v1/tracks/'+id,
-
- // // headers: {
- // // 'Authorization': 'Bearer ' + spotify,
- // // 'Content-Type' : 'application/json',
- // // 'market' : 'FR',
- // // },
- // // json: true
- // // };
- // // console.log("============");
- // // const music = await axios(GetTrackOptions);
- // // console.log("================================"+music.data+ "================================");
- // // currentspot.sourceUrl = music.data.images[0];
- // // setCurrentspot(currentspot);
- // // })
-
- // // const response = await fetch('https://api.spotify.com/v1/me', {
- // // method: 'GET',
- // // headers: {
- // // Authorization: 'Bearer ' + spotify,
- // // 'Content-Type': 'application/json',
- // // },
- // // });
- // // response.json()
-
- // // destructure the response and rename the properties to be in camelCase to satisfy my linter ;)
+ }
- // } catch (err) {
- // console.error(err);
- // }
- // }
- const animationState = new Value(State.UNDETERMINED);
- const playMusic = async (id: string) => {
- try {
- const service = new SpotifyService("BQDWJTPvSloZPYDqLc1YWri2LEcognvqoM5bdoCWMuHR9In2FhaKq5tW3-VC5JET9dD9K-W4Rmm0IiyhtX-fSL3Tb8RTHMJUc5GKFq2jxWlH7QXxsiYZV8Fhw2qU1eCpSof1qkPsBd1R36GOgcBaXq2N6kLTP5UcfP-gzjz65x_fVRSxoP6znK2dkvL6saQ6WwzoEFopqpqo") ;
- console.log("=====================================================)))))))))))))))"+id+"================================")
- await service.playMusic(id);
- }catch(error){}
- }
-
- const tmpMusic2: Music[] = [
- // new Music("La pharmacie", "Jul",require("../assets/images/jul.png")),
- // new Music("Deux frères", "PNL", require("../assets/images/pnl.png")),
- new Music("6npyDB4mn8MO1A1h666FTk","Bambina", "PNL", "https://upload.wikimedia.org/wikipedia/en/a/a0/PNL_-_Dans_la_l%C3%A9gende.png","https://p.scdn.co/mp3-preview/d38052978a79adced2187cd8b6497bb10bedc452?cid=774b29d4f13844c495f206cafdad9c86"),
- // new Music("0qwxx9ouUc5kGmMWHglDpq","Stratos", "Kekra", "https://images.genius.com/ddc9cadedd1d4cef0860aaa85af9cd46.705x705x1.png",""),
- new Music("03o8WSqd2K5rkGvn9IsLy2","Autobahn", "Sch", "https://images.genius.com/83b6c98680d38bde1571f6b4093244b5.1000x1000x1.jpg","https://p.scdn.co/mp3-preview/c55f95de81b8c3d0df04148da1b03bd38db56e8f?cid=774b29d4f13844c495f206cafdad9c86"),
- new Music("6DPrYPPGYK218iVIZDix3i","Freeze Raël", "Freeze Corleone", "https://intrld.com/wp-content/uploads/2020/08/freeze-corleone-la-menace-fanto%CC%82me.png","https://p.scdn.co/mp3-preview/a9f9cb19ac1fe6db0d06b67decf8edbb25895a33?cid=774b29d4f13844c495f206cafdad9c86"),
- // new Music("Blanka", "PNL", require("../assets/images/pnl.png")),
- new Music("5GFHFEASZeJF0gyWuDDjGE","Kratos", "PNL", "https://upload.wikimedia.org/wikipedia/en/a/a0/PNL_-_Dans_la_l%C3%A9gende.png","https://p.scdn.co/mp3-preview/9e854f4905c1228482e390169eb76d8520076b8f?cid=774b29d4f13844c495f206cafdad9c86"),
- ] ;
- const getSimilarTrack = async () => {
- const service =new SpotifyService("BQC0Ne1eU2bR28A65uO-M9QPLCmGveUG5E7tQ5dD8nmzQvcz2OqUWNMYEM7zx0sEIvOPoV3S9XKSlFbFx5C3si97YAXU-4AzRiqoshfmLTFlGoPMkmGhYip9MDzshhbZM76eEWJ6x43YoXiM-TQBhI0HKh78W6a3A34TXIrn0QzU3rvZM2-ftnTfKD2e2bAN3FgDc38C");
- var simularMusic = await service.getSimilarTrack(currentspot.id,5,'FR');
- setSimularMusic(simularMusic);
- }
- useEffect(() => {
+ useEffect(() => {
getSimilarTrack();
}, []);
- const navigator = useNavigation();
+
+ const handlePlaySound = async () => {
+ if (sound === null) {
+ const { sound: newSound } = await Audio.Sound.createAsync(
+ { uri: music.trackPreviewUrl },
+ { shouldPlay: true }
+ );
+ setSound(newSound);
+ setIsPlaying(true);
+ } else {
+ setIsPlaying(true);
+ //@ts-ignore
+ await sound.playAsync();
+ }
+ };
+
+ const handleStopSound = async () => {
+ if (sound !== null) {
+ setIsPlaying(false);
+
+ //@ts-ignore
+ await sound.stopAsync();
+ }
+ else{
+ }
+ };
+ useEffect(() => {
+ return sound ? () => {
+ console.log('Unloading Sound');
+ //@ts-ignore
+ sound.unloadAsync();
+ }
+ : undefined;
+ }, [sound]);
+
+ const sensor = useAnimatedSensor(SensorType.ROTATION);
+ const styleAniamatedImage = useAnimatedStyle(() => {
+ const {yaw, pitch, roll} = sensor.sensor.value;
+ const verticalAxis =interpolate(
+ pitch,
+ [-halfPi*2,halfPi*2],
+ [-45, 45]
+ )
+ const horizontalAxis =interpolate(
+ roll,
+ [-halfPi*2,halfPi*2],
+ [-45, 45]
+ )
+ return {
+ top : withSpring( verticalAxis),
+ left : withSpring(horizontalAxis),
+ };
+
+ })
return (
-
{
Dans ma collection 2
*/}
-
+ {testtoken}
+ {simularMusic.length !== 0 && (
+
{(props) => (
{ navigator.navigate("MusicDetail", {"music": props}) }} >
)}
+ )}
-
);
};
diff --git a/src/FLAD/screens/Register.tsx b/src/FLAD/screens/Register.tsx
index f76d983..84c9c52 100644
--- a/src/FLAD/screens/Register.tsx
+++ b/src/FLAD/screens/Register.tsx
@@ -10,6 +10,7 @@ import { registerUser } from '../redux/thunk/authThunk';
import { useDispatch } from 'react-redux';
import { CredentialsRegister } from '../redux/actions/userActions';
import { Buffer } from 'buffer';
+import SpotifyService from '../services/spotify/spotify.service';
// @ts-ignore
const DismissKeyboard = ({ children }) => (
@@ -137,7 +138,9 @@ const scopes = scopesArr.join(' ');
refresh_token: refreshToken,
expires_in: expiresIn,
} = responseJson;
+
await setSpotifyToken(accessToken);
+
console.log(spotifyToken);
} catch (err) {
console.error(err);
@@ -164,12 +167,46 @@ const scopes = scopesArr.join(' ');
expires_in: expiresIn,
} = responseJson;
await setSpotifyToken(accessToken);
+ save(MY_SECURE_AUTH_STATE_KEY, accessToken);
+ testService(accessToken);
console.log(spotifyToken);
} catch (err) {
console.error(err);
}
}
+ const testService = async (token : string) =>{
+ try {
+ const serviceTest = new SpotifyService(token);
+ console.log("==============Test Service 1 ============");
+ const respSearch = await serviceTest.searchMusic("Parapluie Tiakola");
+ console.log("===================repoonce=========================");
+ console.log(respSearch);
+ console.log("============================================");
+ console.log("==============Test Service 2 ============");
+ const respFull = await serviceTest.getMusicById(respSearch[0].id);
+ console.log("===================repoonce=========================");
+ console.log(respFull);
+ console.log("============================================");
+ console.log("==============Test Service 3 ============");
+ const respSimilar = await serviceTest.getSimilarTrack(respSearch[0].id);
+ console.log("===================repoonce=========================");
+ console.log(respSimilar);
+ console.log("============================================");
+ console.log("============================================");
+
+ } catch (error) {
+ console.log("==============Test Service Error============");
+ console.error(error);
+ console.log("============================================");
+
+ }
+
+ }
+
+
+
+
return (
diff --git a/src/FLAD/services/spotify/spotify.service.ts b/src/FLAD/services/spotify/spotify.service.ts
index 45e13d7..49eb369 100644
--- a/src/FLAD/services/spotify/spotify.service.ts
+++ b/src/FLAD/services/spotify/spotify.service.ts
@@ -2,7 +2,19 @@ import axios from "axios";
import MusicFactory from "../../Model/factory/MusicFactory";
import Music from "../../Model/Music";
import { FetchOptions, RequestHandler } from "./spotifyRequestHandler/utils";
-
+ export class MusicMinimal {
+ public id : string;
+ public title: string;
+ public image: string;
+
+ constructor(id : string,title: string, bio: string, image: string, trackPreviewUrl: string) {
+ this.title = title;
+ this.image = image;
+ this.id = id;
+ }
+
+ }
+
export default class SpotifyService implements IspotifyService {
private readonly API_URL = "https://flad-api-production.up.railway.app/api/";
private spotifyRequestHandler = new RequestHandler();
@@ -154,32 +166,71 @@ export default class SpotifyService implements IspotifyService {
return ;
}
- public async getSimilarTrack(musicId : string,limit? : number ,market? : string): Promise{
- var requestData :string = '/recommendations';
+ // public async getSimilarTrack(musicId : string,limit : number =1,market? : string): Promise{
+ // var requestData :string = '/recommendations' +
+ // '?limit=' +limit+
+ // '&market=FR' +
+ // "&seed_tracks=" + musicId;
+
+ // const fetchOptions: FetchOptions = {
+ // method: 'GET',
+ // body: {
+ // seed_tracks: musicId,
+ // market: "FR",
+ // limit: 1,
+ // }
+ // };
+
+ // console.log('222222222221baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros ' + musicId);
+
+ // const respSimilarMusic = await this.spotifyRequestHandler.spotifyFetch(requestData,undefined,this.token);
+ // console.log(respSimilarMusic.status+'baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros');
+ // console.log(respSimilarMusic.data+'baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros2');
+
+ // /// if respSimilarMusic == null || respSimilarMusic.data.count == 0 =>
+ // const similars : Music[]= respSimilarMusic.data.tracks.map(async (trackData: any) => {
+ // // const { id, name, artists, album } = trackData;
+ // console.log(trackData.id);
+ // if(trackData.id){
+ // const data = await this.getMusicById(trackData.id);
+ // return data;
+ // }
+ // // return MusicFactory.mapFromSpotifyTrack(trackData)
+ // // const artistNames = artists.map((artist: any) => artist.name).join(', ');
+ // // const linkCover = album?.images[0]?.url || '';
+ // // return new Music(id, name, artistNames, linkCover);
+ // });
+ // console.log(similars+'################################################');
+ // return similars;
+ // }
+ public async getSimilarTrack(musicId: string, limit: number = 1, market?: string): Promise {
+ const requestData: string = '/recommendations' +
+ '?limit=' + limit +
+ '&market=FR' +
+ '&seed_tracks=' + musicId;
+ console.log(musicId, "=============ouioui=================")
+
+ const respSimilarMusic = await this.spotifyRequestHandler.spotifyFetch(requestData, undefined, this.token);
- const fetchOptions: FetchOptions = {
- method: 'GET',
- body: {
- seed_tracks: musicId,
- // market: "FR",
- // limit: 5,
+ if (!respSimilarMusic || !respSimilarMusic.data.tracks) {
+ return [];
+ }
+
+ const similars: Music[] = await Promise.all(
+ respSimilarMusic.data.tracks.map(async (trackData: any) => {
+
+ if (trackData.id) {
+ console.log(trackData.id, "=============ouioui=================")
+ const data = await this.getMusicById(trackData.id);
+ // console.log(data, "=============nonon=================");
+ return data;
}
- };
- console.log('222222222221baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros');
+ })
+ );
- const respSimilarMusic = await this.spotifyRequestHandler.spotifyFetch(requestData, fetchOptions,this.token);
- console.log(respSimilarMusic.status+'baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros');
- /// if respSimilarMusic == null || respSimilarMusic.data.count == 0 =>
- const similars = respSimilarMusic.data.tracks.map((trackData: any) => {
- // const { id, name, artists, album } = trackData;
- console.log(trackData.id);
- // return MusicFactory.mapFromSpotifyTrack(trackData)
- // const artistNames = artists.map((artist: any) => artist.name).join(', ');
- // const linkCover = album?.images[0]?.url || '';
- // return new Music(id, name, artistNames, linkCover);
- });
- return [] as Music[];
- }
+ return similars.filter((music: Music | undefined) => !!music) as Music[];
+ }
+
async getSpotifyCredentials() {
const res = await axios.get(this.API_URL)
diff --git a/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx b/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx
index 201266c..519f1bf 100644
--- a/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx
+++ b/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx
@@ -32,7 +32,7 @@ export class RequestHandler{
},
data: options.body
});
- console.log(resp, "frfrfrfr");
+ // console.log(resp, "frfrfrfr");
return resp;
// if (
// // @ts-ignore
diff --git a/src/FLAD/services/user/userService.service.tsx b/src/FLAD/services/user/userService.service.tsx
index 92d7968..53290f1 100644
--- a/src/FLAD/services/user/userService.service.tsx
+++ b/src/FLAD/services/user/userService.service.tsx
@@ -10,14 +10,8 @@ export class UserService {
return docData(userDocRef);
}
async uploadName(name: string, email : string) {
- const user = this.auth.currentUser;
try {
- const userDocRef = doc(this.firestore, `User/${user.uid}`);
- await setDoc(userDocRef, {
- name,
- email
- });
- return true;
+
} catch (e) {
return null;
}