2023-06-03 05:36:38 -07:00
|
|
|
import { MouseEvent, useMemo } from 'react';
|
|
|
|
|
import { Box, Center, Divider, Group, Stack } from '@mantine/core';
|
2022-12-31 12:40:11 -08:00
|
|
|
import { closeAllModals, openModal } from '@mantine/modals';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { AnimatePresence, motion } from 'framer-motion';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { IconType } from 'react-icons';
|
2022-12-19 15:59:14 -08:00
|
|
|
import {
|
2022-12-31 12:40:11 -08:00
|
|
|
RiAddFill,
|
2022-12-28 01:58:25 -08:00
|
|
|
RiAlbumFill,
|
2022-12-19 15:59:14 -08:00
|
|
|
RiAlbumLine,
|
|
|
|
|
RiArrowDownSLine,
|
|
|
|
|
RiDiscLine,
|
2023-06-03 05:36:38 -07:00
|
|
|
RiFlag2Fill,
|
|
|
|
|
RiFlagLine,
|
|
|
|
|
RiFolder3Fill,
|
2022-12-19 15:59:14 -08:00
|
|
|
RiFolder3Line,
|
2023-05-10 18:20:04 -07:00
|
|
|
RiHome6Fill,
|
|
|
|
|
RiHome6Line,
|
2023-01-06 01:48:56 -08:00
|
|
|
RiListUnordered,
|
2023-01-06 10:46:09 -08:00
|
|
|
RiMusic2Fill,
|
|
|
|
|
RiMusic2Line,
|
2023-06-03 05:36:38 -07:00
|
|
|
RiPlayLine,
|
|
|
|
|
RiSearchFill,
|
2022-12-31 12:40:11 -08:00
|
|
|
RiUserVoiceFill,
|
2022-12-19 15:59:14 -08:00
|
|
|
RiUserVoiceLine,
|
2023-06-03 05:36:38 -07:00
|
|
|
RiSearchLine,
|
|
|
|
|
RiPlayFill,
|
|
|
|
|
RiSettings2Line,
|
|
|
|
|
RiSettings2Fill,
|
|
|
|
|
RiPlayListLine,
|
|
|
|
|
RiPlayListFill,
|
2022-12-19 15:59:14 -08:00
|
|
|
} from 'react-icons/ri';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { generatePath, Link, useLocation } from 'react-router-dom';
|
2022-12-19 15:59:14 -08:00
|
|
|
import styled from 'styled-components';
|
2023-06-03 05:36:38 -07:00
|
|
|
import {
|
|
|
|
|
SidebarItemType,
|
|
|
|
|
useGeneralSettings,
|
|
|
|
|
useWindowSettings,
|
|
|
|
|
} from '../../../store/settings.store';
|
|
|
|
|
import { LibraryItem, PlaylistListSort, ServerType, SortOrder } from '/@/renderer/api/types';
|
|
|
|
|
import { Button, MotionStack, Spinner, Tooltip } from '/@/renderer/components';
|
|
|
|
|
import { CreatePlaylistForm, usePlaylistList } from '/@/renderer/features/playlists';
|
|
|
|
|
import { ActionBar } from '/@/renderer/features/sidebar/components/action-bar';
|
2023-02-05 18:59:39 -08:00
|
|
|
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
|
2023-06-03 05:36:38 -07:00
|
|
|
import { SidebarPlaylistList } from '/@/renderer/features/sidebar/components/sidebar-playlist-list';
|
|
|
|
|
import { useContainerQuery } from '/@/renderer/hooks';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2023-01-15 21:58:25 -08:00
|
|
|
import {
|
|
|
|
|
useAppStoreActions,
|
|
|
|
|
useCurrentServer,
|
2023-06-03 05:36:38 -07:00
|
|
|
useCurrentSong,
|
2023-03-28 14:19:23 -07:00
|
|
|
useFullScreenPlayerStore,
|
2023-06-03 05:36:38 -07:00
|
|
|
useSetFullScreenPlayerStore,
|
|
|
|
|
useSidebarStore,
|
2023-01-15 21:58:25 -08:00
|
|
|
} from '/@/renderer/store';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { fadeIn } from '/@/renderer/styles';
|
2023-03-29 00:31:09 -07:00
|
|
|
import { Platform } from '/@/renderer/types';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-03-29 00:31:09 -07:00
|
|
|
const SidebarContainer = styled.div<{ windowBarStyle: Platform }>`
|
2022-12-19 15:59:14 -08:00
|
|
|
height: 100%;
|
2023-03-29 00:31:09 -07:00
|
|
|
max-height: ${(props) =>
|
2023-05-24 17:35:04 +02:00
|
|
|
props.windowBarStyle === Platform.WEB || props.windowBarStyle === Platform.LINUX
|
2023-03-29 00:31:09 -07:00
|
|
|
? 'calc(100vh - 149px)'
|
|
|
|
|
: 'calc(100vh - 179px)'}; // Playerbar (90px), titlebar (65px), windowbar (30px)
|
2022-12-19 15:59:14 -08:00
|
|
|
user-select: none;
|
|
|
|
|
`;
|
|
|
|
|
|
2023-03-28 14:19:23 -07:00
|
|
|
const ImageContainer = styled(motion.div)<{ height: string }>`
|
2022-12-19 15:59:14 -08:00
|
|
|
position: relative;
|
|
|
|
|
height: ${(props) => props.height};
|
2023-05-10 18:20:04 -07:00
|
|
|
cursor: pointer;
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
${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);
|
|
|
|
|
`;
|
|
|
|
|
|
2023-06-03 05:36:38 -07:00
|
|
|
const sidebarItemMap = {
|
|
|
|
|
[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: RiFlagLine,
|
|
|
|
|
},
|
|
|
|
|
[generatePath(AppRoute.SEARCH, { itemType: LibraryItem.SONG })]: {
|
|
|
|
|
activeIcon: RiSearchFill,
|
|
|
|
|
icon: RiSearchLine,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.SETTINGS]: {
|
|
|
|
|
activeIcon: RiSettings2Fill,
|
|
|
|
|
icon: RiSettings2Line,
|
|
|
|
|
},
|
|
|
|
|
[AppRoute.NOW_PLAYING]: {
|
|
|
|
|
activeIcon: RiPlayFill,
|
|
|
|
|
icon: RiPlayLine,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
export const Sidebar = () => {
|
2022-12-28 01:58:25 -08:00
|
|
|
const location = useLocation();
|
2022-12-19 15:59:14 -08:00
|
|
|
const sidebar = useSidebarStore();
|
2023-03-28 23:59:51 -07:00
|
|
|
const { setSideBar } = useAppStoreActions();
|
2023-03-30 06:44:33 -07:00
|
|
|
const { windowBarStyle } = useWindowSettings();
|
2023-06-14 00:45:10 -07:00
|
|
|
const { sidebarPlaylistList } = useGeneralSettings();
|
2022-12-19 15:59:14 -08:00
|
|
|
const imageUrl = useCurrentSong()?.imageUrl;
|
2023-01-15 21:58:25 -08:00
|
|
|
const server = useCurrentServer();
|
2023-01-06 01:03:58 -08:00
|
|
|
|
|
|
|
|
const upsizedImageUrl = imageUrl
|
|
|
|
|
?.replace(/size=\d+/, 'size=300')
|
|
|
|
|
.replace(/width=\d+/, 'width=300')
|
|
|
|
|
.replace(/height=\d+/, 'height=300');
|
|
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
const showImage = sidebar.image;
|
2022-12-31 12:40:11 -08:00
|
|
|
|
|
|
|
|
const handleCreatePlaylistModal = (e: MouseEvent<HTMLButtonElement>) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
|
|
openModal({
|
|
|
|
|
children: <CreatePlaylistForm onCancel={() => closeAllModals()} />,
|
2023-05-21 17:53:43 -07:00
|
|
|
size: server?.type === ServerType?.NAVIDROME ? 'xl' : 'sm',
|
2022-12-31 12:40:11 -08:00
|
|
|
title: 'Create Playlist',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-05 18:59:39 -08:00
|
|
|
const playlistsQuery = usePlaylistList({
|
2023-04-30 22:01:52 -07:00
|
|
|
query: {
|
|
|
|
|
sortBy: PlaylistListSort.NAME,
|
|
|
|
|
sortOrder: SortOrder.ASC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
2023-02-05 18:59:39 -08:00
|
|
|
});
|
|
|
|
|
|
2023-03-28 14:19:23 -07:00
|
|
|
const setFullScreenPlayerStore = useSetFullScreenPlayerStore();
|
|
|
|
|
const { expanded: isFullScreenPlayerExpanded } = useFullScreenPlayerStore();
|
|
|
|
|
const expandFullScreenPlayer = () => {
|
|
|
|
|
setFullScreenPlayerStore({ expanded: !isFullScreenPlayerExpanded });
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-07 22:47:23 -08:00
|
|
|
const cq = useContainerQuery({ sm: 300 });
|
|
|
|
|
|
2023-06-03 05:36:38 -07:00
|
|
|
const { sidebarItems } = useGeneralSettings();
|
|
|
|
|
|
|
|
|
|
const sidebarItemsWithRoute: (SidebarItemType & {
|
|
|
|
|
activeIcon: IconType;
|
|
|
|
|
icon: IconType;
|
|
|
|
|
})[] = useMemo(() => {
|
|
|
|
|
if (!sidebarItems) return [];
|
|
|
|
|
|
|
|
|
|
const items = sidebarItems
|
|
|
|
|
.filter((item) => !item.disabled)
|
|
|
|
|
.map((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
...sidebarItemMap[item.route as keyof typeof sidebarItemMap],
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
}, [sidebarItems]);
|
|
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
return (
|
2023-03-29 00:31:09 -07:00
|
|
|
<SidebarContainer
|
|
|
|
|
ref={cq.ref}
|
|
|
|
|
windowBarStyle={windowBarStyle}
|
|
|
|
|
>
|
|
|
|
|
<ActionBar />
|
2022-12-19 15:59:14 -08:00
|
|
|
<Stack
|
2022-12-31 12:40:11 -08:00
|
|
|
h="100%"
|
2022-12-19 15:59:14 -08:00
|
|
|
justify="space-between"
|
|
|
|
|
spacing={0}
|
|
|
|
|
>
|
2023-01-06 14:27:31 -08:00
|
|
|
<MotionStack
|
2023-02-08 03:44:37 -08:00
|
|
|
h="100%"
|
2023-01-06 14:27:31 -08:00
|
|
|
layout="position"
|
2022-12-31 12:40:11 -08:00
|
|
|
spacing={0}
|
|
|
|
|
sx={{ maxHeight: showImage ? `calc(100% - ${sidebar.leftWidth})` : '100%' }}
|
2022-12-19 15:59:14 -08:00
|
|
|
>
|
2023-02-05 18:59:39 -08:00
|
|
|
<Stack spacing={0}>
|
2023-06-03 05:36:38 -07:00
|
|
|
{sidebarItemsWithRoute.map((item) => (
|
|
|
|
|
<SidebarItem
|
|
|
|
|
key={`sidebar-${item.route}`}
|
|
|
|
|
to={item.route}
|
|
|
|
|
>
|
|
|
|
|
<Group spacing="sm">
|
|
|
|
|
{location.pathname === item.route ? (
|
|
|
|
|
<item.activeIcon size="1.1em" />
|
|
|
|
|
) : (
|
|
|
|
|
<item.icon size="1.1em" />
|
|
|
|
|
)}
|
|
|
|
|
{item.label}
|
|
|
|
|
</Group>
|
|
|
|
|
</SidebarItem>
|
|
|
|
|
))}
|
2023-02-05 18:59:39 -08:00
|
|
|
</Stack>
|
2023-02-07 22:47:23 -08:00
|
|
|
<Divider
|
|
|
|
|
mx="1rem"
|
|
|
|
|
my="0.5rem"
|
|
|
|
|
/>
|
2023-06-14 00:45:10 -07:00
|
|
|
{sidebarPlaylistList && (
|
|
|
|
|
<>
|
|
|
|
|
<Group
|
|
|
|
|
position="apart"
|
|
|
|
|
pt="1rem"
|
|
|
|
|
px="1.5rem"
|
2023-02-05 18:59:39 -08:00
|
|
|
>
|
2023-06-14 00:45:10 -07:00
|
|
|
<Group>
|
|
|
|
|
<Box
|
|
|
|
|
fw="600"
|
|
|
|
|
sx={{ fontSize: '1.2rem' }}
|
|
|
|
|
>
|
|
|
|
|
Playlists
|
|
|
|
|
</Box>
|
|
|
|
|
{playlistsQuery.isLoading && <Spinner />}
|
|
|
|
|
</Group>
|
|
|
|
|
<Group spacing="sm">
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
size="md"
|
|
|
|
|
tooltip={{ label: 'Create playlist', openDelay: 500 }}
|
|
|
|
|
variant="default"
|
|
|
|
|
onClick={handleCreatePlaylistModal}
|
|
|
|
|
>
|
|
|
|
|
<RiAddFill size="1em" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
component={Link}
|
|
|
|
|
size="md"
|
|
|
|
|
to={AppRoute.PLAYLISTS}
|
|
|
|
|
tooltip={{ label: 'Playlist list', openDelay: 500 }}
|
|
|
|
|
variant="default"
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
|
|
|
|
<RiListUnordered size="1em" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</Group>
|
|
|
|
|
<SidebarPlaylistList data={playlistsQuery.data} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2023-01-06 14:27:31 -08:00
|
|
|
</MotionStack>
|
2022-12-19 15:59:14 -08:00
|
|
|
<AnimatePresence
|
|
|
|
|
initial={false}
|
2023-01-06 14:27:31 -08:00
|
|
|
mode="popLayout"
|
2022-12-19 15:59:14 -08:00
|
|
|
>
|
|
|
|
|
{showImage && (
|
|
|
|
|
<ImageContainer
|
|
|
|
|
key="sidebar-image"
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
2023-01-06 14:27:31 -08:00
|
|
|
exit={{ opacity: 0, y: 200 }}
|
2022-12-19 15:59:14 -08:00
|
|
|
height={sidebar.leftWidth}
|
|
|
|
|
initial={{ opacity: 0, y: 200 }}
|
2023-03-28 14:19:23 -07:00
|
|
|
role="button"
|
2022-12-19 15:59:14 -08:00
|
|
|
transition={{ duration: 0.3, ease: 'easeInOut' }}
|
2023-03-28 14:19:23 -07:00
|
|
|
onClick={expandFullScreenPlayer}
|
2022-12-19 15:59:14 -08:00
|
|
|
>
|
2023-05-21 19:47:46 -07:00
|
|
|
<Tooltip
|
|
|
|
|
label="Toggle fullscreen player"
|
|
|
|
|
openDelay={500}
|
|
|
|
|
>
|
|
|
|
|
{upsizedImageUrl ? (
|
|
|
|
|
<SidebarImage
|
|
|
|
|
loading="eager"
|
|
|
|
|
src={upsizedImageUrl}
|
2022-12-19 15:59:14 -08:00
|
|
|
/>
|
2023-05-21 19:47:46 -07:00
|
|
|
) : (
|
|
|
|
|
<Center sx={{ background: 'var(--placeholder-bg)', height: '100%' }}>
|
|
|
|
|
<RiDiscLine
|
|
|
|
|
color="var(--placeholder-fg)"
|
|
|
|
|
size={50}
|
|
|
|
|
/>
|
|
|
|
|
</Center>
|
|
|
|
|
)}
|
|
|
|
|
</Tooltip>
|
2022-12-19 15:59:14 -08:00
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
opacity={0.8}
|
|
|
|
|
radius={100}
|
2023-01-30 01:36:36 -08:00
|
|
|
size="md"
|
2023-05-10 18:20:04 -07:00
|
|
|
sx={{ cursor: 'default', position: 'absolute', right: 5, top: 5 }}
|
2023-01-06 01:59:37 -08:00
|
|
|
tooltip={{ label: 'Collapse', openDelay: 500 }}
|
2022-12-19 15:59:14 -08:00
|
|
|
variant="default"
|
|
|
|
|
onClick={(e) => {
|
2023-03-28 14:19:23 -07:00
|
|
|
e.stopPropagation();
|
2023-03-28 23:59:51 -07:00
|
|
|
setSideBar({ image: false });
|
2022-12-19 15:59:14 -08:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowDownSLine
|
|
|
|
|
color="white"
|
|
|
|
|
size={20}
|
|
|
|
|
/>
|
|
|
|
|
</Button>
|
|
|
|
|
</ImageContainer>
|
|
|
|
|
)}
|
|
|
|
|
</AnimatePresence>
|
|
|
|
|
</Stack>
|
|
|
|
|
</SidebarContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|