mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-17 14:10:14 +02:00
Refactor sidebar playlist
This commit is contained in:
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { RiAddBoxFill, RiAddCircleFill, RiPlayFill } from 'react-icons/ri';
|
import { RiAddBoxFill, RiAddCircleFill, RiPlayFill } from 'react-icons/ri';
|
||||||
import { generatePath } from 'react-router';
|
import { generatePath } from 'react-router';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { LibraryItem } from '/@/renderer/api/types';
|
import { LibraryItem, PlaylistListSort, SortOrder } from '/@/renderer/api/types';
|
||||||
import { Button, Text } from '/@/renderer/components';
|
import { Button, Text } from '/@/renderer/components';
|
||||||
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
||||||
import { usePlaylistList } from '/@/renderer/features/playlists';
|
import { usePlaylistList } from '/@/renderer/features/playlists';
|
||||||
@@ -14,11 +14,7 @@ import { Play } from '/@/renderer/types';
|
|||||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||||
import { FixedSizeList, ListChildComponentProps } from 'react-window';
|
import { FixedSizeList, ListChildComponentProps } from 'react-window';
|
||||||
import { useHideScrollbar } from '/@/renderer/hooks';
|
import { useHideScrollbar } from '/@/renderer/hooks';
|
||||||
import { useGeneralSettings } from '/@/renderer/store';
|
import { useCurrentServer, useGeneralSettings } from '/@/renderer/store';
|
||||||
|
|
||||||
interface SidebarPlaylistListProps {
|
|
||||||
data: ReturnType<typeof usePlaylistList>['data'];
|
|
||||||
}
|
|
||||||
|
|
||||||
const PlaylistRow = ({ index, data, style }: ListChildComponentProps) => {
|
const PlaylistRow = ({ index, data, style }: ListChildComponentProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -121,10 +117,20 @@ const PlaylistRow = ({ index, data, style }: ListChildComponentProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
|
export const SidebarPlaylistList = () => {
|
||||||
const { isScrollbarHidden, hideScrollbarElementProps } = useHideScrollbar(0);
|
const { isScrollbarHidden, hideScrollbarElementProps } = useHideScrollbar(0);
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
||||||
const { defaultFullPlaylist } = useGeneralSettings();
|
const { defaultFullPlaylist } = useGeneralSettings();
|
||||||
|
const server = useCurrentServer();
|
||||||
|
|
||||||
|
const playlistsQuery = usePlaylistList({
|
||||||
|
query: {
|
||||||
|
sortBy: PlaylistListSort.NAME,
|
||||||
|
sortOrder: SortOrder.ASC,
|
||||||
|
startIndex: 0,
|
||||||
|
},
|
||||||
|
serverId: server?.id,
|
||||||
|
});
|
||||||
|
|
||||||
const [rect, setRect] = useState({
|
const [rect, setRect] = useState({
|
||||||
height: 0,
|
height: 0,
|
||||||
@@ -150,9 +156,9 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
|
|||||||
return {
|
return {
|
||||||
defaultFullPlaylist,
|
defaultFullPlaylist,
|
||||||
handlePlay: handlePlayPlaylist,
|
handlePlay: handlePlayPlaylist,
|
||||||
items: data?.items,
|
items: playlistsQuery?.data?.items,
|
||||||
};
|
};
|
||||||
}, [data?.items, defaultFullPlaylist, handlePlayPlaylist]);
|
}, [playlistsQuery?.data?.items, defaultFullPlaylist, handlePlayPlaylist]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@@ -168,7 +174,7 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => {
|
|||||||
: 'overlay-scrollbar'
|
: 'overlay-scrollbar'
|
||||||
}
|
}
|
||||||
height={debounced.height}
|
height={debounced.height}
|
||||||
itemCount={data?.items?.length || 0}
|
itemCount={playlistsQuery?.data?.items?.length || 0}
|
||||||
itemData={memoizedItemData}
|
itemData={memoizedItemData}
|
||||||
itemSize={25}
|
itemSize={25}
|
||||||
overscanCount={20}
|
overscanCount={20}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MouseEvent, useMemo } from 'react';
|
|
||||||
import { Box, Center, Divider, Group, Stack } from '@mantine/core';
|
import { Box, Center, Divider, Group, Stack } from '@mantine/core';
|
||||||
import { closeAllModals, openModal } from '@mantine/modals';
|
import { closeAllModals, openModal } from '@mantine/modals';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
|
import { MouseEvent, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { RiAddFill, RiArrowDownSLine, RiDiscLine, RiListUnordered } from 'react-icons/ri';
|
import { RiAddFill, RiArrowDownSLine, RiDiscLine, RiListUnordered } from 'react-icons/ri';
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
@@ -11,9 +11,9 @@ import {
|
|||||||
useGeneralSettings,
|
useGeneralSettings,
|
||||||
useWindowSettings,
|
useWindowSettings,
|
||||||
} from '../../../store/settings.store';
|
} from '../../../store/settings.store';
|
||||||
import { PlaylistListSort, ServerType, SortOrder } from '/@/renderer/api/types';
|
import { ServerType } from '/@/renderer/api/types';
|
||||||
import { Button, MotionStack, Spinner, Tooltip } from '/@/renderer/components';
|
import { Button, MotionStack, Tooltip } from '/@/renderer/components';
|
||||||
import { CreatePlaylistForm, usePlaylistList } from '/@/renderer/features/playlists';
|
import { CreatePlaylistForm } from '/@/renderer/features/playlists';
|
||||||
import { ActionBar } from '/@/renderer/features/sidebar/components/action-bar';
|
import { ActionBar } from '/@/renderer/features/sidebar/components/action-bar';
|
||||||
import { SidebarIcon } from '/@/renderer/features/sidebar/components/sidebar-icon';
|
import { SidebarIcon } from '/@/renderer/features/sidebar/components/sidebar-icon';
|
||||||
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
|
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
|
||||||
@@ -110,15 +110,6 @@ export const Sidebar = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const playlistsQuery = usePlaylistList({
|
|
||||||
query: {
|
|
||||||
sortBy: PlaylistListSort.NAME,
|
|
||||||
sortOrder: SortOrder.ASC,
|
|
||||||
startIndex: 0,
|
|
||||||
},
|
|
||||||
serverId: server?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const setFullScreenPlayerStore = useSetFullScreenPlayerStore();
|
const setFullScreenPlayerStore = useSetFullScreenPlayerStore();
|
||||||
const { expanded: isFullScreenPlayerExpanded } = useFullScreenPlayerStore();
|
const { expanded: isFullScreenPlayerExpanded } = useFullScreenPlayerStore();
|
||||||
const expandFullScreenPlayer = () => {
|
const expandFullScreenPlayer = () => {
|
||||||
@@ -198,7 +189,6 @@ export const Sidebar = () => {
|
|||||||
>
|
>
|
||||||
{t('page.sidebar.playlists', { postProcess: 'titleCase' })}
|
{t('page.sidebar.playlists', { postProcess: 'titleCase' })}
|
||||||
</Box>
|
</Box>
|
||||||
{playlistsQuery.isLoading && <Spinner />}
|
|
||||||
</Group>
|
</Group>
|
||||||
<Group spacing="sm">
|
<Group spacing="sm">
|
||||||
<Button
|
<Button
|
||||||
@@ -233,7 +223,7 @@ export const Sidebar = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
<SidebarPlaylistList data={playlistsQuery.data} />
|
<SidebarPlaylistList />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</MotionStack>
|
</MotionStack>
|
||||||
|
|||||||
Reference in New Issue
Block a user