diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index 6e93a44..d4c75f9 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -25,8 +25,7 @@ const RawGitako: React.FC = function RawGitako(props) { const intelligentToggle = configContext.val.intelligentToggle React.useEffect(() => { - const shouldShow = - intelligentToggle === null ? platform.shouldShow(props.metaData) : intelligentToggle + const shouldShow = intelligentToggle === null ? platform.shouldShow() : intelligentToggle props.setShouldShow(shouldShow) }, [intelligentToggle, props.metaData]) @@ -60,11 +59,7 @@ const RawGitako: React.FC = function RawGitako(props) { const updateSideBarVisibility = React.useCallback( function updateSideBarVisibility() { if (configContext.val.intelligentToggle === null) { - props.setShouldShow( - platform.shouldShow({ - branchName: props.metaData?.branchName, - }), - ) + props.setShouldShow(platform.shouldShow()) } }, [props.metaData?.branchName, configContext.val.intelligentToggle], diff --git a/src/platforms/GitHub/URLHelper.ts b/src/platforms/GitHub/URLHelper.ts index b67711b..fc8140b 100644 --- a/src/platforms/GitHub/URLHelper.ts +++ b/src/platforms/GitHub/URLHelper.ts @@ -29,26 +29,6 @@ export function isInRepoPage() { return Boolean(document.querySelector(repoHeaderSelector)) } -// route types related to determining if sidebar should show -const TYPES = { - TREE: 'tree', - BLOB: 'blob', - COMMIT: 'commit', - // known but not related types: issues, pulls, wiki, insight, - // TODO: record more types -} - -export function isInCodePage(metaData?: Partial) { - const mergedRepo = { ...parse(), ...metaData } - const { type, branchName } = mergedRepo - return Boolean( - isInRepoPage() && - (!type || type === TYPES.TREE || type === TYPES.BLOB) && - type !== TYPES.COMMIT && - (branchName || (!type && !branchName)), - ) -} - function isCommitPath(path: string[]) { return isCompleteCommitSHA(path[0]) } diff --git a/src/platforms/GitHub/index.ts b/src/platforms/GitHub/index.ts index a91c4cc..e6a5072 100644 --- a/src/platforms/GitHub/index.ts +++ b/src/platforms/GitHub/index.ts @@ -135,8 +135,8 @@ export const GitHub: Platform = { return root }, - shouldShow(metaData) { - return URLHelper.isInCodePage(metaData) + shouldShow() { + return DOMHelper.isInCodePage() }, getCurrentPath(branchName) { return URLHelper.getCurrentPath(branchName) diff --git a/src/platforms/Gitee/URLHelper.ts b/src/platforms/Gitee/URLHelper.ts index cbaa8d3..0a539da 100644 --- a/src/platforms/Gitee/URLHelper.ts +++ b/src/platforms/Gitee/URLHelper.ts @@ -1,5 +1,4 @@ import { raiseError } from 'analytics' -import { isInRepoPage } from './DOMHelper' export function parse(): Partial & { path: string[] } { const { pathname } = window.location @@ -25,26 +24,6 @@ export function parseSHA() { return type === 'blob' || type === 'tree' ? path[0] : undefined } -// route types related to determining if sidebar should show -const TYPES = { - TREE: 'tree', - BLOB: 'blob', - COMMIT: 'commit', - // known but not related types: issues, pulls, wiki, insight, - // TODO: record more types -} - -export function isInCodePage(metaData?: Partial) { - const mergedRepo = { ...parse(), ...metaData } - const { type, branchName } = mergedRepo - return Boolean( - isInRepoPage() && - (!type || type === TYPES.TREE || type === TYPES.BLOB) && - type !== TYPES.COMMIT && - (branchName || (!type && !branchName)), - ) -} - function isCommitPath(path: string[]) { return isCompleteCommitSHA(path[0]) } diff --git a/src/platforms/Gitee/index.ts b/src/platforms/Gitee/index.ts index eff996e..a5f9e87 100644 --- a/src/platforms/Gitee/index.ts +++ b/src/platforms/Gitee/index.ts @@ -131,8 +131,8 @@ export const Gitee: Platform = { return root }, - shouldShow(metaData) { - return URLHelper.isInCodePage(metaData) + shouldShow() { + return DOMHelper.isInCodePage() }, getCurrentPath(branchName) { return URLHelper.getCurrentPath(branchName) diff --git a/src/platforms/platform.d.ts b/src/platforms/platform.d.ts index cbf60cc..1dfed0a 100644 --- a/src/platforms/platform.d.ts +++ b/src/platforms/platform.d.ts @@ -6,7 +6,7 @@ type Platform = { accessToken?: string, ): Promise> getTreeData(metaData: MetaData, accessToken?: string): Promise - shouldShow(metaData?: Partial): boolean + shouldShow(): boolean getCurrentPath(branchName: string): string[] | null setOAuth(code: string): Promise getOAuthLink(): string