-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stardust
committed
Nov 24, 2022
1 parent
415c4f0
commit a5c5773
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = () => <div>CountryTracks</div>; | ||
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 <Loader title="Loading songs around you" />; | ||
} | ||
|
||
if (error && country) { | ||
return <Error />; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<h2 className="font-bold text-3xl text-white text-lfet mt-4 mb-10"> | ||
Around you <span className="font-black">{country}</span> | ||
</h2> | ||
|
||
<div className="flex flex-wrap sm:justify-start justify-center gap-8"> | ||
{data?.map((song, i) => ( | ||
<SongCard | ||
key={song.key} | ||
song={song} | ||
isPlaying={isPlaying} | ||
activeSong={activeSong} | ||
data={data} | ||
i={i} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CountryTracks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters