-
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
b41486f
commit 1ff58e1
Showing
2 changed files
with
47 additions
and
3 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,44 @@ | ||
const Search = () => ( | ||
<div>Search</div> | ||
); | ||
import { useSelector } from 'react-redux'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { Error, Loader, SongCard } from '../components'; | ||
import { useGetSongsBySearchQuery } from '../redux/services/shazamCore'; | ||
|
||
const Search = () => { | ||
const { searchTerm } = useParams(); | ||
const { activeSong, isPlaying } = useSelector((state) => state.player); | ||
const { data, isFetching, error } = useGetSongsBySearchQuery(searchTerm); | ||
|
||
const songs = data?.tracks?.hits?.map((song) => song.track); | ||
|
||
if (isFetching) { | ||
return <Loader title="Loading top charts" />; | ||
} | ||
|
||
if (error) { | ||
return <Error />; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<h2 className="font-bold text-3xl text-white text-lfet mt-4 mb-10"> | ||
Showing result for <span className="font-black">{searchTerm}</span> | ||
</h2> | ||
|
||
<div className="flex flex-wrap sm:justify-start justify-center gap-8"> | ||
{songs?.map((song, i) => ( | ||
<SongCard | ||
key={song.key} | ||
song={song} | ||
isPlaying={isPlaying} | ||
activeSong={activeSong} | ||
data={songs} | ||
i={i} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Search; |
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