import { MouseEvent } from 'react'; import { Stack, Grid, Accordion, Center, Group, Divider, Box } from '@mantine/core'; import { closeAllModals, openModal } from '@mantine/modals'; import { AnimatePresence, motion } from 'framer-motion'; import { Button, DropdownMenu, MotionStack, Spinner, TextInput } from '/@/renderer/components'; import { RiAddFill, RiAlbumFill, RiAlbumLine, RiArrowDownSLine, RiArrowLeftSLine, RiArrowRightSLine, RiDatabaseFill, RiDatabaseLine, RiDiscLine, RiFlag2Line, RiFolder3Line, RiHome5Fill, RiHome5Line, RiListUnordered, RiMenuFill, RiMusic2Fill, RiMusic2Line, RiSearchLine, RiUserVoiceFill, RiUserVoiceLine, } from 'react-icons/ri'; import { useNavigate, Link, useLocation } from 'react-router-dom'; import styled from 'styled-components'; import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item'; import { AppRoute } from '/@/renderer/router/routes'; import { useSidebarStore, useAppStoreActions, useCurrentSong, useCurrentServer, } from '/@/renderer/store'; import { fadeIn } from '/@/renderer/styles'; import { CreatePlaylistForm, usePlaylistList } from '/@/renderer/features/playlists'; import { PlaylistListSort, ServerType, SortOrder } from '/@/renderer/api/types'; import { SidebarPlaylistList } from '/@/renderer/features/sidebar/components/sidebar-playlist-list'; import { AppMenu } from '/@/renderer/features/titlebar/components/app-menu'; import { useContainerQuery } from '/@/renderer/hooks'; const SidebarContainer = styled.div` height: 100%; max-height: calc(100vh - 149px); // Playerbar (90px), titlebar (65px) user-select: none; `; const ImageContainer = styled(motion(Link))<{ height: string }>` position: relative; height: ${(props) => props.height}; ${fadeIn}; animation: fadein 0.2s ease-in-out; button { display: none; } &:hover button { display: block; } `; const SidebarImage = styled.img` width: 100%; height: 100%; object-fit: cover; background: var(--placeholder-bg); `; const ActionsContainer = styled(Grid)` height: 65px; padding: 1rem; -webkit-app-region: drag; input { -webkit-app-region: no-drag; } `; export const Sidebar = () => { const navigate = useNavigate(); const location = useLocation(); const sidebar = useSidebarStore(); const { setSidebar } = useAppStoreActions(); const imageUrl = useCurrentSong()?.imageUrl; const server = useCurrentServer(); const upsizedImageUrl = imageUrl ?.replace(/size=\d+/, 'size=300') .replace(/width=\d+/, 'width=300') .replace(/height=\d+/, 'height=300'); const showImage = sidebar.image; const handleCreatePlaylistModal = (e: MouseEvent) => { e.stopPropagation(); openModal({ children: closeAllModals()} />, size: server?.type === ServerType?.NAVIDROME ? 'lg' : 'sm', title: 'Create Playlist', }); }; const playlistsQuery = usePlaylistList({ sortBy: PlaylistListSort.NAME, sortOrder: SortOrder.ASC, startIndex: 0, }); const cq = useContainerQuery({ sm: 300 }); return ( } placeholder="Search" size="md" /> {location.pathname === AppRoute.HOME ? ( ) : ( )} Home setSidebar({ expanded: e })} > {location.pathname.includes('/library/') ? ( ) : ( )} Library {location.pathname === AppRoute.LIBRARY_ALBUMS ? ( ) : ( )} Albums {location.pathname === AppRoute.LIBRARY_SONGS ? ( ) : ( )} Tracks {location.pathname === AppRoute.LIBRARY_ALBUM_ARTISTS ? ( ) : ( )} Album Artists Genres Folders Playlists {playlistsQuery.isLoading && } {showImage && ( {upsizedImageUrl ? ( ) : (
)}
)}
); };