mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: catch unexpected PJAX with scope
This commit is contained in:
parent
f026a7dfd2
commit
4b96e01845
3 changed files with 13 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ import { cx } from 'utils/cx'
|
|||
import { parseURLSearch, run } from 'utils/general'
|
||||
import { loadWithPJAX, useOnPJAXDone, usePJAX } from 'utils/hooks/usePJAX'
|
||||
import { useProgressBar } from 'utils/hooks/useProgressBar'
|
||||
import { useStateIO } from 'utils/hooks/useStateIO'
|
||||
import * as keyHelper from 'utils/keyHelper'
|
||||
import { Icon } from './Icon'
|
||||
import { LoadingIndicator } from './LoadingIndicator'
|
||||
|
|
@ -47,9 +48,14 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
})
|
||||
}, [])
|
||||
|
||||
/**
|
||||
* Catch unexpected PJAX, force trigger init on scope change.
|
||||
*/
|
||||
const pageScope = useStateIO(platform.resolvePageScope?.())
|
||||
useOnPJAXDone(() => pageScope.onChange(platform.resolvePageScope?.()))
|
||||
React.useEffect(() => {
|
||||
props.init()
|
||||
}, [accessToken])
|
||||
}, [accessToken, pageScope.value])
|
||||
|
||||
React.useEffect(
|
||||
function attachKeyDown() {
|
||||
|
|
|
|||
|
|
@ -118,6 +118,11 @@ export const GitHub: Platform = {
|
|||
}
|
||||
return metaData
|
||||
},
|
||||
resolvePageScope() {
|
||||
if (URLHelper.parse().type === 'releases') return 'releases'
|
||||
if (URLHelper.isInPullPage()) return 'pull'
|
||||
return 'general'
|
||||
},
|
||||
async getDefaultBranchName({ userName, repoName }, accessToken) {
|
||||
const data = await API.getRepoMeta(userName, repoName, accessToken)
|
||||
return data.default_branch
|
||||
|
|
|
|||
1
src/platforms/platform.d.ts
vendored
1
src/platforms/platform.d.ts
vendored
|
|
@ -2,6 +2,7 @@ type Platform = {
|
|||
isEnterprise(): boolean
|
||||
// branch name might not be available when resolving from DOM and URL
|
||||
resolveMeta(): MakeOptional<MetaData, 'branchName'> | null
|
||||
resolvePageScope?(): string
|
||||
getDefaultBranchName(
|
||||
metaData: Pick<MetaData, 'userName' | 'repoName'>,
|
||||
accessToken?: string,
|
||||
|
|
|
|||
Loading…
Reference in a new issue