A heart on every song, album and artist, in the player bar and the full-screen player, and a Favourites page with the songs, albums and artists, newest first. The heart changes at once and goes back if the server refuses. Hearts are only for music of this server: a friend's song has none. - FavoriteButton, useIsFavorite and useSetFavorite - /favorites page, a Favourites item in the Library group of the menu, on the Library page and in the phone Library tab
30 lines
964 B
TypeScript
30 lines
964 B
TypeScript
import { Heart } from 'lucide-react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useIsFavorite, useSetFavorite, type FavoriteKind } from '@/api/favorites'
|
|
import { Button } from '@/components/ui/button'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface Props {
|
|
kind: FavoriteKind
|
|
id: number
|
|
className?: string
|
|
}
|
|
|
|
/** A heart that marks a song, an album or an artist of this server as a favourite, and takes it back. */
|
|
export default function FavoriteButton({ kind, id, className }: Props) {
|
|
const { t } = useTranslation()
|
|
const on = useIsFavorite(kind, id)
|
|
const set = useSetFavorite(kind, id)
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className={className}
|
|
aria-pressed={on}
|
|
aria-label={t(on ? 'favorites.remove' : 'favorites.add')}
|
|
onClick={() => set.mutate(!on)}
|
|
>
|
|
<Heart aria-hidden="true" fill={on ? 'currentColor' : 'none'} className={cn(on && 'text-primary')} />
|
|
</Button>
|
|
)
|
|
}
|