2023-09-22 15:33:28 -07:00
|
|
|
import { Group, UnstyledButton } from '@mantine/core';
|
2023-05-10 18:20:04 -07:00
|
|
|
import { motion } from 'framer-motion';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import { IconType } from 'react-icons';
|
2023-05-10 18:20:04 -07:00
|
|
|
import {
|
2023-07-01 19:10:05 -07:00
|
|
|
RiUserVoiceLine,
|
|
|
|
|
RiMenuFill,
|
|
|
|
|
RiFolder3Line,
|
|
|
|
|
RiPlayListLine,
|
|
|
|
|
RiAlbumLine,
|
|
|
|
|
RiHome6Line,
|
|
|
|
|
RiMusic2Line,
|
|
|
|
|
RiHome6Fill,
|
|
|
|
|
RiAlbumFill,
|
|
|
|
|
RiMusic2Fill,
|
|
|
|
|
RiUserVoiceFill,
|
|
|
|
|
RiFlag2Fill,
|
|
|
|
|
RiFolder3Fill,
|
|
|
|
|
RiPlayListFill,
|
|
|
|
|
RiSearchLine,
|
|
|
|
|
RiSearchFill,
|
|
|
|
|
RiPlayFill,
|
|
|
|
|
RiPlayLine,
|
|
|
|
|
RiSettings2Fill,
|
|
|
|
|
RiSettings2Line,
|
|
|
|
|
RiFlag2Line,
|
2023-09-22 15:33:28 -07:00
|
|
|
RiArrowLeftSLine,
|
|
|
|
|
RiArrowRightSLine,
|
2023-05-10 18:20:04 -07:00
|
|
|
} from 'react-icons/ri';
|
2023-09-22 15:33:28 -07:00
|
|
|
import { generatePath, NavLink, useNavigate } from 'react-router-dom';
|
2023-05-10 18:20:04 -07:00
|
|
|
import styled from 'styled-components';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { LibraryItem } from '/@/renderer/api/types';
|
2023-05-10 18:20:04 -07:00
|
|
|
import { DropdownMenu, ScrollArea } from '/@/renderer/components';
|
|
|
|
|
import { CollapsedSidebarItem } from '/@/renderer/features/sidebar/components/collapsed-sidebar-item';
|
|
|
|
|
import { AppMenu } from '/@/renderer/features/titlebar/components/app-menu';
|
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { SidebarItemType, useGeneralSettings, useWindowSettings } from '/@/renderer/store';
|
2023-05-10 18:20:04 -07:00
|
|
|
import { Platform } from '/@/renderer/types';
|
2023-09-22 15:33:28 -07:00
|
|
|
import { CollapsedSidebarButton } from '/@/renderer/features/sidebar/components/collapsed-sidebar-button';
|
2023-05-10 18:20:04 -07:00
|
|
|
|
2023-09-22 02:34:57 -07:00
|
|
|
const SidebarContainer = styled(motion.div)<{ $windowBarStyle: Platform }>`
|
2023-07-01 19:10:05 -07:00
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
height: 100%;
|
|
|
|
|
max-height: ${(props) =>
|
2023-09-22 02:34:57 -07:00
|
|
|
props.$windowBarStyle === Platform.WEB || props.$windowBarStyle === Platform.LINUX
|
2023-07-01 19:10:05 -07:00
|
|
|
? 'calc(100vh - 149px)'
|
2023-09-15 20:42:38 -07:00
|
|
|
: 'calc(100vh - 119px)'};
|
2023-07-01 19:10:05 -07:00
|
|
|
user-select: none;
|
2023-05-10 18:20:04 -07:00
|
|
|
`;
|
|
|
|
|
|
2023-06-03 05:36:38 -07:00
|
|
|
const sidebarItemMap = {
|
2023-07-01 19:10:05 -07:00
|
|
|
[AppRoute.HOME]: {
|
|
|
|
|
activeIcon: RiHome6Fill,
|
|
|
|
|
icon: RiHome6Line,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.LIBRARY_ALBUMS]: {
|
|
|
|
|
activeIcon: RiAlbumFill,
|
|
|
|
|
icon: RiAlbumLine,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.LIBRARY_ALBUM_ARTISTS]: {
|
|
|
|
|
activeIcon: RiUserVoiceFill,
|
|
|
|
|
icon: RiUserVoiceLine,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.PLAYLISTS]: {
|
|
|
|
|
activeIcon: RiPlayListFill,
|
|
|
|
|
icon: RiPlayListLine,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.LIBRARY_SONGS]: {
|
|
|
|
|
activeIcon: RiMusic2Fill,
|
|
|
|
|
icon: RiMusic2Line,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.LIBRARY_FOLDERS]: {
|
|
|
|
|
activeIcon: RiFolder3Fill,
|
|
|
|
|
icon: RiFolder3Line,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.LIBRARY_GENRES]: {
|
|
|
|
|
activeIcon: RiFlag2Fill,
|
|
|
|
|
icon: RiFlag2Line,
|
|
|
|
|
},
|
|
|
|
|
[generatePath(AppRoute.SEARCH, { itemType: LibraryItem.SONG })]: {
|
|
|
|
|
activeIcon: RiSearchFill,
|
|
|
|
|
icon: RiSearchLine,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.SETTINGS]: {
|
|
|
|
|
activeIcon: RiSettings2Fill,
|
|
|
|
|
icon: RiSettings2Line,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.NOW_PLAYING]: {
|
|
|
|
|
activeIcon: RiPlayFill,
|
|
|
|
|
icon: RiPlayLine,
|
|
|
|
|
},
|
2023-06-03 05:36:38 -07:00
|
|
|
};
|
|
|
|
|
|
2023-05-10 18:20:04 -07:00
|
|
|
export const CollapsedSidebar = () => {
|
2023-09-22 15:33:28 -07:00
|
|
|
const navigate = useNavigate();
|
2023-07-01 19:10:05 -07:00
|
|
|
const { windowBarStyle } = useWindowSettings();
|
|
|
|
|
const { sidebarItems } = useGeneralSettings();
|
2023-06-03 05:36:38 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const sidebarItemsWithRoute: (SidebarItemType & {
|
|
|
|
|
activeIcon: IconType;
|
|
|
|
|
icon: IconType;
|
|
|
|
|
})[] = useMemo(() => {
|
|
|
|
|
if (!sidebarItems) return [];
|
2023-06-03 05:36:38 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const items = sidebarItems
|
|
|
|
|
.filter((item) => !item.disabled)
|
|
|
|
|
.map((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
...sidebarItemMap[item.route as keyof typeof sidebarItemMap],
|
|
|
|
|
}));
|
2023-06-03 05:36:38 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return items;
|
|
|
|
|
}, [sidebarItems]);
|
2023-05-10 18:20:04 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2023-09-22 02:34:57 -07:00
|
|
|
<SidebarContainer $windowBarStyle={windowBarStyle}>
|
2023-07-01 19:10:05 -07:00
|
|
|
<ScrollArea
|
|
|
|
|
scrollHideDelay={0}
|
|
|
|
|
scrollbarSize={8}
|
|
|
|
|
>
|
2023-09-22 15:33:28 -07:00
|
|
|
<Group
|
|
|
|
|
grow
|
|
|
|
|
spacing={0}
|
|
|
|
|
style={{
|
|
|
|
|
borderRight: 'var(--sidebar-border)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CollapsedSidebarButton
|
|
|
|
|
component={UnstyledButton}
|
|
|
|
|
onClick={() => navigate(-1)}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowLeftSLine size="22" />
|
|
|
|
|
</CollapsedSidebarButton>
|
|
|
|
|
<CollapsedSidebarButton
|
|
|
|
|
component={UnstyledButton}
|
|
|
|
|
onClick={() => navigate(1)}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowRightSLine size="22" />
|
|
|
|
|
</CollapsedSidebarButton>
|
|
|
|
|
</Group>
|
2023-07-01 19:10:05 -07:00
|
|
|
<DropdownMenu position="right-start">
|
|
|
|
|
<DropdownMenu.Target>
|
|
|
|
|
<CollapsedSidebarItem
|
|
|
|
|
activeIcon={<RiMenuFill size="25" />}
|
|
|
|
|
component={UnstyledButton}
|
|
|
|
|
icon={<RiMenuFill size="25" />}
|
|
|
|
|
label="Menu"
|
|
|
|
|
/>
|
|
|
|
|
</DropdownMenu.Target>
|
|
|
|
|
<DropdownMenu.Dropdown>
|
|
|
|
|
<AppMenu />
|
|
|
|
|
</DropdownMenu.Dropdown>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
{sidebarItemsWithRoute.map((item) => (
|
|
|
|
|
<CollapsedSidebarItem
|
|
|
|
|
key={item.id}
|
|
|
|
|
activeIcon={<item.activeIcon size="25" />}
|
|
|
|
|
component={NavLink}
|
|
|
|
|
icon={<item.icon size="25" />}
|
|
|
|
|
label={item.label}
|
|
|
|
|
route={item.route}
|
|
|
|
|
to={item.route}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</ScrollArea>
|
|
|
|
|
</SidebarContainer>
|
|
|
|
|
);
|
2023-05-10 18:20:04 -07:00
|
|
|
};
|