Skip to content

Commit 086106e

Browse files
author
Julia Miroshnichenko22
committed
addSearchComp
1 parent d42f058 commit 086106e

File tree

7 files changed

+115
-11
lines changed

7 files changed

+115
-11
lines changed

src/components/ArtistCard.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
const ArtistCard = () => {
2-
<div>ArtistCard</div>;
1+
import { useNavigate } from 'react-router-dom';
2+
3+
const ArtistCard = (track) => {
4+
const navigate = useNavigate();
5+
6+
return (
7+
<div
8+
className="flex flex-col w-[250px] p-4 bg-white/5 bg-opacity-80 backdrop-blur-sm animate-slideup rounded-lg cursor-pointer"
9+
onClick={() => navigate(`/artists/${track?.artists[0].adamid}`)}
10+
>
11+
<img alt="artist" src={track?.images?.coverart} className="w-full h-56 rounded-lg" />
12+
<p className="mt-4 font-semibold text-lg text-white truncate">{track?.subtitle}</p>
13+
</div>
14+
);
315
};
416

517
export default ArtistCard;

src/components/TopPlay.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const TopPlay = () => {
6666
<div className="w-full flex flex-col">
6767
<div className="flex flex-row justify-between items-center">
6868
<h2 className="text-white font-bold text-2xl">Top Charts</h2>
69-
<link to="/top charts">
69+
<link to="/top-charts">
7070
<p className="text-gray-300 text-base cursor-pointer">See more</p>
7171
</link>
7272
</div>

src/pages/AroundYou.jsx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1-
import React from 'react';
1+
import { useState, useEffect } from 'react';
2+
import { axios } from 'axios';
3+
import { useSelector } from 'react-redux';
24

3-
const CountryTracks = () => <div>CountryTracks</div>;
5+
import { Error, Loader, SongCard } from '../components';
6+
import {useGetSongsForCountryQuery} from '../redux/services/shazamCore';
47

5-
export default CountryTracks;
8+
const AroundYou = () => {
9+
const [country, setcountry] = useState('');
10+
const [loading, setLoading] = useState(true);
11+
const [activeSong, isPlaying] = useSelector((state) => state.player);
12+
const {data, isFetching, error} = useGetSongsForCountryQuery (country)
13+
14+
useEffect(() => {
15+
axios
16+
.get(`https://geo.ipify.org/api/v2/country?apiKey=at_RQv8NLlRvVkI4Ibti3HqadiCwQxJm`)
17+
.then((res) => setCountry(res?.data?.location?.country));
18+
.catch((err) => console.log(err));
19+
.finally(() => setLoading(false))
20+
}, [country]);
21+
22+
if(isFetching && loading) return <Loader title="Loading songs around you"/>;
23+
24+
if(error && country) return <Error/>;
25+
26+
return <div className="flex flex-col">
27+
<h2 className="font-bold text-3xl text-white text-left mt-4 mb-10">Around You <span className="font-black">{country}</span></h2>
28+
29+
<div className="flex flex-wrap sm:justify-start justify-center gap-8">
30+
{data?.map((song, i) => (
31+
<SongCard
32+
key={song.key}
33+
song={song}
34+
isPlaying={isPlaying}
35+
activeSong={activeSong}
36+
data={data}
37+
i={i}
38+
/>
39+
))}
40+
</div>
41+
</div>
42+
43+
44+
export default AroundYou;

src/pages/Search.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const Search = () => (
2-
<div>Search</div>
3-
);
1+
const Search = () => <div>Search</div>;
42

53
export default Search;

src/pages/TopArtists.jsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
const TopArtists = () => <div>TopArtists</div>;
1+
import { ArtistCard, Loader, Error} from '../components';
2+
import {useGetTopChartsQuery} from '../redux/services/shazamCore';
3+
4+
const TopArtists = () => {
5+
const {data, isFetching, error} = useGetTopChartsQuery()
6+
7+
if(isFetching) return <Loader title="Loading top charts"/>;
8+
9+
if(error) return <Error/>;
10+
11+
return <div className="flex flex-col">
12+
<h2 className="font-bold text-3xl text-white text-left mt-4 mb-10">Top Artists</h2>
13+
14+
<div className="flex flex-wrap sm:justify-start justify-center gap-8">
15+
{data?.map((track) => (
16+
<ArtistCard
17+
key={track.key}
18+
track={track}
19+
/>
20+
))}
21+
</div>
22+
</div>
23+
224

325
export default TopArtists;

src/pages/TopCharts.jsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1-
const TopCharts = () => <div>TopCharts</div>;
1+
import { useSelector } from 'react-redux';
2+
3+
import { Error, Loader, SongCard } from '../components';
4+
import {useGetTopChartsQuery} from '../redux/services/shazamCore';
5+
6+
const TopCharts = () => {
7+
const [activeSong, isPlaying] = useSelector((state) => state.player);
8+
const {data, isFetching, error} = useGetTopChartsQuery()
9+
10+
if(isFetching) return <Loader title="Loading top charts"/>;
11+
12+
if(error) return <Error/>;
13+
14+
return <div className="flex flex-col">
15+
<h2 className="font-bold text-3xl text-white text-left mt-4 mb-10">Discover Top Charts</h2>
16+
17+
<div className="flex flex-wrap sm:justify-start justify-center gap-8">
18+
{data?.map((song, i) => (
19+
<SongCard
20+
key={song.key}
21+
song={song}
22+
isPlaying={isPlaying}
23+
activeSong={activeSong}
24+
data={data}
25+
i={i}
26+
/>
27+
))}
28+
</div>
29+
</div>
30+
231

332
export default TopCharts;

src/redux/services/shazamCore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const shazamCoreApi = createApi({
2828
getArtistDetails: builder.query({
2929
query: ({ artistId }) => `/artists/details?artist_id=${artistId}`,
3030
}),
31+
getSongsForCountry: builder.query({
32+
query: (countryCode) => `/charts.country?country_code=${countryCode}`,
33+
}),
3134
}),
3235
});
3336

@@ -36,4 +39,5 @@ export const {
3639
useGetSongDetailsQuery,
3740
useGetSongRelatedQuery,
3841
useGetArtistDetailsQuery,
42+
useGetSongsForCountryQuery,
3943
} = shazamCoreApi;

0 commit comments

Comments
 (0)