import React from 'react'; import { Center, Group } from '@mantine/core'; import { openContextModal } from '@mantine/modals'; import { motion, AnimatePresence, LayoutGroup } from 'framer-motion'; import { RiArrowUpSLine, RiDiscLine, RiMore2Fill } from 'react-icons/ri'; import { generatePath, Link } from 'react-router-dom'; import styled from 'styled-components'; import { Button, DropdownMenu, Text } from '/@/renderer/components'; import { AppRoute } from '/@/renderer/router/routes'; import { useAppStoreActions, useAppStore, useCurrentSong } from '/@/renderer/store'; import { fadeIn } from '/@/renderer/styles'; import { useCreateFavorite, useDeleteFavorite } from '/@/renderer/features/shared'; import { LibraryItem } from '/@/renderer/api/types'; const LeftControlsContainer = styled.div` display: flex; width: 100%; height: 100%; padding-left: 1rem; `; const ImageWrapper = styled.div` display: flex; align-items: center; justify-content: center; padding: 1rem 1rem 1rem 0; `; const MetadataStack = styled(motion.div)` display: flex; flex-direction: column; gap: 0; justify-content: center; width: 100%; overflow: hidden; `; const Image = styled(motion(Link))` width: 60px; height: 60px; filter: drop-shadow(0 0 5px rgb(0, 0, 0, 100%)); ${fadeIn}; animation: fadein 0.2s ease-in-out; button { display: none; } &:hover button { display: block; } `; const PlayerbarImage = styled.img` width: 100%; height: 100%; object-fit: cover; `; const LineItem = styled.div<{ $secondary?: boolean }>` display: inline-block; width: 95%; max-width: 20vw; overflow: hidden; color: ${(props) => props.$secondary && 'var(--main-fg-secondary)'}; line-height: 1.3; white-space: nowrap; text-overflow: ellipsis; a { color: ${(props) => props.$secondary && 'var(--text-secondary)'}; } `; export const LeftControls = () => { const { setSidebar } = useAppStoreActions(); const hideImage = useAppStore((state) => state.sidebar.image); const currentSong = useCurrentSong(); const title = currentSong?.name; const artists = currentSong?.artists; const isSongDefined = Boolean(currentSong?.id); const openAddToPlaylistModal = () => { openContextModal({ innerProps: { songId: [currentSong?.id], }, modal: 'addToPlaylist', size: 'md', title: 'Add to playlist', }); }; const addToFavoritesMutation = useCreateFavorite(); const removeFromFavoritesMutation = useDeleteFavorite(); const handleAddToFavorites = () => { if (!isSongDefined || !currentSong) return; addToFavoritesMutation.mutate({ query: { id: [currentSong.id], type: LibraryItem.SONG, }, }); }; const handleRemoveFromFavorites = () => { if (!isSongDefined || !currentSong) return; removeFromFavoritesMutation.mutate({ query: { id: [currentSong.id], type: LibraryItem.SONG, }, }); }; return ( {!hideImage && ( {currentSong?.imageUrl ? ( ) : ( <>
)}
)}
{title || '—'} {isSongDefined && ( Add to playlist Add to favorites Remove from favorites )} {artists?.map((artist, index) => ( {index > 0 && ( , )}{' '} {artist.name || '—'} ))} {currentSong?.album || '—'}
); };