Skip to content

Commit 767fb8d

Browse files
authored
Merge pull request #227 from import-ai/feat/ai_tags_toggle
feat(option): Add AI tag extraction toggle for users
2 parents 8ac6f8a + e29fdc4 commit 767fb8d

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

src/i18n/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
"namespace": "Namespace",
178178
"api_key": "API Keys",
179179
"applications": "Applications",
180+
"content": "Content",
180181
"third_party_account": {
181182
"manage": "Third-party",
182183
"title": "Third-party Account Management",
@@ -278,7 +279,9 @@
278279
"theme_setting": "Appearance",
279280
"theme_light": "Light",
280281
"theme_dark": "Dark",
281-
"theme_system": "System"
282+
"theme_system": "System",
283+
"auto_tag_setting": "AI-Powered Tag Extraction",
284+
"auto_tag_description": "Automatically extract and generate tags from content using AI"
282285
},
283286
"unauth_page": {
284287
"title": "Access Denied",

src/i18n/locales/zh.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
"namespace": "空间设置",
178178
"api_key": "API 密钥",
179179
"applications": "应用管理",
180+
"content": "内容",
180181
"third_party_account": {
181182
"manage": "三方账号管理",
182183
"title": "第三方账号管理",
@@ -278,7 +279,9 @@
278279
"theme_setting": "外观",
279280
"theme_light": "浅色",
280281
"theme_dark": "深色",
281-
"theme_system": "系统"
282+
"theme_system": "系统",
283+
"auto_tag_setting": "AI 智能标签提取",
284+
"auto_tag_description": "使用 AI 自动从内容中提取和生成标签"
282285
},
283286
"unauth_page": {
284287
"title": "访问被拒绝",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Tags } from 'lucide-react';
2+
import { useEffect, useState } from 'react';
3+
import { useTranslation } from 'react-i18next';
4+
5+
import { Switch } from '@/components/ui/switch';
6+
import { http } from '@/lib/request';
7+
8+
export default function AutoTag() {
9+
const { t } = useTranslation();
10+
const [isEnabled, setIsEnabled] = useState(true);
11+
const [loading, setLoading] = useState(true);
12+
13+
useEffect(() => {
14+
const loadPreference = async () => {
15+
try {
16+
const response = await http.get(
17+
'/user/option/enable_ai_tag_extraction'
18+
);
19+
if (response.value !== undefined) {
20+
setIsEnabled(response.value === 'true');
21+
}
22+
} catch {
23+
// If option doesn't exist, default is enabled
24+
setIsEnabled(true);
25+
} finally {
26+
setLoading(false);
27+
}
28+
};
29+
loadPreference().then();
30+
}, []);
31+
32+
const handleToggle = async (checked: boolean) => {
33+
setIsEnabled(checked);
34+
try {
35+
await http.post('/user/option', {
36+
name: 'enable_ai_tag_extraction',
37+
value: checked ? 'true' : 'false',
38+
});
39+
} catch {
40+
setIsEnabled(!checked);
41+
}
42+
};
43+
44+
return (
45+
<div className="flex items-center justify-between">
46+
<div className="flex flex-col gap-1">
47+
<div className="flex items-center gap-2">
48+
<Tags className="size-4" />
49+
<span>{t('manage.auto_tag_setting')}</span>
50+
</div>
51+
<span className="text-xs text-muted-foreground ml-6">
52+
{t('manage.auto_tag_description')}
53+
</span>
54+
</div>
55+
<Switch
56+
checked={isEnabled}
57+
onCheckedChange={handleToggle}
58+
disabled={loading}
59+
/>
60+
</div>
61+
);
62+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import AutoTag from './auto-tag';
2+
3+
export default function Content() {
4+
return (
5+
<div className="flex flex-col gap-4">
6+
<AutoTag />
7+
</div>
8+
);
9+
}

src/page/sidebar/switcher/swtting-wrapper.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SidebarNav } from '@/page/user/form/sidebar';
88

99
import { ApplicationsForm } from './applications';
1010
import CommonForm from './basic';
11+
import Content from './content';
1112
import { APIKeyForm } from './form/api-key';
1213
import ProfileForm from './form/profile';
1314
import SettingForm from './form/setting';
@@ -71,6 +72,11 @@ export default function SettingWrapper({
7172
value: 'basic',
7273
children: <CommonForm />,
7374
},
75+
{
76+
label: t('setting.content'),
77+
value: 'content',
78+
children: <Content />,
79+
},
7480
{
7581
label: t('setting.third_party_account.manage'),
7682
value: 'third-party',

0 commit comments

Comments
 (0)