mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-29 14:03:24 +03:00
fix(core): adjust ai onboarding trigger logic, launch by auth status (#6941)
- if signed in, show ai-onboarding dialog - if not signed in, show ai onboarding toast
This commit is contained in:
parent
ad09bb6cd9
commit
6cef03c4c3
@ -1,18 +1,13 @@
|
||||
import { Button, IconButton, Modal } from '@affine/component';
|
||||
import { openSettingModalAtom } from '@affine/core/atoms';
|
||||
import { useBlurRoot } from '@affine/core/hooks/use-blur-root';
|
||||
import { SubscriptionService } from '@affine/core/modules/cloud';
|
||||
import { AuthService, SubscriptionService } from '@affine/core/modules/cloud';
|
||||
import { mixpanel } from '@affine/core/utils';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { Trans } from '@affine/i18n';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { ArrowLeftSmallIcon } from '@blocksuite/icons';
|
||||
import {
|
||||
useLiveData,
|
||||
useServices,
|
||||
WorkspaceService,
|
||||
} from '@toeverything/infra';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useLiveData, useServices } from '@toeverything/infra';
|
||||
import { useAtom } from 'jotai';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
@ -90,22 +85,23 @@ function prefetchVideos() {
|
||||
export const AIOnboardingGeneral = ({
|
||||
onDismiss,
|
||||
}: BaseAIOnboardingDialogProps) => {
|
||||
const { workspaceService, subscriptionService } = useServices({
|
||||
WorkspaceService,
|
||||
const { authService, subscriptionService } = useServices({
|
||||
AuthService,
|
||||
SubscriptionService,
|
||||
});
|
||||
|
||||
const videoWrapperRef = useRef<HTMLDivElement | null>(null);
|
||||
const prevVideoRef = useRef<HTMLVideoElement | null>(null);
|
||||
const isCloud =
|
||||
workspaceService.workspace.flavour === WorkspaceFlavour.AFFINE_CLOUD;
|
||||
const loginStatus = useLiveData(authService.session.status$);
|
||||
const isLoggedIn = loginStatus === 'authenticated';
|
||||
const t = useAFFiNEI18N();
|
||||
const open = useLiveData(showAIOnboardingGeneral$);
|
||||
const aiSubscription = useLiveData(subscriptionService.subscription.ai$);
|
||||
const [index, setIndex] = useState(0);
|
||||
const list = useMemo(() => getPlayList(t), [t]);
|
||||
const setSettingModal = useSetAtom(openSettingModalAtom);
|
||||
useBlurRoot(open && isCloud);
|
||||
const [settingModal, setSettingModal] = useAtom(openSettingModalAtom);
|
||||
const readyToOpen = isLoggedIn && !settingModal.open;
|
||||
useBlurRoot(open && readyToOpen);
|
||||
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === list.length - 1;
|
||||
@ -189,7 +185,7 @@ export const AIOnboardingGeneral = ({
|
||||
prevVideoRef.current = video;
|
||||
}, [index]);
|
||||
|
||||
return isCloud ? (
|
||||
return readyToOpen ? (
|
||||
<Modal
|
||||
open={open}
|
||||
onOpenChange={v => {
|
||||
|
@ -4,10 +4,9 @@ import {
|
||||
useNavigateHelper,
|
||||
} from '@affine/core/hooks/use-navigate-helper';
|
||||
import { AuthService } from '@affine/core/modules/cloud';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { AiIcon } from '@blocksuite/icons';
|
||||
import { useLiveData, useService, WorkspaceService } from '@toeverything/infra';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { cssVar } from '@toeverything/theme';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
@ -50,7 +49,7 @@ const FooterActions = ({ onDismiss }: { onDismiss: () => void }) => {
|
||||
type="plain"
|
||||
onClick={() => {
|
||||
onDismiss();
|
||||
jumpToSignIn('/', RouteLogic.REPLACE, {}, { initCloud: 'true' });
|
||||
jumpToSignIn('', RouteLogic.REPLACE, {}, { initCloud: 'true' });
|
||||
}}
|
||||
>
|
||||
{t['com.affine.ai-onboarding.local.action-get-started']()}
|
||||
@ -64,14 +63,15 @@ export const AIOnboardingLocal = ({
|
||||
onDismiss,
|
||||
}: BaseAIOnboardingDialogProps) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const workspaceService = useService(WorkspaceService);
|
||||
const authService = useService(AuthService);
|
||||
const notifyId = useLiveData(localNotifyId$);
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
|
||||
const isLocal = workspaceService.workspace.flavour === WorkspaceFlavour.LOCAL;
|
||||
const loginStatus = useLiveData(authService.session.status$);
|
||||
const notSignedIn = loginStatus !== 'authenticated';
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLocal) return;
|
||||
if (!notSignedIn) return;
|
||||
if (notifyId) return;
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
@ -105,7 +105,7 @@ export const AIOnboardingLocal = ({
|
||||
);
|
||||
localNotifyId$.next(id);
|
||||
}, 1000);
|
||||
}, [isLocal, notifyId, onDismiss, t]);
|
||||
}, [notSignedIn, notifyId, onDismiss, t]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user