Skip to content

Commit

Permalink
feat: cleanup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 12, 2024
1 parent 16c95e6 commit 7c5ca16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { extractLinkSearchParams } from '@affine/core/utils/link';
import { useService } from '@toeverything/infra';
import { useEffect, useRef } from 'react';
import {
Expand Down Expand Up @@ -27,9 +28,7 @@ type LoaderData = z.infer<typeof LoaderData>;
type ParsedState = z.infer<typeof ParsedState>;

async function parseState(url: string): Promise<ParsedState> {
const { code, state: stateStr } = Array.from(
new URL(url).searchParams.entries()
).reduce((acc, [k, v]) => ((acc[k] = v), acc), {} as Record<string, string>);
const { code, state: stateStr } = extractLinkSearchParams(url);
if (!code || !stateStr) throw new Error('Invalid oauth callback parameters');
try {
/** @deprecated old client compatibility*/
Expand Down
8 changes: 2 additions & 6 deletions packages/frontend/core/src/desktop/pages/open-app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenInAppPage } from '@affine/core/modules/open-in-app/views/open-in-app-page';
import { appSchemaUrl, appSchemes } from '@affine/core/utils';
import { extractLinkSearchParams } from '@affine/core/utils/link';
import type { GetCurrentUserQuery } from '@affine/graphql';
import { fetcher, getCurrentUserQuery } from '@affine/graphql';
import type { LoaderFunction } from 'react-router-dom';
Expand Down Expand Up @@ -67,12 +68,7 @@ export const loader: LoaderFunction = async args => {
const action = args.params.action || '';

try {
const { url, ...params } = Array.from(
new URL(args.request.url).searchParams.entries()
).reduce(
(acc, [k, v]) => ((acc[k] = v), acc),
{} as Record<string, string>
);
const { url, ...params } = extractLinkSearchParams(args.request.url);
const res =
(action === 'signin-redirect' &&
(await fetcher({
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/core/src/utils/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function extractLinkSearchParams(link: string): Record<string, string> {
return Array.from(new URL(link).searchParams.entries()).reduce(
(acc, [k, v]) => ((acc[k] = v), acc),
{} as Record<string, string>
);
}

0 comments on commit 7c5ca16

Please sign in to comment.