diff --git a/src/pages/AroundYou.jsx b/src/pages/AroundYou.jsx index 6f838a5..a214792 100644 --- a/src/pages/AroundYou.jsx +++ b/src/pages/AroundYou.jsx @@ -1,5 +1,55 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import { useSelector } from 'react-redux'; -const CountryTracks = () =>
CountryTracks
; +import { Error, Loader, SongCard } from '../components'; +import { useGetSongsByCountryQuery } from '../redux/services/shazamCore'; + +const CountryTracks = () => { + const [country, setCountry] = useState(''); + const [loading, setLoading] = useState(true); + const { activeSong, isPlaying } = useSelector((state) => state.player); + const { data, isFetching, error } = useGetSongsByCountryQuery(country); + + useEffect(() => { + // at_LWaIX7s2ECGPjSwomyBlqhS6hQC9G + axios + .get( + 'https://geo.ipify.org/api/v2/country?apiKey=at_LWaIX7s2ECGPjSwomyBlqhS6hQC9G' + ) + .then((res) => setCountry(res?.data?.location?.country)) + .catch(() => {}) + .finally(() => setLoading(false)); + }, [country]); + + if (isFetching && loading) { + return ; + } + + if (error && country) { + return ; + } + + return ( +
+

+ Around you {country} +

+ +
+ {data?.map((song, i) => ( + + ))} +
+
+ ); +}; export default CountryTracks; diff --git a/src/redux/services/shazamCore.js b/src/redux/services/shazamCore.js index 9850178..6f04c7d 100644 --- a/src/redux/services/shazamCore.js +++ b/src/redux/services/shazamCore.js @@ -24,6 +24,9 @@ export const shazamCoreApi = createApi({ getArtistDetails: builder.query({ query: (artistId) => `/artists/details?artist_id=${artistId}`, }), + getSongsByCountry: builder.query({ + query: (country) => `/charts/country?country_code=${country}`, + }), }), }); @@ -32,4 +35,5 @@ export const { useGetSongDetailsQuery, useGetSongRelatedQuery, useGetArtistDetailsQuery, + useGetSongsByCountryQuery, } = shazamCoreApi;