From f026a7dfd2a94f221f204820ba80a3913ff055ba Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Tue, 13 Apr 2021 21:30:34 +0800 Subject: [PATCH] feature: hide sidebar when auth failed but token is set --- src/components/SideBar.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index b9b1115..c1c4ea5 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -68,18 +68,27 @@ const RawGitako: React.FC = function RawGitako(props) { ) const intelligentToggle = configContext.value.intelligentToggle + // Hide sidebar when error due to auth but token is set #128 + const hideSidebarOnInvalidToken: boolean = + intelligentToggle === null && Boolean(errorDueToAuth && accessToken) React.useEffect(() => { - const shouldShow = intelligentToggle === null ? platform.shouldShow() : intelligentToggle - props.setShouldShow(shouldShow) - }, [intelligentToggle, props.metaData]) + if (hideSidebarOnInvalidToken) { + props.setShouldShow(false) + } else { + const shouldShow = intelligentToggle === null ? platform.shouldShow() : intelligentToggle + props.setShouldShow(shouldShow) + } + }, [intelligentToggle, hideSidebarOnInvalidToken, props.metaData]) const updateSideBarVisibility = React.useCallback( function updateSideBarVisibility() { - if (intelligentToggle === null) { + if (hideSidebarOnInvalidToken) { + props.setShouldShow(false) + } else if (intelligentToggle === null) { props.setShouldShow(platform.shouldShow()) } }, - [props.metaData?.branchName, intelligentToggle], + [props.metaData?.branchName, intelligentToggle, hideSidebarOnInvalidToken], ) useOnPJAXDone(updateSideBarVisibility)