mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: prevent auto collapsing sidebar when enabling Auto Expand or pinning sidebar
fix #155
This commit is contained in:
parent
4f35c36054
commit
e740d67d44
1 changed files with 15 additions and 16 deletions
|
|
@ -55,7 +55,13 @@ export function SideBar() {
|
|||
|
||||
const sidebarToggleMode = configContext.value.sidebarToggleMode
|
||||
const intelligentToggle = configContext.value.intelligentToggle
|
||||
const $shouldShow = useStateIO(intelligentToggle === null ? false : intelligentToggle)
|
||||
const $shouldShow = useStateIO(() =>
|
||||
intelligentToggle === null
|
||||
? sidebarToggleMode === 'persistent'
|
||||
? platform.shouldShow()
|
||||
: false
|
||||
: intelligentToggle,
|
||||
)
|
||||
const shouldShow = $shouldShow.value
|
||||
React.useEffect(() => {
|
||||
if (sidebarToggleMode === 'persistent') {
|
||||
|
|
@ -69,7 +75,7 @@ export function SideBar() {
|
|||
}
|
||||
}, [shouldShow, sidebarToggleMode])
|
||||
|
||||
// Save expand state on toggle if auto expand if not on
|
||||
// Save expand state on toggle if auto expand is off
|
||||
React.useEffect(() => {
|
||||
if (intelligentToggle !== null) {
|
||||
configContext.onChange({ intelligentToggle: shouldShow })
|
||||
|
|
@ -96,7 +102,13 @@ export function SideBar() {
|
|||
}, [error])
|
||||
useToggleSideBarWithKeyboard(state, configContext, toggleShowSideBar)
|
||||
|
||||
useSetShouldShowOnPJAXDone(setShowSideBar)
|
||||
const updateSideBarVisibility = React.useCallback(() => {
|
||||
if (intelligentToggle === null && sidebarToggleMode === 'persistent') {
|
||||
setShowSideBar(platform.shouldShow())
|
||||
}
|
||||
}, [intelligentToggle, sidebarToggleMode])
|
||||
|
||||
useOnPJAXDone(updateSideBarVisibility)
|
||||
|
||||
platform.usePlatformHooks?.()
|
||||
|
||||
|
|
@ -201,16 +213,3 @@ export function SideBar() {
|
|||
</Theme>
|
||||
)
|
||||
}
|
||||
|
||||
function useSetShouldShowOnPJAXDone(setShouldShow: (value: boolean) => void) {
|
||||
const { intelligentToggle, sidebarToggleMode } = useConfigs().value
|
||||
const updateSideBarVisibility = React.useCallback(() => {
|
||||
if (intelligentToggle === null && sidebarToggleMode === 'persistent') {
|
||||
setShouldShow(platform.shouldShow())
|
||||
}
|
||||
}, [intelligentToggle, sidebarToggleMode])
|
||||
React.useEffect(() => {
|
||||
updateSideBarVisibility()
|
||||
}, [updateSideBarVisibility])
|
||||
useOnPJAXDone(updateSideBarVisibility)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue