|
@ -1,9 +1,8 @@ |
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
import { Icon } from 'rsuite'; |
|
|
import { Icon } from 'rsuite'; |
|
|
import { useHistory } from 'react-router-dom'; |
|
|
import { useHistory } from 'react-router-dom'; |
|
|
import { useQueryClient } from 'react-query'; |
|
|
|
|
|
import cacheImage from '../shared/cacheImage'; |
|
|
import cacheImage from '../shared/cacheImage'; |
|
|
import { getAlbum, getPlaylist, star, unstar, getAllArtistSongs } from '../../api/api'; |
|
|
import { getAlbum, getPlaylist, getAllArtistSongs } from '../../api/api'; |
|
|
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; |
|
|
import { useAppDispatch, useAppSelector } from '../../redux/hooks'; |
|
|
import { appendPlayQueue, fixPlayer2Index, setPlayQueue } from '../../redux/playQueueSlice'; |
|
|
import { appendPlayQueue, fixPlayer2Index, setPlayQueue } from '../../redux/playQueueSlice'; |
|
|
import { isCached } from '../../shared/utils'; |
|
|
import { isCached } from '../../shared/utils'; |
|
@ -39,12 +38,12 @@ const Card = ({ |
|
|
size, |
|
|
size, |
|
|
cacheImages, |
|
|
cacheImages, |
|
|
cachePath, |
|
|
cachePath, |
|
|
|
|
|
handleFavorite, |
|
|
...rest |
|
|
...rest |
|
|
}: any) => { |
|
|
}: any) => { |
|
|
const history = useHistory(); |
|
|
const history = useHistory(); |
|
|
const dispatch = useAppDispatch(); |
|
|
const dispatch = useAppDispatch(); |
|
|
const playQueue = useAppSelector((state) => state.playQueue); |
|
|
const playQueue = useAppSelector((state) => state.playQueue); |
|
|
const queryClient = useQueryClient(); |
|
|
|
|
|
|
|
|
|
|
|
const handleClick = () => { |
|
|
const handleClick = () => { |
|
|
history.push(url); |
|
|
history.push(url); |
|
@ -102,30 +101,6 @@ const Card = ({ |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleFavorite = async () => { |
|
|
|
|
|
if (!rest.details.starred) { |
|
|
|
|
|
await star(rest.details.id, 'album'); |
|
|
|
|
|
} else { |
|
|
|
|
|
await unstar(rest.details.id, 'album'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await queryClient.refetchQueries(['artist'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
}); |
|
|
|
|
|
await queryClient.refetchQueries(['album'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
}); |
|
|
|
|
|
await queryClient.refetchQueries(['starred'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
}); |
|
|
|
|
|
await queryClient.refetchQueries(['playlist'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
}); |
|
|
|
|
|
await queryClient.refetchQueries(['search'], { |
|
|
|
|
|
active: true, |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleOpenModal = () => { |
|
|
const handleOpenModal = () => { |
|
|
dispatch( |
|
|
dispatch( |
|
|
addModalPage({ |
|
|
addModalPage({ |
|
@ -185,7 +160,7 @@ const Card = ({ |
|
|
/> |
|
|
/> |
|
|
{playClick.type !== 'playlist' && ( |
|
|
{playClick.type !== 'playlist' && ( |
|
|
<FavoriteOverlayButton |
|
|
<FavoriteOverlayButton |
|
|
onClick={handleFavorite} |
|
|
onClick={() => handleFavorite(rest.details)} |
|
|
size={size <= 160 ? 'xs' : 'sm'} |
|
|
size={size <= 160 ? 'xs' : 'sm'} |
|
|
icon={<Icon icon={rest.details.starred ? 'heart' : 'heart-o'} />} |
|
|
icon={<Icon icon={rest.details.starred ? 'heart' : 'heart-o'} />} |
|
|
/> |
|
|
/> |
|
|