From 0ed692ff9b056d00dde73040482e6b1bdc404d04 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 29 Sep 2022 12:46:06 +0530 Subject: [PATCH] feat: add panel settings section in quick settings (#1669) --- .../ApplicationView/ApplicationView.tsx | 31 +++++--- .../src/javascripts/Components/Icon/Icon.tsx | 1 + .../PanelSettingsSection.tsx | 78 +++++++++++++++++++ .../QuickSettingsMenu/QuickSettingsMenu.tsx | 2 + .../StyledTooltip/StyledTooltip.tsx | 1 - .../ItemList/ItemListController.ts | 15 ++-- packages/web/src/stylesheets/_main.scss | 1 - 7 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 packages/web/src/javascripts/Components/QuickSettingsMenu/PanelSettingsSection.tsx diff --git a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx index 4909370dd..b40db86b4 100644 --- a/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx +++ b/packages/web/src/javascripts/Components/ApplicationView/ApplicationView.tsx @@ -12,7 +12,7 @@ import PreferencesViewWrapper from '@/Components/Preferences/PreferencesViewWrap import ChallengeModal from '@/Components/ChallengeModal/ChallengeModal' import NotesContextMenu from '@/Components/NotesContextMenu/NotesContextMenu' import PurchaseFlowWrapper from '@/Components/PurchaseFlow/PurchaseFlowWrapper' -import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react' +import { FunctionComponent, useCallback, useEffect, useMemo, useRef, useState } from 'react' import RevisionHistoryModal from '@/Components/RevisionHistoryModal/RevisionHistoryModal' import PremiumModalProvider from '@/Hooks/usePremiumModal' import ConfirmSignoutContainer from '@/Components/ConfirmSignoutModal/ConfirmSignoutModal' @@ -35,13 +35,14 @@ type Props = { const ApplicationView: FunctionComponent = ({ application, mainApplicationGroup }) => { const platformString = getPlatformString() - const [appClass, setAppClass] = useState('') const [launched, setLaunched] = useState(false) const [needsUnlock, setNeedsUnlock] = useState(true) const [challenges, setChallenges] = useState([]) const viewControllerManager = application.getViewControllerManager() + const appColumnContainerRef = useRef(null) + useEffect(() => { const desktopService = application.getDesktopService() @@ -125,15 +126,27 @@ const ApplicationView: FunctionComponent = ({ application, mainApplicatio useEffect(() => { const removeObserver = application.addWebEventObserver(async (eventName, data) => { if (eventName === WebAppEvent.PanelResized) { + if (!appColumnContainerRef.current) { + return + } + const { panel, collapsed } = data as PanelResizedData - let appClass = '' - if (panel === PANEL_NAME_NOTES && collapsed) { - appClass += 'collapsed-notes' + + if (panel === PANEL_NAME_NOTES) { + if (collapsed) { + appColumnContainerRef.current.classList.add('collapsed-notes') + } else { + appColumnContainerRef.current.classList.remove('collapsed-notes') + } } - if (panel === PANEL_NAME_NAVIGATION && collapsed) { - appClass += ' collapsed-navigation' + + if (panel === PANEL_NAME_NAVIGATION) { + if (collapsed) { + appColumnContainerRef.current.classList.add('collapsed-navigation') + } else { + appColumnContainerRef.current.classList.remove('collapsed-navigation') + } } - setAppClass(appClass) } else if (eventName === WebAppEvent.WindowDidFocus) { if (!(await application.isLocked())) { application.sync.sync().catch(console.error) @@ -180,7 +193,7 @@ const ApplicationView: FunctionComponent = ({ application, mainApplicatio
-
+
{ + const [currentNavPanelWidth, setCurrentNavPanelWidth] = useState( + application.getPreference(PrefKey.TagsPanelWidth, MinimumNavPanelWidth), + ) + + const [currentItemsPanelWidth, setCurrentItemsPanelWidth] = useState( + application.getPreference(PrefKey.NotesPanelWidth, MinimumNotesPanelWidth), + ) + + const toggleNavigationPanel = () => { + const isCollapsed = currentNavPanelWidth <= WidthForCollapsedPanel + if (isCollapsed) { + void application.setPreference(PrefKey.TagsPanelWidth, MinimumNavPanelWidth) + } else { + void application.setPreference(PrefKey.TagsPanelWidth, WidthForCollapsedPanel) + } + application.publishPanelDidResizeEvent(PANEL_NAME_NAVIGATION, !isCollapsed) + } + + const toggleItemsListPanel = () => { + const isCollapsed = currentItemsPanelWidth <= WidthForCollapsedPanel + if (isCollapsed) { + void application.setPreference(PrefKey.NotesPanelWidth, MinimumNotesPanelWidth) + } else { + void application.setPreference(PrefKey.NotesPanelWidth, WidthForCollapsedPanel) + } + application.publishPanelDidResizeEvent(PANEL_NAME_NOTES, !isCollapsed) + } + + useEffect(() => { + const removeObserver = application.addEventObserver(async () => { + setCurrentNavPanelWidth(application.getPreference(PrefKey.TagsPanelWidth, MinimumNavPanelWidth)) + setCurrentItemsPanelWidth(application.getPreference(PrefKey.NotesPanelWidth, MinimumNotesPanelWidth)) + }, ApplicationEvent.PreferencesChanged) + + return removeObserver + }, [application]) + + return ( +
+ +
Panel Settings
+ WidthForCollapsedPanel} + onChange={toggleNavigationPanel} + > + Show navigation panel + + WidthForCollapsedPanel} + onChange={toggleItemsListPanel} + > + Show items list panel + +
+ ) +} +export default memo(PanelSettingsSection) diff --git a/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx b/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx index a4f900105..878530337 100644 --- a/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx +++ b/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx @@ -11,6 +11,7 @@ import { sortThemes } from '@/Utils/SortThemes' import RadioIndicator from '../RadioIndicator/RadioIndicator' import HorizontalSeparator from '../Shared/HorizontalSeparator' import { QuickSettingsController } from '@/Controllers/QuickSettingsController' +import PanelSettingsSection from './PanelSettingsSection' const focusModeAnimationDuration = 1255 @@ -174,6 +175,7 @@ const QuickSettingsMenu: FunctionComponent = ({ application, quickSet onClose={closeQuickSettingsMenu} isEnabled={focusModeEnabled} /> +
) } diff --git a/packages/web/src/javascripts/Components/StyledTooltip/StyledTooltip.tsx b/packages/web/src/javascripts/Components/StyledTooltip/StyledTooltip.tsx index fc282bc96..80c0c85bb 100644 --- a/packages/web/src/javascripts/Components/StyledTooltip/StyledTooltip.tsx +++ b/packages/web/src/javascripts/Components/StyledTooltip/StyledTooltip.tsx @@ -9,6 +9,5 @@ export default styled(Tooltip)` background-color: var(--sn-stylekit-contrast-background-color); color: var(--sn-stylekit-foreground-color); border-color: var(--sn-stylekit-border-color); - z-index: var(--z-index-tooltip); } ` diff --git a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts index e3d9033b7..0f29b2ded 100644 --- a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts +++ b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts @@ -188,6 +188,7 @@ export class ItemListController extends AbstractViewController implements Intern notes: observable, notesToDisplay: observable, panelTitle: observable, + panelWidth: observable, renderedItems: observable, showDisplayOptionsMenu: observable, @@ -453,17 +454,21 @@ export class ItemListController extends AbstractViewController implements Intern this.displayOptions = newDisplayOptions this.webDisplayOptions = newWebDisplayOptions + const newWidth = this.application.getPreference(PrefKey.NotesPanelWidth) + if (newWidth && newWidth !== this.panelWidth) { + this.panelWidth = newWidth + } + + if (!displayOptionsChanged) { + return + } + if (displayOptionsChanged) { this.reloadNotesDisplayOptions() } await this.reloadItems(ItemsReloadSource.DisplayOptionsChange) - const width = this.application.getPreference(PrefKey.NotesPanelWidth) - if (width) { - this.panelWidth = width - } - if (newDisplayOptions.sortBy !== currentSortBy) { await this.selectFirstItem() } diff --git a/packages/web/src/stylesheets/_main.scss b/packages/web/src/stylesheets/_main.scss index 9ffd84c11..e12228e9a 100644 --- a/packages/web/src/stylesheets/_main.scss +++ b/packages/web/src/stylesheets/_main.scss @@ -13,7 +13,6 @@ --z-index-lock-screen: 10000; --z-index-modal: 10000; --z-index-toast: 11000; - --z-index-tooltip: 12000; --sn-stylekit-base-font-size: 0.813rem; --sn-stylekit-simplified-chinese-font: 'Microsoft Yahei', '微软雅黑体';