similar good but verry slow => if i change something in the code it works verry faster(when i save durring the app proccessing)
continuous-integration/drone/push Build is passing Details

pull/12/head
David D'ALMEIDA 2 years ago
parent d1f1d57b2d
commit b466ff5a77

@ -2,6 +2,9 @@ import { StyleSheet } from 'react-native';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import store from './redux/store'; import store from './redux/store';
import AuthNavigation from './navigation/AuthNavigation'; import AuthNavigation from './navigation/AuthNavigation';
import * as SplashScreen from 'expo-splash-screen';
SplashScreen.preventAutoHideAsync();
export default function App() { export default function App() {

@ -39,7 +39,7 @@
[ [
"expo-location", "expo-location",
{ {
"locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location." "locationAlwaysAndWhenInUsePermission": "Allow Flad to use your location."
} }
] ]
] ]

Binary file not shown.

After

Width:  |  Height:  |  Size: 835 B

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.6666 3.33219L9.71998 4.27886L8.65998 3.21886V10.6655H7.33998V3.21886L6.27998 4.27886L5.33332 3.33219L7.99998 0.665527L10.6666 3.33219ZM13.3333 6.66553V13.9989C13.3333 14.7322 12.7333 15.3322 12 15.3322H3.99998C3.25998 15.3322 2.66665 14.7322 2.66665 13.9989V6.66553C2.66665 5.92553 3.25998 5.33219 3.99998 5.33219H5.99998V6.66553H3.99998V13.9989H12V6.66553H9.99998V5.33219H12C12.7333 5.33219 13.3333 5.92553 13.3333 6.66553Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 557 B

@ -4,57 +4,127 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import StartNavigation from './StartNavigation'; import StartNavigation from './StartNavigation';
import { Provider, useDispatch, useSelector } from 'react-redux'; import { Provider, useDispatch, useSelector } from 'react-redux';
import store from '../redux/store'; import store from '../redux/store';
import { useCallback, useEffect } from 'react'; import { useCallback, useEffect, useState } from 'react';
import * as SplashScreen from 'expo-splash-screen'; import * as SplashScreen from 'expo-splash-screen';
import { View } from 'react-native'; import { View } from 'react-native';
import { getRefreshToken } from '../redux/thunk/authThunk'; 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() { export default function AuthNavigation() {
//@ts-ignore //@ts-ignore
const appIsReady : boolean = useSelector(state => state.userReducer.loading); const tokenProcesed : boolean = useSelector(state => state.userReducer.loading);
//@ts-ignore //@ts-ignore
const isLogin : boolean = useSelector(state => state.userReducer.isLogedIn); const isLogin : boolean = useSelector(state => state.userReducer.isLogedIn);
// const userToken : string = useSelector(state => state.userReducer.userFladToken); // const userToken : string = useSelector(state => state.userReducer.userFladToken);
const [appIsReady, setAppIsReady] = useState(false);
const dispatch = useDispatch(); 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(() => { useEffect(() => {
async function prepare() { async function prepare() {
console.log(appIsReady, "1 AuthNav")
//@ts-ignore //@ts-ignore
await dispatch(getRefreshToken()) await dispatch(getRefreshToken())
if (appIsReady) { if (tokenProcesed && appIsReady ) {
console.log("++++++++++++++++++++++++++++++++++++++jsiuis con +++++++++++++++++++++++++++++3");
await SplashScreen.hideAsync(); await SplashScreen.hideAsync();
} // await SplashScreen.hideAsync(); } // await SplashScreen.hideAsync();
} }
prepare(); prepare();
}, [appIsReady]); }, [appIsReady,tokenProcesed]);
// const onStackRootView = useCallback(async () => { // const onStackRootView = useCallback(async () => {
// }, [appIsReady]); // }, [appIsReady]);
// 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 ){
if (appIsReady == false) { // }
console.log(appIsReady, "T9 AuthNav") // 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; return null;
} }
console.log(appIsReady, "k9 AuthNav")
// console.log(userToken, "k9 AuthNav") // console.log(userToken, "k9 AuthNav")
return ( return (
<> <>
{isLogin ? ( {isLogin ? (
/* {userToken != null ? ( */ /* {userToken != null ? ( */
<SafeAreaProvider> // should set the reference to the function in Navigation to realy perform an on ready
// test purpose
<SafeAreaProvider onLayout={()=>setAppIsReady(true)}>
<Navigation/> <Navigation/>
</SafeAreaProvider> </SafeAreaProvider>
) : ) :
<SafeAreaProvider > <SafeAreaProvider onLayout={()=>setAppIsReady(true)}>
<StartNavigation /> <StartNavigation />
</SafeAreaProvider> </SafeAreaProvider>
} }

@ -41,12 +41,15 @@ const initialState = {
user :action.playload, user :action.playload,
isLogedIn: true isLogedIn: true
}; };
// case USER_SIGNUP:
// return {...state, nounours: action.payload};
case userTypes.USER_LOGOUT: case userTypes.USER_LOGOUT:
return {...state, return {...state,
user :null, user :null,
isLogedIn: false } isLogedIn: false }
case userTypes.SAVE_SPOTIFY:
return {
...state,
userSpotifyToken : action.playload,
};
default: default:
return state; return state;
} }

@ -2,6 +2,7 @@
export const userTypes = { export const userTypes = {
LOGIN: 'LOGIN', LOGIN: 'LOGIN',
SIGNUP: 'SIGNUP', SIGNUP: 'SIGNUP',
SAVE_SPOTIFY :'SAVE_SPOTIFY',
UPDATE_USER: 'UPDATE_USER', UPDATE_USER: 'UPDATE_USER',
UPDATE_PROFILE_PICTURE: 'UPDATE_PROFILE_PICTURE', UPDATE_PROFILE_PICTURE: 'UPDATE_PROFILE_PICTURE',
USER_LOGOUT : 'USER_LOGOUT', USER_LOGOUT : 'USER_LOGOUT',

@ -23,64 +23,44 @@ import { LittleCard } from "../components/littleCard";
import normalize from "../components/Normalize"; import normalize from "../components/Normalize";
import { Circle } from "react-native-svg"; import { Circle } from "react-native-svg";
import { AntDesign } from '@expo/vector-icons'; import { AntDesign } from '@expo/vector-icons';
import * as SecureStore from 'expo-secure-store';
const halfPi = Math.PI/2; const halfPi = Math.PI/2;
//@ts-ignore //@ts-ignore
const MusicDetail = ({ route }) => { const MusicDetail = ({ route }) => {
const music : Music = route.params.music; const music : Music = route.params.music;
const [currentspot, setCurrentspot] = useState(music); const [currentspot] = useState(music);
const [sound, setSound] = useState(null); const [simularMusic, setSimularMusic] = useState<Music[]>([]);
const [simularMusic, setSimularMusic] = useState([] as Music []);
const [isPlaying, setIsPlaying] = useState(false); const [isPlaying, setIsPlaying] = useState(false);
const loader = useSharedValue(0); const [sound, setSound] = useState(null);
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 () => { const navigator = useNavigation();
console.log("===============================================================================================================");
console.log('get in Sound'); const [testtoken, setTesttoken] = useState('')
const { sound } = await Audio.Sound.createAsync({uri :music.trackPreviewUrl}); const sheet = async () => {
//@ts-ignore const data = await SecureStore.getItemAsync('MySecureAuthStateKey');
setSound(sound); setTesttoken(data)
console.log('Playing Sound'); }
await sound.playAsync(); sheet();
setIsPlaying(true);
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);
}
}
// const soundObject = new Audio.Sound(); useEffect(() => {
// try { getSimilarTrack();
// await soundObject.loadAsync({ uri: trackPreviewUrl }); }, []);
// await soundObject.playAsync();
// setIsPlaying(true);
// } catch (error) {
// console.log('Error loading sound:', error);
// }
};
const handlePlaySound = async () => { const handlePlaySound = async () => {
if (sound === null) { if (sound === null) {
@ -116,11 +96,6 @@ const MusicDetail = ({ route }) => {
} }
: undefined; : undefined;
}, [sound]); }, [sound]);
// useEffect(() => {
// if(isPlaying){
// }
// })
const sensor = useAnimatedSensor(SensorType.ROTATION); const sensor = useAnimatedSensor(SensorType.ROTATION);
const styleAniamatedImage = useAnimatedStyle(() => { const styleAniamatedImage = useAnimatedStyle(() => {
@ -141,115 +116,7 @@ const MusicDetail = ({ route }) => {
}; };
}) })
// 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(() => {
getSimilarTrack();
}, []);
const navigator = useNavigation();
return ( return (
<SafeAreaView style={styles.mainSafeArea}>
<View style={styles.body}> <View style={styles.body}>
<View style={styles.backgroundSection}> <View style={styles.backgroundSection}>
<Image <Image
@ -334,17 +201,19 @@ const MusicDetail = ({ route }) => {
<Text style={{ fontSize: 16, fontWeight:"700",lineHeight:12, color : '#FFFFFF' }}>Dans ma collection 2</Text> <Text style={{ fontSize: 16, fontWeight:"700",lineHeight:12, color : '#FFFFFF' }}>Dans ma collection 2</Text>
</Pressable> */} </Pressable> */}
</View> </View>
<HorizontalFlatList title={'Similar'} data={tmpMusic2}> <Text>{testtoken}</Text>
{simularMusic.length !== 0 && (
<HorizontalFlatList title={'Similar'} data={simularMusic}>
{(props) => ( {(props) => (
<Pressable onLongPress={() => { navigator.navigate("MusicDetail", {"music": props}) }} > <Pressable onLongPress={() => { navigator.navigate("MusicDetail", {"music": props}) }} >
<LittleCard image={props.image} title ={props.title}/> <LittleCard image={props.image} title ={props.title}/>
</Pressable> </Pressable>
)} )}
</HorizontalFlatList> </HorizontalFlatList>
)}
</ScrollView> </ScrollView>
</View> </View>
</View> </View>
</SafeAreaView>
); );
}; };

@ -10,6 +10,7 @@ import { registerUser } from '../redux/thunk/authThunk';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { CredentialsRegister } from '../redux/actions/userActions'; import { CredentialsRegister } from '../redux/actions/userActions';
import { Buffer } from 'buffer'; import { Buffer } from 'buffer';
import SpotifyService from '../services/spotify/spotify.service';
// @ts-ignore // @ts-ignore
const DismissKeyboard = ({ children }) => ( const DismissKeyboard = ({ children }) => (
@ -137,7 +138,9 @@ const scopes = scopesArr.join(' ');
refresh_token: refreshToken, refresh_token: refreshToken,
expires_in: expiresIn, expires_in: expiresIn,
} = responseJson; } = responseJson;
await setSpotifyToken(accessToken); await setSpotifyToken(accessToken);
console.log(spotifyToken); console.log(spotifyToken);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -164,12 +167,46 @@ const scopes = scopesArr.join(' ');
expires_in: expiresIn, expires_in: expiresIn,
} = responseJson; } = responseJson;
await setSpotifyToken(accessToken); await setSpotifyToken(accessToken);
save(MY_SECURE_AUTH_STATE_KEY, accessToken);
testService(accessToken);
console.log(spotifyToken); console.log(spotifyToken);
} catch (err) { } catch (err) {
console.error(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 ( return (
<DismissKeyboard> <DismissKeyboard>
<View style={styles.container}> <View style={styles.container}>

@ -2,6 +2,18 @@ import axios from "axios";
import MusicFactory from "../../Model/factory/MusicFactory"; import MusicFactory from "../../Model/factory/MusicFactory";
import Music from "../../Model/Music"; import Music from "../../Model/Music";
import { FetchOptions, RequestHandler } from "./spotifyRequestHandler/utils"; 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 { export default class SpotifyService implements IspotifyService {
private readonly API_URL = "https://flad-api-production.up.railway.app/api/"; private readonly API_URL = "https://flad-api-production.up.railway.app/api/";
@ -154,32 +166,71 @@ export default class SpotifyService implements IspotifyService {
return ; return ;
} }
public async getSimilarTrack(musicId : string,limit? : number ,market? : string): Promise<Music[]>{ // public async getSimilarTrack(musicId : string,limit : number =1,market? : string): Promise<Music[]>{
var requestData :string = '/recommendations'; // var requestData :string = '/recommendations' +
// '?limit=' +limit+
// '&market=FR' +
// "&seed_tracks=" + musicId;
const fetchOptions: FetchOptions = { // const fetchOptions: FetchOptions = {
method: 'GET', // method: 'GET',
body: { // body: {
seed_tracks: musicId, // seed_tracks: musicId,
// market: "FR", // market: "FR",
// limit: 5, // 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<Music[]> {
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);
if (!respSimilarMusic || !respSimilarMusic.data.tracks) {
return [];
} }
};
console.log('222222222221baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros');
const respSimilarMusic = await this.spotifyRequestHandler.spotifyFetch(requestData, fetchOptions,this.token); const similars: Music[] = await Promise.all(
console.log(respSimilarMusic.status+'baaaaaaaaaaaaahhhhhhhhhhhh LAaa chp gros'); respSimilarMusic.data.tracks.map(async (trackData: any) => {
/// if respSimilarMusic == null || respSimilarMusic.data.count == 0 =>
const similars = respSimilarMusic.data.tracks.map((trackData: any) => { if (trackData.id) {
// const { id, name, artists, album } = trackData; console.log(trackData.id, "=============ouioui=================")
console.log(trackData.id); const data = await this.getMusicById(trackData.id);
// return MusicFactory.mapFromSpotifyTrack(trackData) // console.log(data, "=============nonon=================");
// const artistNames = artists.map((artist: any) => artist.name).join(', '); return data;
// 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() { async getSpotifyCredentials() {
const res = await axios.get(this.API_URL) const res = await axios.get(this.API_URL)

@ -32,7 +32,7 @@ export class RequestHandler{
}, },
data: options.body data: options.body
}); });
console.log(resp, "frfrfrfr"); // console.log(resp, "frfrfrfr");
return resp; return resp;
// if ( // if (
// // @ts-ignore // // @ts-ignore

@ -10,14 +10,8 @@ export class UserService {
return docData(userDocRef); return docData(userDocRef);
} }
async uploadName(name: string, email : string) { async uploadName(name: string, email : string) {
const user = this.auth.currentUser;
try { try {
const userDocRef = doc(this.firestore, `User/${user.uid}`);
await setDoc(userDocRef, {
name,
email
});
return true;
} catch (e) { } catch (e) {
return null; return null;
} }

Loading…
Cancel
Save