From 1e4a509a234e4592f5b81f586b0020452866c479 Mon Sep 17 00:00:00 2001 From: lazzzis Date: Tue, 5 Jul 2022 21:11:25 -0700 Subject: [PATCH] style: revert changes on src/ and __test__ --- __tests__/cases/non-parallel/pjax.general.ts | 2 +- __tests__/cases/non-parallel/pjax.internal.ts | 2 +- .../cases/non-parallel/project-page.gitako.ts | 6 ++---- __tests__/cases/parallel/expand-to-target.ts | 7 ++++++- __tests__/utils.ts | 6 ++---- src/components/Icon.tsx | 2 +- src/components/MetaBar.tsx | 2 +- src/components/SideBarBodyWrapper.tsx | 2 +- src/content.tsx | 2 +- src/global.d.ts | 4 ++-- src/platforms/GitHub/DOMHelper.ts | 3 ++- src/platforms/Gitea/API.ts | 21 ++++++++++--------- src/platforms/Gitea/URLHelper.ts | 2 +- src/utils/EventHub.ts | 2 +- src/utils/hooks/useResizeHandler.tsx | 3 +-- src/utils/hooks/useStateIO.ts | 4 +++- 16 files changed, 37 insertions(+), 33 deletions(-) diff --git a/__tests__/cases/non-parallel/pjax.general.ts b/__tests__/cases/non-parallel/pjax.general.ts index 993d3d8..76657f4 100644 --- a/__tests__/cases/non-parallel/pjax.general.ts +++ b/__tests__/cases/non-parallel/pjax.general.ts @@ -4,7 +4,7 @@ import { patientClick, selectFileTreeItem, sleep, - waitForLegacyPJAXRedirect, + waitForLegacyPJAXRedirect } from '../../utils' describe(`in Gitako project page`, () => { diff --git a/__tests__/cases/non-parallel/pjax.internal.ts b/__tests__/cases/non-parallel/pjax.internal.ts index 63f6988..4b57bec 100644 --- a/__tests__/cases/non-parallel/pjax.internal.ts +++ b/__tests__/cases/non-parallel/pjax.internal.ts @@ -5,7 +5,7 @@ import { patientClick, selectFileTreeItem, sleep, - waitForLegacyPJAXRedirect, + waitForLegacyPJAXRedirect } from '../../utils' describe(`in Gitako project page`, () => { diff --git a/__tests__/cases/non-parallel/project-page.gitako.ts b/__tests__/cases/non-parallel/project-page.gitako.ts index d00769a..8182fda 100644 --- a/__tests__/cases/non-parallel/project-page.gitako.ts +++ b/__tests__/cases/non-parallel/project-page.gitako.ts @@ -3,13 +3,11 @@ import { expectToFind, expectToNotFind, scroll, - selectFileTreeItem, + selectFileTreeItem } from '../../utils' describe(`in Gitako project page`, () => { - beforeAll(() => - page.goto('https://github.com/EnixCoda/Gitako/tree/test/200-changed-files-200-lines-each'), - ) + beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/tree/test/200-changed-files-200-lines-each')) it('should render Gitako', async () => { await expectToFind('.gitako-side-bar .gitako-side-bar-body-wrapper') diff --git a/__tests__/cases/parallel/expand-to-target.ts b/__tests__/cases/parallel/expand-to-target.ts index 519addd..4be5dc0 100644 --- a/__tests__/cases/parallel/expand-to-target.ts +++ b/__tests__/cases/parallel/expand-to-target.ts @@ -1,4 +1,9 @@ -import { expectToFind, selectFileTreeItem, sleep, waitForLegacyPJAXRedirect } from '../../utils' +import { + expectToFind, + selectFileTreeItem, + sleep, + waitForLegacyPJAXRedirect +} from '../../utils' describe(`in Gitako project page`, () => { beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/tree/develop/src')) diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 4910897..88d5238 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -40,7 +40,7 @@ export async function listenTo( (event, target, callbackName, oneTime) => { const t = target === 'document' ? document : window const onEvent = (...args: any[]): void => { - ;(window[callbackName as any] as any as (...args: any[]) => void)(...args) + ;((window[callbackName as any] as any) as (...args: any[]) => void)(...args) if (oneTime) t.removeEventListener(event, onEvent) } t.addEventListener(event, onEvent) @@ -81,9 +81,7 @@ export async function patientClick(selector: string) { } export async function expandFloatModeSidebar() { - const rect = await ( - await page.$('.gitako-toggle-show-button') - )?.evaluate(button => { + const rect = await (await page.$('.gitako-toggle-show-button'))?.evaluate(button => { const { x, y, width, height } = button.getBoundingClientRect() // pass required properties to avoid serialization issues return { x, y, width, height } diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index fe70ad2..1204d18 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -24,7 +24,7 @@ import { ReplyIcon as Reply, SearchIcon as Search, TabIcon as Tab, - XIcon as X, + XIcon as X } from '@primer/octicons-react' import * as React from 'react' import { cx } from 'utils/cx' diff --git a/src/components/MetaBar.tsx b/src/components/MetaBar.tsx index 221e3ba..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/createAnchorClickHandler' +import { createAnchorClickHandler } from "utils/createAnchorClickHandler" type Props = { metaData: MetaData diff --git a/src/components/SideBarBodyWrapper.tsx b/src/components/SideBarBodyWrapper.tsx index cc200ef..4698895 100644 --- a/src/components/SideBarBodyWrapper.tsx +++ b/src/components/SideBarBodyWrapper.tsx @@ -104,7 +104,7 @@ export function SideBarBodyWrapper({ const dummySize: [number, number] = React.useMemo(() => [size, size], [size]) - const defaultSideBarWidth = React.useMemo(() => getDefaultConfigs().sideBarWidth, []) + const defaultSideBarWidth = React.useMemo(() => getDefaultConfigs().sideBarWidth, []); return (
(element as HTMLAnchorElement).href, diff --git a/src/platforms/Gitea/API.ts b/src/platforms/Gitea/API.ts index 688302c..d86a1ca 100644 --- a/src/platforms/Gitea/API.ts +++ b/src/platforms/Gitea/API.ts @@ -77,7 +77,8 @@ export async function getTreeData( ): Promise { const search = new URLSearchParams() if (recursive) search.set('recursive', '1') - const url = `${API_ENDPOINT}/repos/${userName}/${repoName}/git/trees/${branchName}?` + search + const url = + `${API_ENDPOINT}/repos/${userName}/${repoName}/git/trees/${branchName}?` + search return await request(url, { accessToken }) } @@ -93,14 +94,14 @@ export async function getBlobData( export async function OAuth(code: string): Promise { const endpoint = `https://gitako.enix.one/oauth/gitea?` - const res = await fetch(endpoint + new URLSearchParams({ code }).toString(), { - method: 'post', - }) + const res = await fetch(endpoint + new URLSearchParams({ code }).toString(), { + method: 'post', + }) - if (res.ok) { - const body = await res.json() - const accessToken = body?.accessToken - if (typeof accessToken === 'string') return accessToken - } - return null + if (res.ok) { + const body = await res.json() + const accessToken = body?.accessToken + if (typeof accessToken === 'string') return accessToken + } + return null } diff --git a/src/platforms/Gitea/URLHelper.ts b/src/platforms/Gitea/URLHelper.ts index 0a539da..a68b81f 100644 --- a/src/platforms/Gitea/URLHelper.ts +++ b/src/platforms/Gitea/URLHelper.ts @@ -67,4 +67,4 @@ export function getCurrentPath(branchName = '') { return path.map(decodeURIComponent) } return [] -} +} \ No newline at end of file diff --git a/src/utils/EventHub.ts b/src/utils/EventHub.ts index aa5765d..1fc02c5 100644 --- a/src/utils/EventHub.ts +++ b/src/utils/EventHub.ts @@ -19,7 +19,7 @@ export class EventSubscription = VoidFN { ports: { [key in keyof Shape]: EventSubscription diff --git a/src/utils/hooks/useResizeHandler.tsx b/src/utils/hooks/useResizeHandler.tsx index 19032d9..2911a30 100644 --- a/src/utils/hooks/useResizeHandler.tsx +++ b/src/utils/hooks/useResizeHandler.tsx @@ -31,8 +31,7 @@ export function useResizeHandler( if (!pointerDown.current) return const [x0, y0] = initialSizeRef.current // Allow minor movement, this happened unintentionally for few times when I use track pad - pointerMoved.current = - pointerMoved.current || (clientX - x0) ** 2 + (clientY - y0) ** 2 > distanceTolerance ** 2 + pointerMoved.current = pointerMoved.current || (clientX - x0) ** 2 + (clientY - y0) ** 2 > distanceTolerance ** 2 const [x1, y1] = baseSize.current onResize([x1 + clientX - x0, y1 + clientY - y0]) } diff --git a/src/utils/hooks/useStateIO.ts b/src/utils/hooks/useStateIO.ts index 6a86132..f216a50 100644 --- a/src/utils/hooks/useStateIO.ts +++ b/src/utils/hooks/useStateIO.ts @@ -1,6 +1,8 @@ import * as React from 'react' -export function useStateIO(initialState: S | (() => S)): { +export function useStateIO( + initialState: S | (() => S), +): { value: S onChange: React.Dispatch> } {