feishin/src/renderer/features/sidebar/components/sidebar.tsx

291 lines
8.7 KiB
TypeScript
Raw Normal View History

2022-12-28 01:58:25 -08:00
import { Stack, Grid, Accordion, Center, Group } from '@mantine/core';
2022-12-19 15:59:14 -08:00
import { SpotlightProvider } from '@mantine/spotlight';
import { AnimatePresence, motion } from 'framer-motion';
import { BsCollection } from 'react-icons/bs';
import { Button, TextInput } from '/@/renderer/components';
import {
2022-12-28 01:58:25 -08:00
RiAlbumFill,
2022-12-19 15:59:14 -08:00
RiAlbumLine,
RiArrowDownSLine,
RiArrowLeftSLine,
RiArrowRightSLine,
2022-12-28 01:58:25 -08:00
RiDatabaseFill,
2022-12-19 15:59:14 -08:00
RiDatabaseLine,
RiDiscLine,
2022-12-28 01:58:25 -08:00
RiFlag2Line,
2022-12-19 15:59:14 -08:00
RiFolder3Line,
2022-12-28 01:58:25 -08:00
RiHome5Fill,
2022-12-19 15:59:14 -08:00
RiHome5Line,
2022-12-28 01:58:25 -08:00
RiMusicFill,
2022-12-19 15:59:14 -08:00
RiMusicLine,
RiPlayListLine,
RiSearchLine,
RiUserVoiceLine,
} from 'react-icons/ri';
2022-12-28 01:58:25 -08:00
import { useNavigate, Link, useLocation } from 'react-router-dom';
2022-12-19 15:59:14 -08:00
import styled from 'styled-components';
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
import { AppRoute } from '/@/renderer/router/routes';
import { useSidebarStore, useAppStoreActions, useCurrentSong } from '/@/renderer/store';
import { fadeIn } from '/@/renderer/styles';
const SidebarContainer = styled.div`
height: 100%;
max-height: calc(100vh - 85px); // Account for and playerbar
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)`
-webkit-app-region: drag;
`;
export const Sidebar = () => {
const navigate = useNavigate();
2022-12-28 01:58:25 -08:00
const location = useLocation();
2022-12-19 15:59:14 -08:00
const sidebar = useSidebarStore();
const { setSidebar } = useAppStoreActions();
const imageUrl = useCurrentSong()?.imageUrl;
const showImage = sidebar.image;
return (
<SidebarContainer>
<Stack
justify="space-between"
spacing={0}
sx={{ height: '100%' }}
>
<Stack
sx={{
maxHeight: showImage ? `calc(100% - ${sidebar.leftWidth})` : '100%',
}}
>
<ActionsContainer p={10}>
<Grid.Col span={8}>
<SpotlightProvider actions={[]}>
<TextInput
disabled
readOnly
icon={<RiSearchLine />}
placeholder="Search"
rightSectionWidth={90}
// onClick={() => openSpotlight()}
/>
</SpotlightProvider>
</Grid.Col>
<Grid.Col span={4}>
<Group
grow
spacing={5}
>
<Button
px={5}
sx={{ color: 'var(--titlebar-fg)' }}
variant="default"
onClick={() => navigate(-1)}
>
<RiArrowLeftSLine size={20} />
</Button>
<Button
px={5}
sx={{ color: 'var(--titlebar-fg)' }}
variant="default"
onClick={() => navigate(1)}
>
<RiArrowRightSLine size={20} />
</Button>
</Group>
</Grid.Col>
</ActionsContainer>
<Stack
spacing={0}
sx={{ overflowY: 'auto' }}
>
<SidebarItem to={AppRoute.HOME}>
<Group>
2022-12-28 01:58:25 -08:00
{location.pathname === AppRoute.HOME ? (
<RiHome5Fill size={15} />
) : (
<RiHome5Line size={15} />
)}
2022-12-19 15:59:14 -08:00
Home
</Group>
</SidebarItem>
<Accordion
multiple
styles={{
2022-12-28 01:58:25 -08:00
control: {
'&:hover': { background: 'none', color: 'var(--sidebar-fg-hover)' },
color: 'var(--sidebar-fg)',
transition: 'color 0.2s ease-in-out',
},
item: { borderBottom: 'none', color: 'var(--sidebar-fg)' },
itemTitle: { color: 'var(--sidebar-fg)' },
2022-12-19 15:59:14 -08:00
panel: {
2022-12-28 01:58:25 -08:00
marginLeft: '1rem',
2022-12-19 15:59:14 -08:00
},
}}
value={sidebar.expanded}
onChange={(e) => setSidebar({ expanded: e })}
>
<Accordion.Item value="library">
<Accordion.Control p="1rem">
<Group>
2022-12-28 01:58:25 -08:00
{location.pathname.includes('/library/') ? (
<RiDatabaseFill size={15} />
) : (
<RiDatabaseLine size={15} />
)}
2022-12-19 15:59:14 -08:00
Library
</Group>
</Accordion.Control>
<Accordion.Panel>
<SidebarItem to={AppRoute.LIBRARY_ALBUMS}>
<Group>
2022-12-28 01:58:25 -08:00
{location.pathname === AppRoute.LIBRARY_ALBUMS ? (
<RiAlbumFill />
) : (
<RiAlbumLine />
)}
2022-12-19 15:59:14 -08:00
Albums
</Group>
</SidebarItem>
<SidebarItem to={AppRoute.LIBRARY_SONGS}>
<Group>
2022-12-28 01:58:25 -08:00
{location.pathname === AppRoute.LIBRARY_SONGS ? (
<RiMusicFill />
) : (
<RiMusicLine />
)}
2022-12-19 15:59:14 -08:00
Tracks
</Group>
</SidebarItem>
2022-12-30 21:04:06 -08:00
<SidebarItem to={AppRoute.LIBRARY_ALBUMARTISTS}>
2022-12-19 15:59:14 -08:00
<Group>
<RiUserVoiceLine />
2022-12-30 21:04:06 -08:00
Album Artists
2022-12-19 15:59:14 -08:00
</Group>
</SidebarItem>
2022-12-28 01:58:25 -08:00
<SidebarItem
disabled
to={AppRoute.LIBRARY_FOLDERS}
>
<Group>
<RiFlag2Line />
Genres
</Group>
</SidebarItem>
2022-12-19 15:59:14 -08:00
<SidebarItem
disabled
to={AppRoute.LIBRARY_FOLDERS}
>
<Group>
<RiFolder3Line />
Folders
</Group>
</SidebarItem>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item value="collections">
<Accordion.Control
disabled
p="1rem"
>
<Group>
<BsCollection size={15} />
Collections
</Group>
</Accordion.Control>
<Accordion.Panel />
</Accordion.Item>
<Accordion.Item value="playlists">
<Accordion.Control
disabled
p="1rem"
>
<Group>
<RiPlayListLine size={15} />
Playlists
</Group>
</Accordion.Control>
<Accordion.Panel />
</Accordion.Item>
</Accordion>
</Stack>
</Stack>
<AnimatePresence
initial={false}
mode="wait"
>
{showImage && (
<ImageContainer
key="sidebar-image"
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
height={sidebar.leftWidth}
initial={{ opacity: 0, y: 200 }}
to={AppRoute.NOW_PLAYING}
transition={{ duration: 0.3, ease: 'easeInOut' }}
>
{imageUrl ? (
<SidebarImage
loading="eager"
src={imageUrl}
/>
) : (
<Center sx={{ background: 'var(--placeholder-bg)', height: '100%' }}>
<RiDiscLine
color="var(--placeholder-fg)"
size={50}
/>
</Center>
)}
<Button
compact
opacity={0.8}
radius={100}
size="sm"
sx={{ position: 'absolute', right: 5, top: 5 }}
tooltip={{ label: 'Collapse' }}
variant="default"
onClick={(e) => {
e.preventDefault();
setSidebar({ image: false });
}}
>
<RiArrowDownSLine
color="white"
size={20}
/>
</Button>
</ImageContainer>
)}
</AnimatePresence>
</Stack>
</SidebarContainer>
);
};