mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: emit pjax end
This commit is contained in:
parent
b0193985c5
commit
db0de416dc
5 changed files with 24 additions and 10 deletions
|
|
@ -200,8 +200,7 @@ function ListView({
|
|||
}, [metaData.branchName])
|
||||
|
||||
useOnLocationChange(goToCurrentItem)
|
||||
// `false` for ignoring pjax:end, which could cause unexpected results of history.goBack
|
||||
useOnPJAXDone(goToCurrentItem, false)
|
||||
useOnPJAXDone(goToCurrentItem)
|
||||
|
||||
const itemData = React.useMemo(
|
||||
() => ({
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@ import * as React from 'react'
|
|||
import { useUpdateEffect } from 'react-use'
|
||||
import { cx } from 'utils/cx'
|
||||
import { parseURLSearch } from 'utils/general'
|
||||
import { loadWithPJAX, useOnPJAXDone, usePJAX } from 'utils/hooks/usePJAX'
|
||||
import { loadWithPJAX, useOnPJAXDone, usePJAX, useRedirectedEvents } from 'utils/hooks/usePJAX'
|
||||
import { useProgressBar } from 'utils/hooks/useProgressBar'
|
||||
import * as keyHelper from 'utils/keyHelper'
|
||||
import { Icon } from './Icon'
|
||||
|
||||
const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
||||
useRedirectedEvents(document, 'pjax:ready', 'pjax:end')
|
||||
const configContext = useConfigs()
|
||||
const accessToken = props.configContext.val.access_token
|
||||
const [baseSize] = React.useState(() => configContext.val.sideBarWidth)
|
||||
|
|
@ -82,7 +83,7 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
},
|
||||
[props.metaData?.branchName, configContext.val.intelligentToggle],
|
||||
)
|
||||
useOnPJAXDone(updateSideBarVisibility)
|
||||
useOnPJAXDone(updateSideBarVisibility, true)
|
||||
|
||||
const copyFileButton = configContext.val.copyFileButton
|
||||
useGitHubAttachCopyFileButton(copyFileButton)
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ export function useGitHubAttachCopySnippetButton(copySnippetButton: boolean) {
|
|||
[copySnippetButton],
|
||||
)
|
||||
React.useEffect(attachCopySnippetButton, [copySnippetButton])
|
||||
useOnPJAXDone(attachCopySnippetButton)
|
||||
useOnPJAXDone(attachCopySnippetButton, true)
|
||||
}
|
||||
|
||||
export function useGitHubAttachCopyFileButton(copyFileButton: boolean) {
|
||||
|
|
@ -305,5 +305,5 @@ export function useGitHubAttachCopyFileButton(copyFileButton: boolean) {
|
|||
[copyFileButton],
|
||||
)
|
||||
React.useEffect(attachCopyFileButton, [copyFileButton])
|
||||
useOnPJAXDone(attachCopyFileButton)
|
||||
useOnPJAXDone(attachCopyFileButton, true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,5 +173,5 @@ export function useGiteeAttachCopySnippetButton(copySnippetButton: boolean) {
|
|||
[copySnippetButton],
|
||||
)
|
||||
React.useEffect(attachCopySnippetButton, [copySnippetButton])
|
||||
useOnPJAXDone(attachCopySnippetButton)
|
||||
useOnPJAXDone(attachCopySnippetButton, true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,21 @@ export const loadWithPJAX = (url: string) => {
|
|||
Pjax.assign(url, config)
|
||||
}
|
||||
|
||||
export function useOnPJAXDone(callback: () => void, both = true) {
|
||||
useEvent('pjax:ready', callback, document)
|
||||
if (both) useEvent('pjax:end', callback, document) // emit by GitHub
|
||||
export function useOnPJAXDone(callback: () => void, legacy?: boolean) {
|
||||
useEvent(legacy ? 'pjax:end' : 'pjax:ready', callback, document)
|
||||
}
|
||||
|
||||
export function useRedirectedEvents(
|
||||
originalTarget: Window | Document | Element,
|
||||
originalEvent: string,
|
||||
redirectedEvent: string,
|
||||
redirectToTarget = originalTarget,
|
||||
) {
|
||||
useEvent(
|
||||
originalEvent,
|
||||
() => {
|
||||
redirectToTarget.dispatchEvent(new Event(redirectedEvent))
|
||||
},
|
||||
originalTarget,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue