From 9484904f6046d3ef855ab2cf478e2691643f9428 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 1 Oct 2025 20:14:30 -0700 Subject: [PATCH] New: Add button to close side bar Closes #7757 --- .../src/Components/Page/Header/PageHeader.css | 1 - .../Components/Page/Sidebar/PageSidebar.css | 34 +++++++++++ .../Page/Sidebar/PageSidebar.css.d.ts | 5 ++ .../Components/Page/Sidebar/PageSidebar.tsx | 58 ++++++++++--------- 4 files changed, 71 insertions(+), 27 deletions(-) diff --git a/frontend/src/Components/Page/Header/PageHeader.css b/frontend/src/Components/Page/Header/PageHeader.css index b94bd64b8..dfb1f3bdd 100644 --- a/frontend/src/Components/Page/Header/PageHeader.css +++ b/frontend/src/Components/Page/Header/PageHeader.css @@ -1,5 +1,4 @@ .header { - z-index: 3; display: flex; align-items: center; flex: 0 0 auto; diff --git a/frontend/src/Components/Page/Sidebar/PageSidebar.css b/frontend/src/Components/Page/Sidebar/PageSidebar.css index ee44c0407..5508b376d 100644 --- a/frontend/src/Components/Page/Sidebar/PageSidebar.css +++ b/frontend/src/Components/Page/Sidebar/PageSidebar.css @@ -7,6 +7,40 @@ transform: translateX(0); } +.sidebarHeader { + display: flex; + align-items: center; + justify-content: space-between; + height: $headerHeight; +} + +.logoContainer { + display: flex; + align-items: center; + padding-left: 20px; +} + +.logoLink { + line-height: 0; +} + +.logo { + width: 32px; + height: 32px; +} + +.sidebarCloseButton { + composes: button from '~Components/Link/IconButton.css'; + + margin-right: 15px; + color: #e1e2e3; + text-align: center; + + &:hover { + color: var(--sonarrBlue); + } +} + .sidebar { display: flex; flex-direction: column; diff --git a/frontend/src/Components/Page/Sidebar/PageSidebar.css.d.ts b/frontend/src/Components/Page/Sidebar/PageSidebar.css.d.ts index 7cefa5fb5..0576ff982 100644 --- a/frontend/src/Components/Page/Sidebar/PageSidebar.css.d.ts +++ b/frontend/src/Components/Page/Sidebar/PageSidebar.css.d.ts @@ -1,8 +1,13 @@ // This file is automatically generated. // Please do not change this file! interface CssExports { + 'logo': string; + 'logoContainer': string; + 'logoLink': string; 'sidebar': string; + 'sidebarCloseButton': string; 'sidebarContainer': string; + 'sidebarHeader': string; } export const cssExports: CssExports; export default cssExports; diff --git a/frontend/src/Components/Page/Sidebar/PageSidebar.tsx b/frontend/src/Components/Page/Sidebar/PageSidebar.tsx index 9d0946cc0..6e86dbbbb 100644 --- a/frontend/src/Components/Page/Sidebar/PageSidebar.tsx +++ b/frontend/src/Components/Page/Sidebar/PageSidebar.tsx @@ -1,4 +1,3 @@ -import classNames from 'classnames'; import React, { useCallback, useEffect, @@ -11,6 +10,8 @@ import { useDispatch } from 'react-redux'; import { useLocation } from 'react-router'; import QueueStatus from 'Activity/Queue/Status/QueueStatus'; import { IconName } from 'Components/Icon'; +import IconButton from 'Components/Link/IconButton'; +import Link from 'Components/Link/Link'; import OverlayScroller from 'Components/Scroller/OverlayScroller'; import Scroller from 'Components/Scroller/Scroller'; import usePrevious from 'Helpers/Hooks/usePrevious'; @@ -230,10 +231,6 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { transition: 'none', transform: isSidebarVisible ? 0 : SIDEBAR_WIDTH * -1, }); - const [sidebarStyle, setSidebarStyle] = useState({ - top: dimensions.headerHeight, - height: `${window.innerHeight - HEADER_HEIGHT}px`, - }); const urlBase = window.Sonarr.urlBase; const pathname = urlBase @@ -299,22 +296,6 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { dispatch(setIsSidebarVisible({ isSidebarVisible: false })); }, [dispatch]); - const handleWindowScroll = useCallback(() => { - const windowScroll = - window.scrollY == null - ? document.documentElement.scrollTop - : window.scrollY; - const sidebarTop = Math.max(HEADER_HEIGHT - windowScroll, 0); - const sidebarHeight = window.innerHeight - sidebarTop; - - if (isSmallScreen) { - setSidebarStyle({ - top: `${sidebarTop}px`, - height: `${sidebarHeight}px`, - }); - } - }, [isSmallScreen]); - const handleTouchStart = useCallback( (event: TouchEvent) => { const touches = event.touches; @@ -396,10 +377,13 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { touchStartY.current = null; }, []); + const handleSidebarClosePress = useCallback(() => { + dispatch(setIsSidebarVisible({ isSidebarVisible: false })); + }, [dispatch]); + useEffect(() => { if (isSmallScreen) { window.addEventListener('click', handleWindowClick, { capture: true }); - window.addEventListener('scroll', handleWindowScroll); window.addEventListener('touchstart', handleTouchStart); window.addEventListener('touchmove', handleTouchMove); window.addEventListener('touchend', handleTouchEnd); @@ -408,7 +392,6 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { return () => { window.removeEventListener('click', handleWindowClick, { capture: true }); - window.removeEventListener('scroll', handleWindowScroll); window.removeEventListener('touchstart', handleTouchStart); window.removeEventListener('touchmove', handleTouchMove); window.removeEventListener('touchend', handleTouchEnd); @@ -417,7 +400,6 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { }, [ isSmallScreen, handleWindowClick, - handleWindowScroll, handleTouchStart, handleTouchMove, handleTouchEnd, @@ -456,13 +438,37 @@ function PageSidebar({ isSidebarVisible, isSmallScreen }: PageSidebarProps) { return (
+ {isSmallScreen ? ( +
+
+ + Sonarr Logo + +
+ + +
+ ) : null} +
{LINKS.map((link) => {