Skip to content

Commit

Permalink
feat: show playlist after created
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul Andrade committed Mar 6, 2022
1 parent c9c9427 commit 5b96579
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/features/playlist/playlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,42 @@ export const Playlist = ({
artists,
usePlaylist = usePlaylistMutation
}: PlaylistProps) => {
const { mutate, isLoading } = usePlaylist()
const { mutate, isLoading, data } = usePlaylist()

const playlistCreated = data?.data
const text = playlistCreated?.id
? 'Randomfy playlist was created.'
: 'You can make a randomfy playlist!'

return artists.length === MAX_RANDOM_FY_ITEMS ? (
<Fragment>
<div className="p-4 max-w-5xl my-0 mx-auto">
<PrimaryText>You can make a randomfy playlist!</PrimaryText>
<PrimaryText>{text}</PrimaryText>
</div>
<div
className={`flex justify-center p-4 pb-12 ${
isLoading ? 'animate-pulse' : ''
}`}
>
<PrimaryButton
ariaLabel="create playlist button"
onClick={() => mutate(artists)}
>
Create Playlist
</PrimaryButton>
{playlistCreated?.id ? (
<iframe
className="max-w-5xl my-0 mx-auto rounded-xl"
src={`https://open.spotify.com/embed/playlist/${playlistCreated.id}?utm_source=generator&theme=0`}
width="100%"
height="380"
frameBorder="0"
allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
></iframe>
) : (
<PrimaryButton
ariaLabel="create playlist button"
onClick={() => mutate(artists)}
>
Create Playlist
</PrimaryButton>
)}
</div>

<Toaster
toastOptions={{
error: {
Expand Down
2 changes: 1 addition & 1 deletion src/queries/use-playlist-mutation/use-playlist-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const usePlaylistMutation = () => {
Array<Recommendation>
>((data) => createPlaylist(data), {
onSuccess: () => {
toast.success('Playlist create with success!')
toast.success('Playlist was created with success!')
},
onError: () => {
toast.error('Something wrong with the Playlist! ')
Expand Down

1 comment on commit 5b96579

@vercel
Copy link

@vercel vercel bot commented on 5b96579 Mar 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.