mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: extract createAnchorClickHandler
This commit is contained in:
parent
fc3e19650d
commit
9c4152fce6
3 changed files with 13 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
12
src/utils/createAnchorClickHandler.ts
Normal file
12
src/utils/createAnchorClickHandler.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue