From 9c4152fce6ff04a4e02bdbb0e84320a86d8f5f4c Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 24 Apr 2022 00:02:02 +0800 Subject: [PATCH] refactor: extract createAnchorClickHandler --- src/components/MetaBar.tsx | 2 +- src/utils/createAnchorClickHandler.ts | 12 ++++++++++++ src/utils/general.ts | 10 ---------- 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 src/utils/createAnchorClickHandler.ts diff --git a/src/components/MetaBar.tsx b/src/components/MetaBar.tsx index 903d954..bb7e0cc 100644 --- a/src/components/MetaBar.tsx +++ b/src/components/MetaBar.tsx @@ -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 diff --git a/src/utils/createAnchorClickHandler.ts b/src/utils/createAnchorClickHandler.ts new file mode 100644 index 0000000..e7f95e8 --- /dev/null +++ b/src/utils/createAnchorClickHandler.ts @@ -0,0 +1,12 @@ +import { isOpenInNewWindowClick } from './general'; +import { loadWithPJAX } from './hooks/usePJAX'; + +export function createAnchorClickHandler(url: string) { + return (e: React.MouseEvent) => { + if (isOpenInNewWindowClick(e)) + return; + + e.preventDefault(); + loadWithPJAX(url, e.currentTarget); + }; +} diff --git a/src/utils/general.ts b/src/utils/general.ts index 0b928c8..619b889 100644 --- a/src/utils/general.ts +++ b/src/utils/general.ts @@ -1,6 +1,5 @@ import { ReactElement } from 'react' import * as ReactDOM from 'react-dom' -import { loadWithPJAX } from './hooks/usePJAX' export function pick(source: T, keys: string[]): Partial { 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) => { - if (isOpenInNewWindowClick(e)) return - - e.preventDefault() - loadWithPJAX(url, e.currentTarget) - } -}