diff --git a/src/FLAD/redux/actions/spotActions.tsx b/src/FLAD/redux/actions/spotActions.tsx index 41fbfa3..331b6bd 100644 --- a/src/FLAD/redux/actions/spotActions.tsx +++ b/src/FLAD/redux/actions/spotActions.tsx @@ -1,5 +1,6 @@ import Music from "../../Model/Music"; import { Spot } from "../../Model/Spot"; +import { spotifyTypes } from "../types/spotifyTypes"; import {spotTypes} from "../types/spotTypes"; export const setSpotList = (spotList: Spot[]) => { @@ -11,7 +12,7 @@ export const setSpotList = (spotList: Spot[]) => { export const setUserCurrentMusic = (currentMusic: Music) => { return { - type: spotTypes.FETCH_SPOT, + type: spotifyTypes.GET_USER_CURRENT_MUSIC, playload: currentMusic, }; } \ No newline at end of file diff --git a/src/FLAD/redux/reducers/appReducer.tsx b/src/FLAD/redux/reducers/appReducer.tsx index 2d6bc04..1be550f 100644 --- a/src/FLAD/redux/reducers/appReducer.tsx +++ b/src/FLAD/redux/reducers/appReducer.tsx @@ -5,24 +5,18 @@ import { favoritesTypes } from "../types/favoritesTypes"; import { spotifyTypes } from "../types/spotifyTypes"; import { spotTypes } from "../types/spotTypes"; let tmpMusic: 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 initialState = { - spot: [] as Spot[], - favoriteMusic: tmpMusic, - userCurrentMusic : null - } + spot: [] as Spot[], + favoriteMusic: tmpMusic, + userCurrentMusic : null +} - - const appReducer = (state = initialState, action : any) => { - switch (action.type) { +const appReducer = (state = initialState, action : any) => { + switch (action.type) { case favoritesTypes.GET_FAVORITE_MUSICS: return {...state, favoriteMusic: action.playload}; case favoritesTypes.ADD_FAVORITE_MUSICS: @@ -37,7 +31,7 @@ const initialState = { return {...state, userCurrentMusic: action.payload}; default: return state; - } } +} - export default appReducer \ No newline at end of file +export default appReducer \ No newline at end of file diff --git a/src/FLAD/redux/thunk/authThunk.tsx b/src/FLAD/redux/thunk/authThunk.tsx index 519aed5..1e51f32 100644 --- a/src/FLAD/redux/thunk/authThunk.tsx +++ b/src/FLAD/redux/thunk/authThunk.tsx @@ -108,7 +108,7 @@ export const getRefreshToken = () => { //@ts-ignore return async dispatch => { try { - let userToken : string | null = await SecureStore.getItemAsync(key); + let userToken : string | null = await SecureStore.getItemAsync('key'); if (userToken) { console.log("==========key2 =================="); diff --git a/src/FLAD/screens/MusicDetail.tsx b/src/FLAD/screens/MusicDetail.tsx index 867bb1d..6fad95e 100644 --- a/src/FLAD/screens/MusicDetail.tsx +++ b/src/FLAD/screens/MusicDetail.tsx @@ -31,7 +31,7 @@ const halfPi = Math.PI/2; //@ts-ignore const MusicDetail = ({ route }) => { const music : Music = route.params.music; - const [currentspot] = useState(music); + const [currentspot, setCurrentSpot] = useState(music); const [simularMusic, setSimularMusic] = useState([]); const [isPlaying, setIsPlaying] = useState(false); const [sound, setSound] = useState(null); @@ -41,26 +41,34 @@ const MusicDetail = ({ route }) => { const [testtoken, setTesttoken] = useState('') const sheet = async () => { - const data = await SecureStore.getItemAsync('MySecureAuthStateKey'); - setTesttoken(data) + SecureStore.getItemAsync('MySecureAuthStateKey').then(result => { setTesttoken(result)}); + } - sheet(); - const getSimilarTrack = async () => { - const service = new SpotifyService(testtoken); - var simularMusic = await service.getSimilarTrack(currentspot.id, 5, 'FR'); + + useEffect(() => { + sheet(); + getSimilarTrack(); + }, [testtoken]); + + // const getSimilarTrack = async () => { + // const service = new SpotifyService(testtoken); + // const simularMusic = await service.getSimilarTrack(currentspot.id, 5, 'FR'); + // console.log("suggesstd", simularMusic) + // setSimularMusic(simularMusic); + + // } + const getSimilarTrack = async () => { try { - Promise.all(simularMusic).then((resolvedMusic) => { - setSimularMusic(resolvedMusic); - }); + const service = new SpotifyService(testtoken); + const simularMusic = await service.getSimilarTrack(currentspot.id, 5, 'FR'); + console.log("suggesstd", simularMusic); + setSimularMusic(simularMusic); } catch (error) { - console.log(error.message); + console.error('Error ================ in getSimilarTrack', error); + // Handle the error here. } - } - - useEffect(() => { - getSimilarTrack(); - }, []); + } const handlePlaySound = async () => { if (sound === null) { @@ -194,14 +202,13 @@ const MusicDetail = ({ route }) => { height: 64, borderRadius: 8, opacity: 0.86 ,backgroundColor: '#0B0606', }}> {/* */} - Partager cette music + Partagedr cette music {/* Dans ma collection 2 */} - {testtoken} {simularMusic.length !== 0 && ( {(props) => ( diff --git a/src/FLAD/screens/Register.tsx b/src/FLAD/screens/Register.tsx index 84c9c52..3e5b988 100644 --- a/src/FLAD/screens/Register.tsx +++ b/src/FLAD/screens/Register.tsx @@ -193,6 +193,15 @@ const scopes = scopesArr.join(' '); console.log("===================repoonce========================="); console.log(respSimilar); console.log("============================================"); + console.log("==============Test Service 4 ============"); + const respCurrent= await serviceTest.getUserCurrentMusic(); + console.log("===================repoonce========================="); + console.log(respCurrent); + console.log("============================================"); + console.log("==============Test Service 5 ============"); + const respRecently= await serviceTest.getUserRecentlyPlayedMusic(); + console.log("===================repoonce========================="); + console.log(respRecently); console.log("============================================"); } catch (error) { diff --git a/src/FLAD/services/spotify/spotify.service.ts b/src/FLAD/services/spotify/spotify.service.ts index 49eb369..51226cc 100644 --- a/src/FLAD/services/spotify/spotify.service.ts +++ b/src/FLAD/services/spotify/spotify.service.ts @@ -204,31 +204,36 @@ export default class SpotifyService implements IspotifyService { // 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); - - if (!respSimilarMusic || !respSimilarMusic.data.tracks) { - return []; + const requestData: string = '/recommendations/' + + '?limit=' + limit + + '&market=FR' + + '&seed_tracks=' + musicId; + console.log(musicId, "=============ouioui=================") + var respSimilarMusic; + try { + console.log( "=======================1=========",requestData,this.token ) + respSimilarMusic= await this.spotifyRequestHandler.spotifyFetch(requestData, {}, this.token); + } catch (error) { + console.log(error, "===================================spot Service"); } - - 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; - } - }) - ); + if (!respSimilarMusic || !respSimilarMusic.data.tracks) { + return []; + } + const similars: Music[] = await Promise.all( + respSimilarMusic.data.tracks.map(async (trackData: any) => { + if (trackData.id !=undefined) { + const data = await this.getMusicById(trackData.id); + return data; + } + + }) + + ) + return similars.filter((music: Music | undefined) => !!music) as Music[]; + + + // return similars; - return similars.filter((music: Music | undefined) => !!music) as Music[]; } diff --git a/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx b/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx index 519f1bf..da5d9b2 100644 --- a/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx +++ b/src/FLAD/services/spotify/spotifyRequestHandler/utils.tsx @@ -1,4 +1,4 @@ -import axios, { AxiosError } from "axios"; +import axios, { AxiosError, AxiosResponse } from "axios"; export type Methods = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'; @@ -19,7 +19,7 @@ export class RequestHandler{ return this._version; } - public async spotifyFetch(url: string, options: FetchOptions = {}, token: string) { + public async spotifyFetch(url: string, options: FetchOptions = {}, token: string) : Promise> { console.log(options+ "sds============="); const resp = await axios({ url: `https://api.spotify.com/${this.version}${url}`, @@ -32,6 +32,7 @@ export class RequestHandler{ }, data: options.body }); + console.log(")))))))))))))))))))",resp.request, "(((((((((((((((((((("); // console.log(resp, "frfrfrfr"); return resp; // if (