refactor: extract createAnchorClickHandler

This commit is contained in:
EnixCoda 2022-04-24 00:02:02 +08:00
parent fc3e19650d
commit 9c4152fce6
3 changed files with 13 additions and 11 deletions

View file

@ -2,7 +2,7 @@ import { BranchName, Breadcrumb, Flex, Text } from '@primer/components'
import { GitBranchIcon } from '@primer/octicons-react'
import { platform } from 'platforms'
import * as React from 'react'
import { createAnchorClickHandler } from 'utils/general'
import { createAnchorClickHandler } from "utils/createAnchorClickHandler"
type Props = {
metaData: MetaData

View file

@ -0,0 +1,12 @@
import { isOpenInNewWindowClick } from './general';
import { loadWithPJAX } from './hooks/usePJAX';
export function createAnchorClickHandler(url: string) {
return (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
if (isOpenInNewWindowClick(e))
return;
e.preventDefault();
loadWithPJAX(url, e.currentTarget);
};
}

View file

@ -1,6 +1,5 @@
import { ReactElement } from 'react'
import * as ReactDOM from 'react-dom'
import { loadWithPJAX } from './hooks/usePJAX'
export function pick<T>(source: T, keys: string[]): Partial<T> {
if (keys && typeof keys === 'object') {
@ -220,12 +219,3 @@ export function resolveDiffGraphMeta(additions: number, deletions: number, chang
w = 5 - g - r
return { g, r, w }
}
export function createAnchorClickHandler(url: string) {
return (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
if (isOpenInNewWindowClick(e)) return
e.preventDefault()
loadWithPJAX(url, e.currentTarget)
}
}