From 6261ec9aad7e69d96d396d476dd49a82073a35fd Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sun, 6 Feb 2022 07:02:09 -0800 Subject: [PATCH] Fix --- src/components/layout/Sidebar.tsx | 50 ++------------------ src/components/layout/SidebarPlaylists.tsx | 53 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 45 deletions(-) create mode 100644 src/components/layout/SidebarPlaylists.tsx diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index cf5e2878..a13cd63e 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -1,9 +1,6 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; -import { useQuery } from 'react-query'; import settings from 'electron-settings'; -import { FixedSizeList as List } from 'react-window'; import useMeasure from 'react-use/lib/useMeasure'; -import { AutoSizer } from 'react-virtualized'; import { LazyLoadImage } from 'react-lazy-load-image-component'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; @@ -18,27 +15,10 @@ import { SidebarNavItem, } from './styled'; import { setSidebar } from '../../redux/miscSlice'; -import { apiController } from '../../api/controller'; import { StyledButton } from '../shared/styled'; import { InfoModal } from '../modal/PageModal'; import placeholderImg from '../../img/placeholder.png'; - -const PlaylistRow = ({ data, index, style }: any) => { - const history = useHistory(); - - return ( -
- history.push(`/playlist/${data[index].id}`)} - > - {data[index].title} - -
- ); -}; +import SidebarPlaylists from './SidebarPlaylists'; const Sidebar = ({ expand, @@ -62,10 +42,6 @@ const Sidebar = ({ const [mainNavRef, { height: mainNavHeight }] = useMeasure(); const [sidebarBodyRef, { height: sidebarBodyHeight }] = useMeasure(); - const { data: playlists }: any = useQuery(['playlists'], () => - apiController({ serverType: config.serverType, endpoint: 'getPlaylists' }) - ); - const getSidebarWidth = useCallback((num: number) => { if (num < 160) { return 160; @@ -118,7 +94,7 @@ const Sidebar = ({ > {expand && misc.sidebar.coverArt && ( - + setShowCoverArtModal(true)} src={ @@ -128,7 +104,7 @@ const Sidebar = ({ ) || placeholderImg } style={{ - height: `${width}`, + height: `${width}px`, width: '100%', objectFit: 'cover', }} @@ -147,9 +123,7 @@ const Sidebar = ({ @@ -342,21 +316,7 @@ const Sidebar = ({ history.push('/playlist')}> {t('Playlists')} - - {({ height }: any) => ( - <> - - {PlaylistRow} - - - )} - + )} diff --git a/src/components/layout/SidebarPlaylists.tsx b/src/components/layout/SidebarPlaylists.tsx new file mode 100644 index 00000000..db7ef1d0 --- /dev/null +++ b/src/components/layout/SidebarPlaylists.tsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { useQuery } from 'react-query'; +import { useHistory } from 'react-router-dom'; +import { AutoSizer } from 'react-virtualized'; +import { FixedSizeList as List } from 'react-window'; +import { apiController } from '../../api/controller'; +import { useAppSelector } from '../../redux/hooks'; +import { StyledButton } from '../shared/styled'; + +const PlaylistRow = ({ data, index, style }: any) => { + const history = useHistory(); + + return ( +
+ history.push(`/playlist/${data[index].id}`)} + > + {data[index].title} + +
+ ); +}; + +const SidebarPlaylists = ({ width }: any) => { + const config = useAppSelector((state) => state.config); + + const { data: playlists }: any = useQuery(['playlists'], () => + apiController({ serverType: config.serverType, endpoint: 'getPlaylists' }) + ); + + return ( + + {({ height }: any) => ( + <> + + {PlaylistRow} + + + )} + + ); +}; + +export default SidebarPlaylists;