import { CSSProperties, useCallback, useState } from 'react'; import styles from './library-command-item.module.css'; import { ItemImage } from '/@/renderer/components/item-image/item-image'; import { usePlayer } from '/@/renderer/features/player/context/player-context'; import { LONG_PRESS_PLAY_BEHAVIOR, PlayTooltip, } from '/@/renderer/features/shared/components/play-button-group'; import { usePlayButtonClick } from '/@/renderer/features/shared/hooks/use-play-button-click'; import { useCurrentServer } from '/@/renderer/store'; import { ActionIcon, ActionIconGroup } from '/@/shared/components/action-icon/action-icon'; import { Flex } from '/@/shared/components/flex/flex'; import { Text } from '/@/shared/components/text/text'; import { LibraryItem, Song } from '/@/shared/types/domain-types'; import { Play } from '/@/shared/types/types'; interface LibraryCommandItemProps { disabled?: boolean; id: string; imageId: null | string; imageUrl: null | string; isHighlighted?: boolean; itemType: LibraryItem; song?: Song; subtitle?: string; title?: string; } export const LibraryCommandItem = ({ disabled, id, imageId, imageUrl, isHighlighted, itemType, song, subtitle, title, }: LibraryCommandItemProps) => { const { addToQueueByData, addToQueueByFetch } = usePlayer(); const server = useCurrentServer(); const handlePlay = useCallback( (playType: Play) => { if (!server.id) return; // Use addToQueueByData for songs when we have the song data if (itemType === LibraryItem.SONG && song) { addToQueueByData([song], playType); } else { addToQueueByFetch(server.id, [id], itemType, playType); } }, [addToQueueByData, addToQueueByFetch, id, itemType, server.id, song], ); const handlePlayNext = usePlayButtonClick({ onClick: () => { handlePlay(Play.NEXT); }, onLongPress: () => { handlePlay(LONG_PRESS_PLAY_BEHAVIOR[Play.NEXT]); }, }); const handlePlayNow = usePlayButtonClick({ onClick: () => { handlePlay(Play.NOW); }, onLongPress: () => { handlePlay(LONG_PRESS_PLAY_BEHAVIOR[Play.NOW]); }, }); const handlePlayLast = usePlayButtonClick({ onClick: () => { handlePlay(Play.LAST); }, onLongPress: () => { handlePlay(LONG_PRESS_PLAY_BEHAVIOR[Play.LAST]); }, }); const [isHovered, setIsHovered] = useState(false); const showControls = isHighlighted || isHovered; return ( setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} style={{ height: '40px', width: '100%' }} >
{title} {subtitle}
{showControls && ( )}
); };