Skip to content

Commit 73de1f0

Browse files
authored
add storage page
1 parent 95aab65 commit 73de1f0

File tree

13 files changed

+451
-212
lines changed

13 files changed

+451
-212
lines changed

src/app/(main)/settings/storage/page.tsx

-140
This file was deleted.

src/app/[variants]/(main)/settings/common/features/Common.tsx

-44
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ import { useTranslation } from 'react-i18next';
99
import { useSyncSettings } from '@/app/[variants]/(main)/settings/hooks/useSyncSettings';
1010
import { FORM_STYLE } from '@/const/layoutTokens';
1111
import { DEFAULT_SETTINGS } from '@/const/settings';
12-
import { useChatStore } from '@/store/chat';
13-
import { useFileStore } from '@/store/file';
1412
import { useServerConfigStore } from '@/store/serverConfig';
1513
import { serverConfigSelectors } from '@/store/serverConfig/selectors';
16-
import { useSessionStore } from '@/store/session';
17-
import { useToolStore } from '@/store/tool';
1814
import { useUserStore } from '@/store/user';
1915
import { settingsSelectors } from '@/store/user/selectors';
2016

@@ -26,16 +22,6 @@ const Common = memo(() => {
2622

2723
const showAccessCodeConfig = useServerConfigStore(serverConfigSelectors.enabledAccessCode);
2824

29-
const [clearSessions, clearSessionGroups] = useSessionStore((s) => [
30-
s.clearSessions,
31-
s.clearSessionGroups,
32-
]);
33-
const [clearTopics, clearAllMessages] = useChatStore((s) => [
34-
s.removeAllTopics,
35-
s.clearAllMessages,
36-
]);
37-
const [removeAllFiles] = useFileStore((s) => [s.removeAllFiles]);
38-
const removeAllPlugins = useToolStore((s) => s.removeAllPlugins);
3925
const settings = useUserStore(settingsSelectors.currentSettings, isEqual);
4026
const [setSettings, resetSettings] = useUserStore((s) => [s.setSettings, s.resetSettings]);
4127

@@ -54,26 +40,6 @@ const Common = memo(() => {
5440
});
5541
}, []);
5642

57-
const handleClear = useCallback(() => {
58-
modal.confirm({
59-
centered: true,
60-
okButtonProps: {
61-
danger: true,
62-
},
63-
onOk: async () => {
64-
await clearSessions();
65-
await removeAllPlugins();
66-
await clearTopics();
67-
await removeAllFiles();
68-
await clearAllMessages();
69-
await clearSessionGroups();
70-
71-
message.success(t('danger.clear.success'));
72-
},
73-
title: t('danger.clear.confirm'),
74-
});
75-
}, []);
76-
7743
const system: SettingItemGroup = {
7844
children: [
7945
{
@@ -98,16 +64,6 @@ const Common = memo(() => {
9864
label: t('danger.reset.title'),
9965
minWidth: undefined,
10066
},
101-
{
102-
children: (
103-
<Button danger onClick={handleClear} type="primary">
104-
{t('danger.clear.action')}
105-
</Button>
106-
),
107-
desc: t('danger.clear.desc'),
108-
label: t('danger.clear.title'),
109-
minWidth: undefined,
110-
},
11167
],
11268
title: t('settingSystem.title'),
11369
};

src/app/[variants]/(main)/settings/hooks/useCategory.tsx

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Icon } from '@lobehub/ui';
22
import { Tag } from 'antd';
3-
import { Bot, Brain, Cloudy, Info, Mic2, Settings2, Sparkles } from 'lucide-react';
3+
import { Bot, Brain, Cloudy, Database, Info, Mic2, Settings2, Sparkles } from 'lucide-react';
44
import Link from 'next/link';
55
import { useMemo } from 'react';
66
import { useTranslation } from 'react-i18next';
@@ -52,26 +52,26 @@ export const useCategory = () => {
5252
),
5353
},
5454
showLLM &&
55-
// TODO: Remove /llm when v2.0
56-
(isDeprecatedEdition
57-
? {
58-
icon: <Icon icon={Brain} />,
59-
key: SettingsTabs.LLM,
60-
label: (
61-
<Link href={'/settings/llm'} onClick={(e) => e.preventDefault()}>
62-
{t('tab.llm')}
63-
</Link>
64-
),
65-
}
66-
: {
67-
icon: <Icon icon={Brain} />,
68-
key: SettingsTabs.Provider,
69-
label: (
70-
<Link href={'/settings/provider'} onClick={(e) => e.preventDefault()}>
71-
{t('tab.provider')}
72-
</Link>
73-
),
74-
}),
55+
// TODO: Remove /llm when v2.0
56+
(isDeprecatedEdition
57+
? {
58+
icon: <Icon icon={Brain} />,
59+
key: SettingsTabs.LLM,
60+
label: (
61+
<Link href={'/settings/llm'} onClick={(e) => e.preventDefault()}>
62+
{t('tab.llm')}
63+
</Link>
64+
),
65+
}
66+
: {
67+
icon: <Icon icon={Brain} />,
68+
key: SettingsTabs.Provider,
69+
label: (
70+
<Link href={'/settings/provider'} onClick={(e) => e.preventDefault()}>
71+
{t('tab.provider')}
72+
</Link>
73+
),
74+
}),
7575

