From ebe28dcd664cd432caf2c56c26086d181dd1e66b Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 12 Nov 2024 13:39:41 +0100 Subject: [PATCH] Refactor layout accommodation using traffic light status --- .../app/library/components/LibraryHeader.tsx | 25 ++++++----- .../src/app/reader/components/HeaderBar.tsx | 6 +-- .../src/app/reader/components/SectionInfo.tsx | 7 ++- .../app/reader/components/sidebar/Header.tsx | 6 +-- .../src/components/WindowButtons.tsx | 6 ++- apps/readest-app/src/hooks/useFullScreen.ts | 27 ------------ apps/readest-app/src/hooks/useTrafficLight.ts | 43 +++++++++++++++++++ apps/readest-app/src/services/appService.ts | 2 +- .../src/services/nativeAppService.ts | 2 +- apps/readest-app/src/types/system.ts | 2 +- 10 files changed, 74 insertions(+), 52 deletions(-) delete mode 100644 apps/readest-app/src/hooks/useFullScreen.ts create mode 100644 apps/readest-app/src/hooks/useTrafficLight.ts diff --git a/apps/readest-app/src/app/library/components/LibraryHeader.tsx b/apps/readest-app/src/app/library/components/LibraryHeader.tsx index c95948fa..29a00098 100644 --- a/apps/readest-app/src/app/library/components/LibraryHeader.tsx +++ b/apps/readest-app/src/app/library/components/LibraryHeader.tsx @@ -4,8 +4,7 @@ import { FaSearch } from 'react-icons/fa'; import { PiPlus } from 'react-icons/pi'; import { PiSelectionAllDuotone } from 'react-icons/pi'; -import { useEnv } from '@/context/EnvContext'; -import useFullScreen from '@/hooks/useFullScreen'; +import useTrafficLight from '@/hooks/useTrafficLight'; import WindowButtons from '@/components/WindowButtons'; interface LibraryHeaderProps { @@ -19,8 +18,7 @@ const LibraryHeader: React.FC = ({ onImportBooks, onToggleSelectMode, }) => { - const { appService } = useEnv(); - const { isFullScreen } = useFullScreen(); + const { isTrafficLightVisible } = useTrafficLight(); const headerRef = useRef(null); useEffect(() => { @@ -55,7 +53,7 @@ const LibraryHeader: React.FC = ({ ref={headerRef} className={clsx( 'titlebar fixed z-10 w-full bg-gray-100 py-2 pr-6', - isFullScreen ? 'pl-2' : 'pl-16', + isTrafficLightVisible ? 'pl-16' : 'pl-2', )} >
@@ -93,14 +91,15 @@ const LibraryHeader: React.FC = ({
- {!appService?.isNativeWindow && ( - - )} + ); diff --git a/apps/readest-app/src/app/reader/components/HeaderBar.tsx b/apps/readest-app/src/app/reader/components/HeaderBar.tsx index 242646db..f1f212b9 100644 --- a/apps/readest-app/src/app/reader/components/HeaderBar.tsx +++ b/apps/readest-app/src/app/reader/components/HeaderBar.tsx @@ -3,7 +3,7 @@ import React, { useRef, useState } from 'react'; import { PiDotsThreeVerticalBold } from 'react-icons/pi'; import { useReaderStore } from '@/store/readerStore'; -import useFullScreen from '@/hooks/useFullScreen'; +import useTrafficLight from '@/hooks/useTrafficLight'; import WindowButtons from '@/components/WindowButtons'; import Dropdown from '@/components/Dropdown'; import SidebarToggler from './SidebarToggler'; @@ -29,7 +29,7 @@ const HeaderBar: React.FC = ({ onSetSettingsDialogOpen, }) => { const headerRef = useRef(null); - const { isFullScreen } = useFullScreen(); + const { isTrafficLightVisible } = useTrafficLight(); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const { hoveredBookKey, isSideBarVisible, setHoveredBookKey } = useReaderStore(); @@ -43,7 +43,7 @@ const HeaderBar: React.FC = ({ ref={headerRef} className={clsx( `header-bar absolute top-0 z-10 flex h-11 w-full items-center pr-4`, - !isFullScreen && isTopLeft && !isSideBarVisible ? 'pl-16' : 'pl-4', + isTrafficLightVisible && isTopLeft && !isSideBarVisible ? 'pl-16' : 'pl-4', `shadow-xs bg-base-100 rounded-window-top-right transition-opacity duration-300`, !isSideBarVisible && 'rounded-window-top-left', isHoveredAnim && 'hover-bar-anim', diff --git a/apps/readest-app/src/app/reader/components/SectionInfo.tsx b/apps/readest-app/src/app/reader/components/SectionInfo.tsx index 39aaadc0..92a7c12a 100644 --- a/apps/readest-app/src/app/reader/components/SectionInfo.tsx +++ b/apps/readest-app/src/app/reader/components/SectionInfo.tsx @@ -1,7 +1,9 @@ -import { useReaderStore } from '@/store/readerStore'; import clsx from 'clsx'; import React from 'react'; +import { useReaderStore } from '@/store/readerStore'; +import useTrafficLight from '@/hooks/useTrafficLight'; + interface SectionInfoProps { chapter?: string; gapLeft: string; @@ -9,11 +11,12 @@ interface SectionInfoProps { const SectionInfo: React.FC = ({ chapter, gapLeft }) => { const { isSideBarVisible } = useReaderStore(); + const { isTrafficLightVisible } = useTrafficLight(); return (
diff --git a/apps/readest-app/src/app/reader/components/sidebar/Header.tsx b/apps/readest-app/src/app/reader/components/sidebar/Header.tsx index 655fdec1..9a096e2f 100644 --- a/apps/readest-app/src/app/reader/components/sidebar/Header.tsx +++ b/apps/readest-app/src/app/reader/components/sidebar/Header.tsx @@ -4,7 +4,7 @@ import { GiBookshelf } from 'react-icons/gi'; import { FiSearch } from 'react-icons/fi'; import { MdOutlineMenu, MdOutlinePushPin, MdPushPin } from 'react-icons/md'; -import useFullScreen from '@/hooks/useFullScreen'; +import useTrafficLight from '@/hooks/useTrafficLight'; import Dropdown from '@/components/Dropdown'; import BookMenu from './BookMenu'; @@ -14,12 +14,12 @@ const SidebarHeader: React.FC<{ onOpenSplitView: () => void; handleTogglePin: () => void; }> = ({ isPinned, onGoToLibrary, onOpenSplitView, handleTogglePin }) => { - const { isFullScreen } = useFullScreen(); + const { isTrafficLightVisible } = useTrafficLight(); return (
diff --git a/apps/readest-app/src/components/WindowButtons.tsx b/apps/readest-app/src/components/WindowButtons.tsx index 215e202b..9bdbb059 100644 --- a/apps/readest-app/src/components/WindowButtons.tsx +++ b/apps/readest-app/src/components/WindowButtons.tsx @@ -70,7 +70,11 @@ const WindowButtons: React.FC = ({ return (
{showMinimize && (