feishin/src/renderer/layouts/default-layout/right-sidebar.tsx

151 lines
4.9 KiB
TypeScript
Raw Normal View History

2023-05-31 01:13:54 -07:00
import { AnimatePresence, motion, Variants } from 'framer-motion';
import { forwardRef, Ref } from 'react';
import { useLocation } from 'react-router';
import styled from 'styled-components';
import { DrawerPlayQueue, SidebarPlayQueue } from '/@/renderer/features/now-playing';
2023-05-31 01:13:54 -07:00
import { ResizeHandle } from '/@/renderer/features/shared';
import { AppRoute } from '/@/renderer/router/routes';
import { useGeneralSettings, useSidebarStore, useWindowSettings } from '/@/renderer/store';
2025-05-20 19:23:36 -07:00
import { Platform } from '/@/shared/types/types';
2023-05-31 01:13:54 -07:00
const RightSidebarContainer = styled(motion.aside)`
2023-07-01 19:10:05 -07:00
position: relative;
grid-area: right-sidebar;
height: 100%;
background: var(--sidebar-bg);
border-left: var(--sidebar-border);
.current-song-cell:not(.current-playlist-song-cell) svg {
display: none;
}
2023-05-31 01:13:54 -07:00
`;
const queueSidebarVariants: Variants = {
2023-07-01 19:10:05 -07:00
closed: (rightWidth) => ({
transition: { duration: 0.5 },
width: rightWidth,
x: 1000,
zIndex: 120,
}),
open: (rightWidth) => ({
transition: {
duration: 0.5,
ease: 'anticipate',
},
width: rightWidth,
x: 0,
zIndex: 120,
}),
2023-05-31 01:13:54 -07:00
};
const QueueDrawer = styled(motion.div)`
2023-07-01 19:10:05 -07:00
background: var(--main-bg);
border: 3px solid var(--generic-border-color);
border-radius: 10px;
2023-05-31 01:13:54 -07:00
`;
const queueDrawerVariants: Variants = {
2023-07-01 19:10:05 -07:00
closed: (windowBarStyle) => ({
height:
windowBarStyle === Platform.WINDOWS || Platform.MACOS
? 'calc(100vh - 205px)'
: 'calc(100vh - 175px)',
position: 'absolute',
right: 0,
top: '75px',
transition: {
duration: 0.4,
ease: 'anticipate',
},
width: '450px',
x: '50vw',
}),
open: (windowBarStyle) => ({
boxShadow: '0px 0px 10px 0px rgba(0, 0, 0, 0.8)',
height:
windowBarStyle === Platform.WINDOWS || Platform.MACOS
? 'calc(100vh - 205px)'
: 'calc(100vh - 175px)',
position: 'absolute',
right: '20px',
top: '75px',
transition: {
damping: 10,
delay: 0,
duration: 0.4,
ease: 'anticipate',
mass: 0.5,
},
width: '450px',
x: 0,
zIndex: 120,
}),
2023-05-31 01:13:54 -07:00
};
interface RightSidebarProps {
2023-07-01 19:10:05 -07:00
isResizing: boolean;
startResizing: (direction: 'left' | 'right') => void;
2023-05-31 01:13:54 -07:00
}
export const RightSidebar = forwardRef(
2023-07-01 19:10:05 -07:00
(
{ isResizing: isResizingRight, startResizing }: RightSidebarProps,
ref: Ref<HTMLDivElement>,
) => {
const { windowBarStyle } = useWindowSettings();
const { rightExpanded, rightWidth } = useSidebarStore();
2023-07-01 19:10:05 -07:00
const { sideQueueType } = useGeneralSettings();
const location = useLocation();
const showSideQueue = rightExpanded && location.pathname !== AppRoute.NOW_PLAYING;
2023-05-31 01:13:54 -07:00
2023-07-01 19:10:05 -07:00
return (
<AnimatePresence
initial={false}
key="queue-sidebar"
2023-07-01 19:10:05 -07:00
mode="sync"
presenceAffectsLayout
2023-07-01 19:10:05 -07:00
>
{showSideQueue && (
<>
{sideQueueType === 'sideQueue' ? (
<RightSidebarContainer
animate="open"
custom={rightWidth}
exit="closed"
id="sidebar-queue"
initial="closed"
key="queue-sidebar"
2023-07-01 19:10:05 -07:00
variants={queueSidebarVariants}
>
<ResizeHandle
$isResizing={isResizingRight}
$placement="left"
2023-07-01 19:10:05 -07:00
onMouseDown={(e) => {
e.preventDefault();
startResizing('right');
}}
ref={ref}
2023-07-01 19:10:05 -07:00
/>
<SidebarPlayQueue />
</RightSidebarContainer>
) : (
<QueueDrawer
animate="open"
custom={windowBarStyle}
exit="closed"
id="drawer-queue"
initial="closed"
key="queue-drawer"
2023-07-01 19:10:05 -07:00
variants={queueDrawerVariants}
>
<DrawerPlayQueue />
</QueueDrawer>
)}
</>
)}
</AnimatePresence>
);
},
2023-05-31 01:13:54 -07:00
);