mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
✨ feat: 实现清空所有会话消息
This commit is contained in:
@@ -22,8 +22,8 @@ const BottomAction = memo<{ children: ReactNode }>(({ children }) => {
|
||||
const { t } = useTranslation('common');
|
||||
|
||||
const { exportSessions, exportSettings, exportAll, exportAgents } = useExportConfig();
|
||||
|
||||
const { importConfig } = useImportConfig();
|
||||
|
||||
const items: MenuProps['items'] = useMemo(
|
||||
() => [
|
||||
{
|
||||
|
||||
@@ -2,9 +2,10 @@ export default {
|
||||
danger: {
|
||||
clear: {
|
||||
action: '立即清除',
|
||||
confirm: '确认清除所有聊天、设置数据?',
|
||||
desc: '清除所有聊天、设置数据',
|
||||
title: '清除所有数据',
|
||||
confirm: '确认清除所有聊天数据?',
|
||||
desc: '清除所有会话数据',
|
||||
success: '已清除所有会话消息',
|
||||
title: '清除所有会话消息',
|
||||
},
|
||||
reset: {
|
||||
action: '立即重置',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Form, type ItemGroup, ThemeSwitch } from '@lobehub/ui';
|
||||
import { Form as AntForm, Button, Input, Popconfirm, Select, Switch } from 'antd';
|
||||
import { Form as AntForm, App, Button, Input, Select, Switch } from 'antd';
|
||||
import isEqual from 'fast-deep-equal';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { AppWindow, BrainCog, MessagesSquare, Palette, Webhook } from 'lucide-react';
|
||||
@@ -11,6 +11,7 @@ import { shallow } from 'zustand/shallow';
|
||||
import { FORM_STYLE } from '@/const/layoutTokens';
|
||||
import AvatarWithUpload from '@/features/AvatarWithUpload';
|
||||
import { options } from '@/locales/options';
|
||||
import { useSessionStore } from '@/store/session';
|
||||
import { settingsSelectors, useSettings } from '@/store/settings';
|
||||
import { DEFAULT_SETTINGS } from '@/store/settings/initialState';
|
||||
import { LanguageModel } from '@/types/llm';
|
||||
@@ -27,6 +28,7 @@ type SettingItemGroup = ItemGroup & {
|
||||
const SettingForm = memo(() => {
|
||||
const { t } = useTranslation('setting');
|
||||
const [form] = AntForm.useForm();
|
||||
const clearSessions = useSessionStore((s) => s.clearSessions);
|
||||
const settings = useSettings(settingsSelectors.currentSettings, isEqual);
|
||||
const { setThemeMode, setSettings, resetSettings } = useSettings(
|
||||
(s) => ({
|
||||
@@ -37,14 +39,35 @@ const SettingForm = memo(() => {
|
||||
shallow,
|
||||
);
|
||||
|
||||
const { message, modal } = App.useApp();
|
||||
const handleReset = useCallback(() => {
|
||||
resetSettings();
|
||||
form.setFieldsValue(DEFAULT_SETTINGS);
|
||||
modal.confirm({
|
||||
cancelText: t('cancel', { ns: 'common' }),
|
||||
centered: true,
|
||||
okButtonProps: { danger: true },
|
||||
okText: t('ok', { ns: 'common' }),
|
||||
onOk: () => {
|
||||
resetSettings();
|
||||
form.setFieldsValue(DEFAULT_SETTINGS);
|
||||
},
|
||||
title: t('danger.reset.confirm'),
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleClear = useCallback(() => {
|
||||
handleReset();
|
||||
// TODO: 删除聊天记录
|
||||
modal.confirm({
|
||||
cancelText: t('cancel', { ns: 'common' }),
|
||||
centered: true,
|
||||
okButtonProps: {
|
||||
danger: true,
|
||||
},
|
||||
okText: t('ok', { ns: 'common' }),
|
||||
onOk: () => {
|
||||
clearSessions();
|
||||
message.success(t('danger.clear.success'));
|
||||
},
|
||||
title: t('danger.clear.confirm'),
|
||||
});
|
||||
}, []);
|
||||
|
||||
const theme: SettingItemGroup = useMemo(
|
||||
@@ -240,18 +263,9 @@ const SettingForm = memo(() => {
|
||||
},
|
||||
{
|
||||
children: (
|
||||
<Popconfirm
|
||||
arrow={false}
|
||||
cancelText={t('cancel', { ns: 'common' })}
|
||||
okButtonProps={{ danger: true }}
|
||||
okText={t('ok', { ns: 'common' })}
|
||||
onConfirm={handleReset}
|
||||
title={t('danger.reset.confirm')}
|
||||
>
|
||||
<Button danger type="primary">
|
||||
{t('danger.reset.action')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Button danger onClick={handleReset} type="primary">
|
||||
{t('danger.reset.action')}
|
||||
</Button>
|
||||
),
|
||||
desc: t('danger.reset.title'),
|
||||
label: t('danger.reset.desc'),
|
||||
@@ -259,18 +273,9 @@ const SettingForm = memo(() => {
|
||||
},
|
||||
{
|
||||
children: (
|
||||
<Popconfirm
|
||||
arrow={false}
|
||||
cancelText={t('cancel', { ns: 'common' })}
|
||||
okButtonProps={{ danger: true }}
|
||||
okText={t('ok', { ns: 'common' })}
|
||||
onConfirm={handleClear}
|
||||
title={t('danger.clear.confirm')}
|
||||
>
|
||||
<Button danger type="primary">
|
||||
{t('danger.clear.action')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Button danger onClick={handleClear} type="primary">
|
||||
{t('danger.clear.action')}
|
||||
</Button>
|
||||
),
|
||||
desc: t('danger.clear.title'),
|
||||
label: t('danger.clear.desc'),
|
||||
|
||||
@@ -11,18 +11,20 @@ import { SessionDispatch, sessionsReducer } from './reducers/session';
|
||||
|
||||
export interface SessionAction {
|
||||
activeSession: (sessionId: string) => void;
|
||||
clearSessions: () => void;
|
||||
|
||||
/**
|
||||
* @title 添加会话
|
||||
* @param session - 会话信息
|
||||
* @returns void
|
||||
*/
|
||||
createSession: () => Promise<string>;
|
||||
|
||||
/**
|
||||
* 变更session
|
||||
* @param payload - 聊天记录
|
||||
*/
|
||||
dispatchSession: (payload: SessionDispatch) => void;
|
||||
|
||||
/**
|
||||
* 导入会话
|
||||
* @param sessions
|
||||
@@ -34,14 +36,12 @@ export interface SessionAction {
|
||||
* @returns 压缩后的消息
|
||||
*/
|
||||
// genShareUrl: () => string;
|
||||
|
||||
/**
|
||||
* @title 删除会话
|
||||
* @param index - 会话索引
|
||||
* @returns void
|
||||
*/
|
||||
removeSession: (sessionId: string) => void;
|
||||
|
||||
/**
|
||||
* @title 切换会话
|
||||
* @param sessionId - 会话索引
|
||||
@@ -60,6 +60,10 @@ export const createSessionSlice: StateCreator<
|
||||
set({ activeId: sessionId });
|
||||
},
|
||||
|
||||
clearSessions: () => {
|
||||
set({ sessions: {} });
|
||||
},
|
||||
|
||||
createSession: async () => {
|
||||
const { dispatchSession, switchSession } = get();
|
||||
|
||||
@@ -100,7 +104,6 @@ export const createSessionSlice: StateCreator<
|
||||
}),
|
||||
});
|
||||
},
|
||||
|
||||
removeSession: (sessionId) => {
|
||||
get().dispatchSession({ id: sessionId, type: 'removeSession' });
|
||||
|
||||
@@ -108,6 +111,7 @@ export const createSessionSlice: StateCreator<
|
||||
Router.push('/');
|
||||
}
|
||||
},
|
||||
|
||||
switchSession: async (sessionId) => {
|
||||
if (get().activeId === sessionId) return;
|
||||
|
||||
@@ -118,7 +122,6 @@ export const createSessionSlice: StateCreator<
|
||||
// 新会话
|
||||
await Router.push(`/chat/${sessionId}`);
|
||||
},
|
||||
|
||||
// genShareUrl: () => {
|
||||
// const session = sessionSelectors.currentSession(get());
|
||||
// if (!session) return '';
|
||||
|
||||
@@ -49,7 +49,11 @@ export const createSettings: StateCreator<
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { OPENAI_API_KEY: _, password: __, ...settings } = importSettings;
|
||||
|
||||
setSettings(settings);
|
||||
setSettings({
|
||||
...settings,
|
||||
// 如果用户存在用户头像,那么不做导入
|
||||
avatar: get().settings.avatar ?? settings.avatar,
|
||||
});
|
||||
},
|
||||
resetSettings: () => {
|
||||
set({ settings: DEFAULT_SETTINGS });
|
||||
|
||||
Reference in New Issue
Block a user