refactor: use local state for vault selection menu
This commit is contained in:
@@ -23,7 +23,6 @@ import { MomentsService } from '@/Controllers/Moments/MomentsService'
|
|||||||
import { PersistenceService } from '@/Controllers/Abstract/PersistenceService'
|
import { PersistenceService } from '@/Controllers/Abstract/PersistenceService'
|
||||||
import { FilePreviewModalController } from '@/Controllers/FilePreviewModalController'
|
import { FilePreviewModalController } from '@/Controllers/FilePreviewModalController'
|
||||||
import { QuickSettingsController } from '@/Controllers/QuickSettingsController'
|
import { QuickSettingsController } from '@/Controllers/QuickSettingsController'
|
||||||
import { VaultSelectionMenuController } from '@/Controllers/VaultSelectionMenuController'
|
|
||||||
import { PaneController } from '@/Controllers/PaneController/PaneController'
|
import { PaneController } from '@/Controllers/PaneController/PaneController'
|
||||||
import { PreferencesController } from '@/Controllers/PreferencesController'
|
import { PreferencesController } from '@/Controllers/PreferencesController'
|
||||||
import { FeaturesController } from '@/Controllers/FeaturesController'
|
import { FeaturesController } from '@/Controllers/FeaturesController'
|
||||||
@@ -177,10 +176,6 @@ export class WebDependencies extends DependencyContainer {
|
|||||||
return new QuickSettingsController(application.events)
|
return new QuickSettingsController(application.events)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.bind(Web_TYPES.VaultSelectionMenuController, () => {
|
|
||||||
return new VaultSelectionMenuController(application.events)
|
|
||||||
})
|
|
||||||
|
|
||||||
this.bind(Web_TYPES.PaneController, () => {
|
this.bind(Web_TYPES.PaneController, () => {
|
||||||
return new PaneController(
|
return new PaneController(
|
||||||
application.preferences,
|
application.preferences,
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ import { NavigationController } from '@/Controllers/Navigation/NavigationControl
|
|||||||
import { FilePreviewModalController } from '@/Controllers/FilePreviewModalController'
|
import { FilePreviewModalController } from '@/Controllers/FilePreviewModalController'
|
||||||
import { OpenSubscriptionDashboard } from './UseCase/OpenSubscriptionDashboard'
|
import { OpenSubscriptionDashboard } from './UseCase/OpenSubscriptionDashboard'
|
||||||
import { QuickSettingsController } from '@/Controllers/QuickSettingsController'
|
import { QuickSettingsController } from '@/Controllers/QuickSettingsController'
|
||||||
import { VaultSelectionMenuController } from '@/Controllers/VaultSelectionMenuController'
|
|
||||||
import { ItemGroupController } from '@/Components/NoteView/Controller/ItemGroupController'
|
import { ItemGroupController } from '@/Components/NoteView/Controller/ItemGroupController'
|
||||||
import { NoAccountWarningController } from '@/Controllers/NoAccountWarningController'
|
import { NoAccountWarningController } from '@/Controllers/NoAccountWarningController'
|
||||||
import { SearchOptionsController } from '@/Controllers/SearchOptionsController'
|
import { SearchOptionsController } from '@/Controllers/SearchOptionsController'
|
||||||
@@ -638,10 +637,6 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
|||||||
return this.deps.get<SearchOptionsController>(Web_TYPES.SearchOptionsController)
|
return this.deps.get<SearchOptionsController>(Web_TYPES.SearchOptionsController)
|
||||||
}
|
}
|
||||||
|
|
||||||
get vaultSelectionController(): VaultSelectionMenuController {
|
|
||||||
return this.deps.get<VaultSelectionMenuController>(Web_TYPES.VaultSelectionMenuController)
|
|
||||||
}
|
|
||||||
|
|
||||||
get openSubscriptionDashboard(): OpenSubscriptionDashboard {
|
get openSubscriptionDashboard(): OpenSubscriptionDashboard {
|
||||||
return this.deps.get<OpenSubscriptionDashboard>(Web_TYPES.OpenSubscriptionDashboard)
|
return this.deps.get<OpenSubscriptionDashboard>(Web_TYPES.OpenSubscriptionDashboard)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ type State = {
|
|||||||
newUpdateAvailable: boolean
|
newUpdateAvailable: boolean
|
||||||
showAccountMenu: boolean
|
showAccountMenu: boolean
|
||||||
showQuickSettingsMenu: boolean
|
showQuickSettingsMenu: boolean
|
||||||
showVaultSelectionMenu: boolean
|
|
||||||
offline: boolean
|
offline: boolean
|
||||||
hasError: boolean
|
hasError: boolean
|
||||||
arbitraryStatusMessage?: string
|
arbitraryStatusMessage?: string
|
||||||
@@ -66,7 +65,6 @@ class Footer extends AbstractComponent<Props, State> {
|
|||||||
newUpdateAvailable: false,
|
newUpdateAvailable: false,
|
||||||
showAccountMenu: false,
|
showAccountMenu: false,
|
||||||
showQuickSettingsMenu: false,
|
showQuickSettingsMenu: false,
|
||||||
showVaultSelectionMenu: false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.webEventListenerDestroyer = props.application.addWebEventObserver((event, data) => {
|
this.webEventListenerDestroyer = props.application.addWebEventObserver((event, data) => {
|
||||||
@@ -128,7 +126,6 @@ class Footer extends AbstractComponent<Props, State> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
showAccountMenu: this.application.accountMenuController.show,
|
showAccountMenu: this.application.accountMenuController.show,
|
||||||
showQuickSettingsMenu: this.application.quickSettingsMenuController.open,
|
showQuickSettingsMenu: this.application.quickSettingsMenuController.open,
|
||||||
showVaultSelectionMenu: this.application.vaultSelectionController.open,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -300,10 +297,6 @@ class Footer extends AbstractComponent<Props, State> {
|
|||||||
this.application.quickSettingsMenuController.toggle()
|
this.application.quickSettingsMenuController.toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
vaultSelectionClickHandler = () => {
|
|
||||||
this.application.vaultSelectionController.toggle()
|
|
||||||
}
|
|
||||||
|
|
||||||
syncResolutionClickHandler = () => {
|
syncResolutionClickHandler = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
showSyncResolution: !this.state.showSyncResolution,
|
showSyncResolution: !this.state.showSyncResolution,
|
||||||
@@ -388,11 +381,7 @@ class Footer extends AbstractComponent<Props, State> {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative z-footer-bar-item ml-1.5 select-none">
|
<div className="relative z-footer-bar-item ml-1.5 select-none">
|
||||||
<VaultSelectionButton
|
<VaultSelectionButton />
|
||||||
isOpen={this.state.showVaultSelectionMenu}
|
|
||||||
toggleMenu={this.vaultSelectionClickHandler}
|
|
||||||
controller={this.application.vaultSelectionController}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<UpgradeNow
|
<UpgradeNow
|
||||||
application={this.application}
|
application={this.application}
|
||||||
|
|||||||
@@ -1,25 +1,20 @@
|
|||||||
import { classNames } from '@standardnotes/utils'
|
import { classNames } from '@standardnotes/utils'
|
||||||
import { useRef } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import Icon from '../Icon/Icon'
|
import Icon from '../Icon/Icon'
|
||||||
import Popover from '../Popover/Popover'
|
import Popover from '../Popover/Popover'
|
||||||
import StyledTooltip from '../StyledTooltip/StyledTooltip'
|
import StyledTooltip from '../StyledTooltip/StyledTooltip'
|
||||||
import { VaultSelectionMenuController } from '@/Controllers/VaultSelectionMenuController'
|
|
||||||
import VaultSelectionMenu from '../VaultSelectionMenu/VaultSelectionMenu'
|
import VaultSelectionMenu from '../VaultSelectionMenu/VaultSelectionMenu'
|
||||||
import { useApplication } from '../ApplicationProvider'
|
import { useApplication } from '../ApplicationProvider'
|
||||||
import { observer } from 'mobx-react-lite'
|
|
||||||
import { featureTrunkVaultsEnabled } from '@/FeatureTrunk'
|
import { featureTrunkVaultsEnabled } from '@/FeatureTrunk'
|
||||||
|
|
||||||
type Props = {
|
const VaultSelectionButton = () => {
|
||||||
isOpen: boolean
|
|
||||||
toggleMenu: () => void
|
|
||||||
controller: VaultSelectionMenuController
|
|
||||||
}
|
|
||||||
|
|
||||||
const VaultSelectionButton = ({ isOpen, toggleMenu, controller }: Props) => {
|
|
||||||
const application = useApplication()
|
const application = useApplication()
|
||||||
const buttonRef = useRef<HTMLButtonElement>(null)
|
const buttonRef = useRef<HTMLButtonElement>(null)
|
||||||
const exclusivelyShownVault = application.vaultDisplayService.exclusivelyShownVault
|
const exclusivelyShownVault = application.vaultDisplayService.exclusivelyShownVault
|
||||||
|
|
||||||
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
const toggleMenu = () => setIsOpen(!isOpen)
|
||||||
|
|
||||||
if (!featureTrunkVaultsEnabled()) {
|
if (!featureTrunkVaultsEnabled()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -53,10 +48,10 @@ const VaultSelectionButton = ({ isOpen, toggleMenu, controller }: Props) => {
|
|||||||
align="start"
|
align="start"
|
||||||
className="py-2"
|
className="py-2"
|
||||||
>
|
>
|
||||||
<VaultSelectionMenu controller={controller} />
|
<VaultSelectionMenu />
|
||||||
</Popover>
|
</Popover>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(VaultSelectionButton)
|
export default VaultSelectionButton
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import { FunctionComponent, useState } from 'react'
|
import { useState } from 'react'
|
||||||
import Menu from '../Menu/Menu'
|
import Menu from '../Menu/Menu'
|
||||||
import { VaultSelectionMenuController } from '@/Controllers/VaultSelectionMenuController'
|
|
||||||
import RadioButtonGroup from '@/Components/RadioButtonGroup/RadioButtonGroup'
|
import RadioButtonGroup from '@/Components/RadioButtonGroup/RadioButtonGroup'
|
||||||
import ManyVaultSelectionMenu from './ManyVaultSelectionMenu'
|
import ManyVaultSelectionMenu from './ManyVaultSelectionMenu'
|
||||||
import SingleVaultSelectionMenu from './SingleVaultSelectionMenu'
|
import SingleVaultSelectionMenu from './SingleVaultSelectionMenu'
|
||||||
@@ -9,13 +8,9 @@ import { useApplication } from '../ApplicationProvider'
|
|||||||
import MenuItemSeparator from '../Menu/MenuItemSeparator'
|
import MenuItemSeparator from '../Menu/MenuItemSeparator'
|
||||||
import MenuItem from '../Menu/MenuItem'
|
import MenuItem from '../Menu/MenuItem'
|
||||||
|
|
||||||
type MenuProps = {
|
|
||||||
controller: VaultSelectionMenuController
|
|
||||||
}
|
|
||||||
|
|
||||||
type SettingsMode = 'many' | 'single'
|
type SettingsMode = 'many' | 'single'
|
||||||
|
|
||||||
const VaultSelectionMenu: FunctionComponent<MenuProps> = () => {
|
const VaultSelectionMenu = () => {
|
||||||
const application = useApplication()
|
const application = useApplication()
|
||||||
|
|
||||||
const [mode, setMode] = useState<SettingsMode>(
|
const [mode, setMode] = useState<SettingsMode>(
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
import { InternalEventBusInterface } from '@standardnotes/snjs'
|
|
||||||
import { action, makeObservable, observable } from 'mobx'
|
|
||||||
import { AbstractViewController } from './Abstract/AbstractViewController'
|
|
||||||
|
|
||||||
export class VaultSelectionMenuController extends AbstractViewController {
|
|
||||||
open = false
|
|
||||||
shouldAnimateCloseMenu = false
|
|
||||||
|
|
||||||
constructor(eventBus: InternalEventBusInterface) {
|
|
||||||
super(eventBus)
|
|
||||||
|
|
||||||
makeObservable(this, {
|
|
||||||
open: observable,
|
|
||||||
shouldAnimateCloseMenu: observable,
|
|
||||||
|
|
||||||
setOpen: action,
|
|
||||||
setShouldAnimateCloseMenu: action,
|
|
||||||
toggle: action,
|
|
||||||
closeVaultSelectionMenu: action,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
setOpen = (open: boolean): void => {
|
|
||||||
this.open = open
|
|
||||||
}
|
|
||||||
|
|
||||||
setShouldAnimateCloseMenu = (shouldAnimate: boolean): void => {
|
|
||||||
this.shouldAnimateCloseMenu = shouldAnimate
|
|
||||||
}
|
|
||||||
|
|
||||||
toggle = (): void => {
|
|
||||||
if (this.open) {
|
|
||||||
this.closeVaultSelectionMenu()
|
|
||||||
} else {
|
|
||||||
this.setOpen(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closeVaultSelectionMenu = (): void => {
|
|
||||||
this.setShouldAnimateCloseMenu(true)
|
|
||||||
setTimeout(() => {
|
|
||||||
this.setOpen(false)
|
|
||||||
this.setShouldAnimateCloseMenu(false)
|
|
||||||
}, 150)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user