mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: simplify detection of code page
This commit is contained in:
parent
ddf409b326
commit
8ae4834d67
6 changed files with 7 additions and 53 deletions
|
|
@ -25,8 +25,7 @@ const RawGitako: React.FC<Props & ConnectorState> = 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<Props & ConnectorState> = 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],
|
||||
|
|
|
|||
|
|
@ -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<MetaData>) {
|
||||
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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { raiseError } from 'analytics'
|
||||
import { isInRepoPage } from './DOMHelper'
|
||||
|
||||
export function parse(): Partial<MetaData> & { 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<MetaData>) {
|
||||
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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
2
src/platforms/platform.d.ts
vendored
2
src/platforms/platform.d.ts
vendored
|
|
@ -6,7 +6,7 @@ type Platform = {
|
|||
accessToken?: string,
|
||||
): Promise<Pick<MetaData, 'userUrl' | 'repoUrl' | 'defaultBranchName'>>
|
||||
getTreeData(metaData: MetaData, accessToken?: string): Promise<TreeNode>
|
||||
shouldShow(metaData?: Partial<MetaData>): boolean
|
||||
shouldShow(): boolean
|
||||
getCurrentPath(branchName: string): string[] | null
|
||||
setOAuth(code: string): Promise<string | null>
|
||||
getOAuthLink(): string
|
||||
|
|
|
|||
Loading…
Reference in a new issue