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