>
+ toggleShowSideBar: () => void
+}) {
+ const logoContainerElement = useLogoContainerElement()
+ const { sidebarToggleMode } = useConfigs().value
+ return (
+
+ setShouldExpand(true) : undefined}
+ onClick={toggleShowSideBar}
+ />
+
+ )
+}
+
function useFocusSidebarOnExpand(shouldExpand: boolean) {
React.useEffect(() => {
// prevent keeping focus within Gitako
diff --git a/src/components/ToggleShowButton.tsx b/src/components/ToggleShowButton.tsx
index 5e23d19..11f83b4 100644
--- a/src/components/ToggleShowButton.tsx
+++ b/src/components/ToggleShowButton.tsx
@@ -1,15 +1,16 @@
import { SyncIcon } from '@primer/octicons-react'
import iconURL from 'assets/icons/Gitako.png'
import { useConfigs } from 'containers/ConfigsContext'
+import { SideBarErrorContext } from 'containers/ErrorContext'
import { ReloadContext } from 'containers/ReloadContext'
import * as React from 'react'
import { useDebounce, useWindowSize } from 'react-use'
import { cx } from 'utils/cx'
+import { useLoadedContext } from 'utils/hooks/useLoadedContext'
import { useResizeHandler } from 'utils/hooks/useResizeHandler'
import { RoundIconButton } from './RoundIconButton'
type Props = {
- error?: string | null
className?: React.HTMLAttributes
['className']
onHover?: React.HTMLAttributes['onMouseEnter']
onClick?: (e: PointerEvent) => void
@@ -21,8 +22,10 @@ function getSafeDistance(y: number, height: number) {
return Math.max(0, Math.min(y, height - buttonHeight))
}
-export function ToggleShowButton({ error, className, onClick, onHover }: Props) {
+export function ToggleShowButton({ className, onClick, onHover }: Props) {
const reload = React.useContext(ReloadContext)
+ const error = useLoadedContext(SideBarErrorContext).value
+
const ref = React.useRef(null)
const config = useConfigs()
const [distance, setDistance] = React.useState(config.value.toggleButtonVerticalDistance)
diff --git a/src/containers/SideBarState.tsx b/src/containers/SideBarState.tsx
index d70816e..6030adf 100644
--- a/src/containers/SideBarState.tsx
+++ b/src/containers/SideBarState.tsx
@@ -1,6 +1,8 @@
import { PropsWithChildren } from 'common'
import * as React from 'react'
+import { useLoadedContext } from 'utils/hooks/useLoadedContext'
import { useStateIO } from 'utils/hooks/useStateIO'
+import { SideBarErrorContext } from './ErrorContext'
import { useInspector } from './StateInspector'
export type SideBarState =
@@ -13,7 +15,8 @@ export type SideBarState =
| 'tree-rendering'
| 'tree-rendered'
| 'idle'
- | 'error-due-to-auth'
+ | 'error' // when error occurs, sidebar should never expand
+ | 'error-due-to-auth' // this is a special error, user can expand sidebar and set token to fix the error
export type SideBarStateContextShape = IO
@@ -22,10 +25,17 @@ export const SideBarStateContext = React.createContext('disabled')
useInspector('SideBarStateContext', $state.value)
-
- return (
-
- {$state.value !== null && children}
-
+ const error = useLoadedContext(SideBarErrorContext).value
+ const $$state: IO = React.useMemo(
+ () =>
+ error && $state.value !== 'error'
+ ? {
+ ...$state,
+ value: 'error',
+ }
+ : $state,
+ [$state, error],
)
+
+ return {children}
}