From 0b383b758ed7fb2ad31221964ec967c9157ebdb4 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:09:44 -0700 Subject: [PATCH] support collapsing shared playlists --- .../components/sidebar-playlist-list.tsx | 57 +++++++++++++++---- src/renderer/store/settings.store.ts | 9 +++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx b/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx index c5aa5f8b..fc9a8a7f 100644 --- a/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx +++ b/src/renderer/features/sidebar/components/sidebar-playlist-list.tsx @@ -2,7 +2,13 @@ import { useCallback, useMemo, useState } from 'react'; import { Box, Flex, Group } from '@mantine/core'; import { useDebouncedValue } from '@mantine/hooks'; import { useTranslation } from 'react-i18next'; -import { RiAddBoxFill, RiAddCircleFill, RiPlayFill } from 'react-icons/ri'; +import { + RiAddBoxFill, + RiAddCircleFill, + RiArrowDownSLine, + RiArrowUpSLine, + RiPlayFill, +} from 'react-icons/ri'; import { generatePath } from 'react-router'; import { Link } from 'react-router-dom'; import { LibraryItem, Playlist } from '/@/renderer/api/types'; @@ -14,7 +20,7 @@ import { Play } from '/@/renderer/types'; import AutoSizer from 'react-virtualized-auto-sizer'; import { FixedSizeList, ListChildComponentProps } from 'react-window'; import { useHideScrollbar } from '/@/renderer/hooks'; -import { useCurrentServer, useGeneralSettings } from '/@/renderer/store'; +import { useCurrentServer, useGeneralSettings, useSettingsStoreActions } from '/@/renderer/store'; interface SidebarPlaylistListProps { data: ReturnType['data']; @@ -23,14 +29,35 @@ interface SidebarPlaylistListProps { const PlaylistRow = ({ index, data, style }: ListChildComponentProps) => { const { t } = useTranslation(); - if (data?.items[index] === null) { + if (Array.isArray(data?.items[index])) { + const [collapse, setCollapse] = data.items[index]; + return (
- {t('page.sidebar.shared', { postProcess: 'titleCase' })} + + {t('page.sidebar.shared', { postProcess: 'titleCase' })} + +
); @@ -138,7 +165,8 @@ const PlaylistRow = ({ index, data, style }: ListChildComponentProps) => { export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => { const { isScrollbarHidden, hideScrollbarElementProps } = useHideScrollbar(0); const handlePlayQueueAdd = usePlayQueueAdd(); - const { defaultFullPlaylist } = useGeneralSettings(); + const { defaultFullPlaylist, sidebarCollapseShared } = useGeneralSettings(); + const { toggleSidebarCollapseShare } = useSettingsStoreActions(); const { type, username } = useCurrentServer() || {}; const [rect, setRect] = useState({ @@ -168,7 +196,7 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => { return { ...base, items: data?.items }; } - const owned: Array = []; + const owned: Array void]> = []; const shared: Playlist[] = []; for (const playlist of data.items) { @@ -180,12 +208,21 @@ export const SidebarPlaylistList = ({ data }: SidebarPlaylistListProps) => { } if (shared.length > 0) { - // Use `null` as a separator between owned and shared playlists - owned.push(null); + owned.push([sidebarCollapseShared, toggleSidebarCollapseShare]); } - return { ...base, items: owned.concat(shared) }; - }, [data?.items, defaultFullPlaylist, handlePlayPlaylist, type, username]); + const final = sidebarCollapseShared ? owned : owned.concat(shared); + + return { ...base, items: final }; + }, [ + sidebarCollapseShared, + data?.items, + defaultFullPlaylist, + handlePlayPlaylist, + type, + username, + toggleSidebarCollapseShare, + ]); return ( ) => void; setSidebarItems: (items: SidebarItemType[]) => void; setTable: (type: TableType, data: DataTableProps) => void; + toggleSidebarCollapseShare: () => void; }; } @@ -335,6 +337,7 @@ const initialState: SettingsState = { resume: false, showQueueDrawerButton: false, sideQueueType: 'sideQueue', + sidebarCollapseShared: false, sidebarCollapsedNavigation: true, sidebarItems, sidebarPlaylistList: true, @@ -645,6 +648,12 @@ export const useSettingsStore = create()( state.tables[type] = data; }); }, + toggleSidebarCollapseShare: () => { + set((state) => { + state.general.sidebarCollapseShared = + !state.general.sidebarCollapseShared; + }); + }, }, ...initialState, })),