import { useHotkeys } from '@mantine/hooks'; import clsx from 'clsx'; import { AnimatePresence, LayoutGroup, motion } from 'motion/react'; import React, { MouseEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { generatePath, Link } from 'react-router-dom'; import styles from './left-controls.module.css'; import { SONG_CONTEXT_MENU_ITEMS } from '/@/renderer/features/context-menu/context-menu-items'; import { useHandleGeneralContextMenu } from '/@/renderer/features/context-menu/hooks/use-handle-context-menu'; import { AppRoute } from '/@/renderer/router/routes'; import { useAppStoreActions, useCurrentSong, useFullScreenPlayerStore, useHotkeySettings, useSetFullScreenPlayerStore, useSidebarStore, } from '/@/renderer/store'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Group } from '/@/shared/components/group/group'; import { Image } from '/@/shared/components/image/image'; import { Separator } from '/@/shared/components/separator/separator'; import { Text } from '/@/shared/components/text/text'; import { Tooltip } from '/@/shared/components/tooltip/tooltip'; import { PlaybackSelectors } from '/@/shared/constants/playback-selectors'; import { LibraryItem } from '/@/shared/types/domain-types'; export const LeftControls = () => { const { t } = useTranslation(); const { setSideBar } = useAppStoreActions(); const { expanded: isFullScreenPlayerExpanded } = useFullScreenPlayerStore(); const setFullScreenPlayerStore = useSetFullScreenPlayerStore(); const { collapsed, image } = useSidebarStore(); const hideImage = image && !collapsed; const currentSong = useCurrentSong(); const title = currentSong?.name; const artists = currentSong?.artists; const { bindings } = useHotkeySettings(); const isSongDefined = Boolean(currentSong?.id); const handleGeneralContextMenu = useHandleGeneralContextMenu( LibraryItem.SONG, SONG_CONTEXT_MENU_ITEMS, ); const handleToggleFullScreenPlayer = (e?: KeyboardEvent | MouseEvent) => { // don't toggle if right click if (e && 'button' in e && e.button === 2) { return; } e?.stopPropagation(); setFullScreenPlayerStore({ expanded: !isFullScreenPlayerExpanded }); }; const handleToggleSidebarImage = (e?: MouseEvent) => { e?.stopPropagation(); setSideBar({ image: true }); }; const handleToggleContextMenu = (e: MouseEvent) => { e.preventDefault(); e.stopPropagation(); if (isSongDefined && !isFullScreenPlayerExpanded) { handleGeneralContextMenu(e, [currentSong!]); } }; const stopPropagation = (e?: MouseEvent) => e?.stopPropagation(); useHotkeys([ [ bindings.toggleFullscreenPlayer.allowGlobal ? '' : bindings.toggleFullscreenPlayer.hotkey, handleToggleFullScreenPlayer, ], ]); return (
{!hideImage && (
{!collapsed && ( )}
)}
{title || '—'} {isSongDefined && ( handleGeneralContextMenu(e, [currentSong!])} size="xs" styles={{ root: { '--ai-size-xs': '1.15rem', }, }} variant="subtle" /> )}
{artists?.map((artist, index) => ( {index > 0 && } {artist.name || '—'} ))}
{currentSong?.album || '—'}
); };