From 148e058cde906b0cfdd92a238ce4a1a70cf23c19 Mon Sep 17 00:00:00 2001 From: EYHN Date: Tue, 30 Apr 2024 04:46:02 +0000 Subject: [PATCH] refactor(core): remove once signed in event (#6740) This once signed in event does not work properly. --- packages/frontend/core/src/atoms/event.ts | 25 ------------------- .../src/hooks/affine/use-enable-cloud.tsx | 16 +++--------- packages/frontend/core/src/pages/invite.tsx | 5 ---- 3 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 packages/frontend/core/src/atoms/event.ts diff --git a/packages/frontend/core/src/atoms/event.ts b/packages/frontend/core/src/atoms/event.ts deleted file mode 100644 index 68f1db9609..0000000000 --- a/packages/frontend/core/src/atoms/event.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { atom, useAtom } from 'jotai'; -import { useCallback } from 'react'; - -export type OnceSignedInEvent = () => void; - -export const onceSignedInEventsAtom = atom([]); - -export const setOnceSignedInEventAtom = atom( - null, - (get, set, event: OnceSignedInEvent) => { - set(onceSignedInEventsAtom, [...get(onceSignedInEventsAtom), event]); - } -); - -export const useOnceSignedInEvents = () => { - const [events, setEvents] = useAtom(onceSignedInEventsAtom); - return useCallback(async () => { - try { - await Promise.all(events.map(event => event())); - } catch (err) { - console.error('Error executing one of the events:', err); - } - setEvents([]); - }, [events, setEvents]); -}; diff --git a/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx b/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx index 1a9bb3c425..a26e28b13f 100644 --- a/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx +++ b/packages/frontend/core/src/hooks/affine/use-enable-cloud.tsx @@ -1,6 +1,5 @@ import { useConfirmModal } from '@affine/component'; import { authAtom } from '@affine/core/atoms'; -import { setOnceSignedInEventAtom } from '@affine/core/atoms/event'; import { AuthService } from '@affine/core/modules/cloud'; import { WorkspaceSubPath } from '@affine/core/shared'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; @@ -32,7 +31,6 @@ export const useEnableCloud = () => { const t = useAFFiNEI18N(); const loginStatus = useLiveData(useService(AuthService).session.status$); const setAuthAtom = useSetAtom(authAtom); - const setOnceSignedInEvent = useSetAtom(setOnceSignedInEventAtom); const { openConfirmModal, closeConfirmModal } = useConfirmModal(); const workspacesService = useService(WorkspacesService); const { openPage } = useNavigateHelper(); @@ -47,21 +45,15 @@ export const useEnableCloud = () => { [openPage, workspacesService] ); - const openSignIn = useCallback( - (...args: ConfirmEnableArgs) => { - setAuthAtom(prev => ({ ...prev, openModal: true })); - setOnceSignedInEvent(() => { - enableCloud(...args).catch(console.error); - }); - }, - [enableCloud, setAuthAtom, setOnceSignedInEvent] - ); + const openSignIn = useCallback(() => { + setAuthAtom(prev => ({ ...prev, openModal: true })); + }, [setAuthAtom]); const signInOrEnableCloud = useCallback( async (...args: ConfirmEnableArgs) => { // not logged in, open login modal if (loginStatus === 'unauthenticated') { - openSignIn(...args); + openSignIn(); } if (loginStatus === 'authenticated') { diff --git a/packages/frontend/core/src/pages/invite.tsx b/packages/frontend/core/src/pages/invite.tsx index 8fff63943d..c28cb4b31a 100644 --- a/packages/frontend/core/src/pages/invite.tsx +++ b/packages/frontend/core/src/pages/invite.tsx @@ -13,7 +13,6 @@ import type { LoaderFunction } from 'react-router-dom'; import { redirect, useLoaderData } from 'react-router-dom'; import { authAtom } from '../atoms'; -import { setOnceSignedInEventAtom } from '../atoms/event'; import { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper'; import { AuthService } from '../modules/cloud'; @@ -59,8 +58,6 @@ export const Component = () => { const { jumpToSignIn } = useNavigateHelper(); const { jumpToSubPath } = useNavigateHelper(); - const setOnceSignedInEvent = useSetAtom(setOnceSignedInEventAtom); - const setAuthAtom = useSetAtom(authAtom); const { inviteInfo } = useLoaderData() as { inviteId: string; @@ -78,7 +75,6 @@ export const Component = () => { useEffect(() => { if (loginStatus === 'unauthenticated' && !isRevalidating) { // We can not pass function to navigate state, so we need to save it in atom - setOnceSignedInEvent(openWorkspace); jumpToSignIn( `/workspace/${inviteInfo.workspace.id}/all`, RouteLogic.REPLACE @@ -91,7 +87,6 @@ export const Component = () => { loginStatus, openWorkspace, setAuthAtom, - setOnceSignedInEvent, ]); if (loginStatus === 'authenticated') {