7676
enableSTT && {
7777
icon: <Icon icon={Mic2} />,
@@ -91,6 +91,15 @@ export const useCategory = () => {
9191
</Link>
9292
),
9393
},
94+
{
95+
icon: <Icon icon={Database} />,
96+
key: SettingsTabs.Storage,
97+
label: (
98+
<Link href={'/settings/storage'} onClick={(e) => e.preventDefault()}>
99+
{t('tab.storage')}
100+
</Link>
101+
),
102+
},
94103
!hideDocs && {
95104
icon: <Icon icon={Info} />,
96105
key: SettingsTabs.About,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use client';
2+
3+
import { Form, type ItemGroup } from '@lobehub/ui';
4+
import { App, Button } from 'antd';
5+
import isEqual from 'fast-deep-equal';
6+
import { useCallback } from 'react';
7+
import { useTranslation } from 'react-i18next';
8+
9+
import { FORM_STYLE } from '@/const/layoutTokens';
10+
import { useChatStore } from '@/store/chat';
11+
import { useFileStore } from '@/store/file';
12+
import { useSessionStore } from '@/store/session';
13+
import { useToolStore } from '@/store/tool';
14+
import { useUserStore } from '@/store/user';
15+
import { settingsSelectors } from '@/store/user/selectors';
16+
17+
const AdvancedActions = () => {
18+
const { t } = useTranslation('setting');
19+
const [form] = Form.useForm();
20+
const { message, modal } = App.useApp();
21+
const [clearSessions, clearSessionGroups] = useSessionStore((s) => [
22+
s.clearSessions,
23+
s.clearSessionGroups,
24+
]);
25+
const [clearTopics, clearAllMessages] = useChatStore((s) => [
26+
s.removeAllTopics,
27+
s.clearAllMessages,
28+
]);
29+
const [removeAllFiles] = useFileStore((s) => [s.removeAllFiles]);
30+
const removeAllPlugins = useToolStore((s) => s.removeAllPlugins);
31+
const settings = useUserStore(settingsSelectors.currentSettings, isEqual);
32+
33+
const handleClear = useCallback(() => {
34+
modal.confirm({
35+
centered: true,
36+
okButtonProps: {
37+
danger: true,
38+
},
39+
onOk: async () => {
40+
await clearSessions();
41+
await removeAllPlugins();
42+
await clearTopics();
43+
await removeAllFiles();
44+
await clearAllMessages();
45+
await clearSessionGroups();
46+
47+
message.success(t('danger.clear.success'));
48+
},
49+
title: t('danger.clear.confirm'),
50+
});
51+
}, []);
52+
53+
const system: ItemGroup = {
54+
children: [
55+
{
56+
children: (
57+
<Button danger onClick={handleClear} type="primary">
58+
{t('danger.clear.action')}
59+
</Button>
60+
),
61+
desc: t('danger.clear.desc'),
62+
label: t('danger.clear.title'),
63+
minWidth: undefined,
64+
},
65+
],
66+
title: t('storage.actions.title'),
67+
};
68+
return (
69+
<Form
70+
form={form}
71+
initialValues={settings}
72+
items={[system]}
73+
itemsType={'group'}
74+
variant={'pure'}
75+
{...FORM_STYLE}
76+
/>
77+
);
78+
};
79+
80+
export default AdvancedActions;

0 commit comments

Comments
 (0)