mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(core): impl AI switch (#8018)
close PD-1658 https://github.com/user-attachments/assets/2f3d1d26-1879-4d95-b80c-7c0965cefbd0
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { NotificationCenter, notify } from '@affine/component';
|
||||
import { ConfirmModal, NotificationCenter, notify } from '@affine/component';
|
||||
import { events } from '@affine/electron-api';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@toeverything/infra';
|
||||
import { useAtom } from 'jotai';
|
||||
import type { ReactElement } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import type { SettingAtom } from '../atoms';
|
||||
import { openSettingModalAtom, openSignOutModalAtom } from '../atoms';
|
||||
@@ -31,6 +31,7 @@ import { useAsyncCallback } from '../hooks/affine-async-hooks';
|
||||
import { useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||
import { AuthService } from '../modules/cloud/services/auth';
|
||||
import { CreateWorkspaceDialogProvider } from '../modules/create-workspace';
|
||||
import { EditorSettingService } from '../modules/editor-settting';
|
||||
import { FindInPageModal } from '../modules/find-in-page/view/find-in-page-modal';
|
||||
import { ImportTemplateDialogProvider } from '../modules/import-template';
|
||||
import { PeekViewManagerModal } from '../modules/peek-view';
|
||||
@@ -183,6 +184,40 @@ export const SignOutConfirmModal = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const AIReloadConfirmModal = () => {
|
||||
const editorSettingService = useService(EditorSettingService);
|
||||
const enableAI = useLiveData(
|
||||
editorSettingService.editorSetting.settings$
|
||||
).enableAI;
|
||||
const [aiState] = useState(enableAI);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(enableAI !== aiState);
|
||||
}, [aiState, enableAI]);
|
||||
|
||||
const onConfirm = useCallback(() => {
|
||||
window.location.reload();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConfirmModal
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
onConfirm={onConfirm}
|
||||
confirmButtonOptions={{
|
||||
variant: 'primary',
|
||||
}}
|
||||
title={'You need to reload the page'}
|
||||
description={
|
||||
'AI settings have been updated. Please reload the page to apply the changes.'
|
||||
}
|
||||
cancelText={'Cancel'}
|
||||
confirmText={'Reload'}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const AllWorkspaceModals = (): ReactElement => {
|
||||
return (
|
||||
<>
|
||||
@@ -191,6 +226,7 @@ export const AllWorkspaceModals = (): ReactElement => {
|
||||
<CreateWorkspaceDialogProvider />
|
||||
<AuthModal />
|
||||
<SignOutConfirmModal />
|
||||
<AIReloadConfirmModal />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user