import clsx from 'clsx'; import { AnimatePresence, motion } from 'motion/react'; import { CSSProperties, MouseEvent, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './sidebar.module.css'; import { useItemImageUrl } from '/@/renderer/components/item-image/item-image'; import { ContextMenuController } from '/@/renderer/features/context-menu/context-menu-controller'; import { useRadioStore } from '/@/renderer/features/radio/hooks/use-radio-player'; import { ActionBar } from '/@/renderer/features/sidebar/components/action-bar'; import { ServerSelector } from '/@/renderer/features/sidebar/components/server-selector'; import { SidebarCollectionList } from '/@/renderer/features/sidebar/components/sidebar-collection-list'; import { SidebarIcon } from '/@/renderer/features/sidebar/components/sidebar-icon'; import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item'; import { SidebarPlaylistList, SidebarSharedPlaylistList, } from '/@/renderer/features/sidebar/components/sidebar-playlist-list'; import { useAppStore, useAppStoreActions, useFullScreenPlayerStore, usePlayerSong, useSetFullScreenPlayerStore, } from '/@/renderer/store'; import { SidebarItemType, useSidebarItems, useSidebarPlaylistList, useWindowSettings, } from '/@/renderer/store/settings.store'; import { Accordion } from '/@/shared/components/accordion/accordion'; import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Group } from '/@/shared/components/group/group'; import { ImageUnloader } from '/@/shared/components/image/image'; import { ScrollArea } from '/@/shared/components/scroll-area/scroll-area'; import { Text } from '/@/shared/components/text/text'; import { Tooltip } from '/@/shared/components/tooltip/tooltip'; import { LibraryItem } from '/@/shared/types/domain-types'; import { Platform } from '/@/shared/types/types'; export const Sidebar = () => { const { t } = useTranslation(); const sidebarPlaylistList = useSidebarPlaylistList(); const translatedSidebarItemMap = useMemo( () => ({ Albums: t('page.sidebar.albums', { postProcess: 'titleCase' }), Artists: t('page.sidebar.albumArtists', { postProcess: 'titleCase' }), 'Artists-all': t('page.sidebar.artists', { postProcess: 'titleCase' }), Collections: t('page.sidebar.collections', { postProcess: 'titleCase' }), Favorites: t('page.sidebar.favorites', { postProcess: 'titleCase' }), Folders: t('page.sidebar.folders', { postProcess: 'titleCase' }), Genres: t('page.sidebar.genres', { postProcess: 'titleCase' }), Home: t('page.sidebar.home', { postProcess: 'titleCase' }), 'Now Playing': t('page.sidebar.nowPlaying', { postProcess: 'titleCase' }), Playlists: t('page.sidebar.playlists', { postProcess: 'titleCase' }), Radio: t('page.sidebar.radio', { postProcess: 'titleCase' }), Search: t('page.sidebar.search', { postProcess: 'titleCase' }), Settings: t('page.sidebar.settings', { postProcess: 'titleCase' }), Tracks: t('page.sidebar.tracks', { postProcess: 'titleCase' }), }), [t], ); const sidebarItems = useSidebarItems(); const { windowBarStyle } = useWindowSettings(); const sidebarImageEnabled = useAppStore((state) => state.sidebar.image); const isRadioPlaying = useRadioStore((state) => state.isPlaying); const showImage = sidebarImageEnabled && !isRadioPlaying; const sidebarItemsWithRoute: SidebarItemType[] = useMemo(() => { if (!sidebarItems) return []; const items = sidebarItems .filter((item) => !item.disabled) .map((item) => ({ ...item, label: translatedSidebarItemMap[item.id as keyof typeof translatedSidebarItemMap] ?? item.label, })); return items; }, [sidebarItems, translatedSidebarItemMap]); /* Library accordion: only items with a route (exclude Collections section) */ const libraryItemsWithRoute = useMemo( () => sidebarItemsWithRoute.filter((item) => item.id !== 'Collections' && item.route), [sidebarItemsWithRoute], ); const isCustomWindowBar = windowBarStyle === Platform.WINDOWS || windowBarStyle === Platform.MACOS; return (
); }; const SidebarImage = () => { const { t } = useTranslation(); const leftWidth = useAppStore((state) => state.sidebar.leftWidth); const { setSideBar } = useAppStoreActions(); const currentSong = usePlayerSong(); const imageUrl = useItemImageUrl({ id: currentSong?.imageId || undefined, itemType: LibraryItem.SONG, serverId: currentSong?._serverId, type: 'sidebar', }); const isSongDefined = Boolean(currentSong?.id); const setFullScreenPlayerStore = useSetFullScreenPlayerStore(); const { expanded: isFullScreenPlayerExpanded } = useFullScreenPlayerStore(); const expandFullScreenPlayer = () => { setFullScreenPlayerStore({ expanded: !isFullScreenPlayerExpanded }); }; const handleToggleContextMenu = (e: MouseEvent