Skip to content

Commit f01d4d5

Browse files
committed
Extract settings components
1 parent 85b75dc commit f01d4d5

3 files changed

Lines changed: 66 additions & 54 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useTranslation } from 'react-i18next'
2+
import { BiExport, BiImport } from 'react-icons/bi'
3+
import { exportData, importData } from '~app/utils/export'
4+
import Button from '../Button'
5+
6+
function ExportDataPanel() {
7+
const { t } = useTranslation()
8+
return (
9+
<div>
10+
<p className="font-bold mb-1 text-lg">{t('Export/Import All Data')}</p>
11+
<p className="mb-3 opacity-80">{t('Data includes all your settings, chat histories, and local prompts')}</p>
12+
<div className="flex flex-row gap-3">
13+
<Button size="small" text={t('Export')} icon={<BiExport />} onClick={exportData} />
14+
<Button size="small" text={t('Import')} icon={<BiImport />} onClick={importData} />
15+
</div>
16+
</div>
17+
)
18+
}
19+
20+
export default ExportDataPanel
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useEffect, useState } from 'react'
2+
import { useTranslation } from 'react-i18next'
3+
import Browser from 'webextension-polyfill'
4+
import Button from '~app/components/Button'
5+
import KDB from '~app/components/Settings/KDB'
6+
7+
function ShortcutPanel() {
8+
const [shortcuts, setShortcuts] = useState<string[]>([])
9+
const { t } = useTranslation()
10+
11+
useEffect(() => {
12+
Browser.commands.getAll().then((commands) => {
13+
for (const c of commands) {
14+
if (c.name === 'open-app' && c.shortcut) {
15+
console.debug(c.shortcut)
16+
setShortcuts(c.shortcut ? [c.shortcut] : [])
17+
}
18+
}
19+
})
20+
}, [])
21+
22+
return (
23+
<div className="flex flex-col gap-2">
24+
<p className="font-bold text-lg">{t('Shortcut to open this app')}</p>
25+
<div className="flex flex-row gap-2 items-center">
26+
{shortcuts.length > 0 && (
27+
<div className="flex flex-row gap-1">
28+
{shortcuts.map((s) => (
29+
<KDB key={s} text={s} />
30+
))}
31+
</div>
32+
)}
33+
<Button
34+
text={t('Change shortcut')}
35+
size="small"
36+
onClick={() => Browser.tabs.create({ url: 'chrome://extensions/shortcuts' })}
37+
/>
38+
</div>
39+
</div>
40+
)
41+
}
42+
43+
export default ShortcutPanel

src/app/pages/SettingPage.tsx

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { FC, PropsWithChildren, useCallback, useEffect, useState } from 'react'
22
import toast, { Toaster } from 'react-hot-toast'
33
import { useTranslation } from 'react-i18next'
4-
import { BiExport, BiImport } from 'react-icons/bi'
54
import Browser from 'webextension-polyfill'
6-
import Button, { MotionButton } from '~app/components/Button'
5+
import { MotionButton } from '~app/components/Button'
76
import { Input } from '~app/components/Input'
87
import RadioGroup from '~app/components/RadioGroup'
98
import Select from '~app/components/Select'
@@ -18,10 +17,10 @@ import ClaudeOpenRouterSettings from '~app/components/Settings/ClaudeOpenRouterS
1817
import ClaudePoeSettings from '~app/components/Settings/ClaudePoeSettings'
1918
import ClaudeWebappSettings from '~app/components/Settings/ClaudeWebappSettings'
2019
import EnabledBotsSettings from '~app/components/Settings/EnabledBotsSettings'
21-
import KDB from '~app/components/Settings/KDB'
20+
import ExportDataPanel from '~app/components/Settings/ExportDataPanel'
2221
import PerplexityAPISettings from '~app/components/Settings/PerplexityAPISettings'
22+
import ShortcutPanel from '~app/components/Settings/ShortcutPanel'
2323
import { ALL_IN_ONE_PAGE_ID, CHATBOTS } from '~app/consts'
24-
import { exportData, importData } from '~app/utils/export'
2524
import {
2625
BingConversationStyle,
2726
ChatGPTMode,
@@ -49,56 +48,6 @@ const ChatBotSettingPanel: FC<PropsWithChildren<{ title: string }>> = (props) =>
4948
)
5049
}
5150

52-
function ExportDataPanel() {
53-
const { t } = useTranslation()
54-
return (
55-
<div>
56-
<p className="font-bold mb-1 text-lg">{t('Export/Import All Data')}</p>
57-
<p className="mb-3 opacity-80">{t('Data includes all your settings, chat histories, and local prompts')}</p>
58-
<div className="flex flex-row gap-3">
59-
<Button size="small" text={t('Export')} icon={<BiExport />} onClick={exportData} />
60-
<Button size="small" text={t('Import')} icon={<BiImport />} onClick={importData} />
61-
</div>
62-
</div>
63-
)
64-
}
65-
66-
function ShortcutPanel() {
67-
const [shortcuts, setShortcuts] = useState<string[]>([])
68-
const { t } = useTranslation()
69-
70-
useEffect(() => {
71-
Browser.commands.getAll().then((commands) => {
72-
for (const c of commands) {
73-
if (c.name === 'open-app' && c.shortcut) {
74-
console.debug(c.shortcut)
75-
setShortcuts(c.shortcut ? [c.shortcut] : [])
76-
}
77-
}
78-
})
79-
}, [])
80-
81-
return (
82-
<div className="flex flex-col gap-2">
83-
<p className="font-bold text-lg">{t('Shortcut to open this app')}</p>
84-
<div className="flex flex-row gap-2 items-center">
85-
{shortcuts.length > 0 && (
86-
<div className="flex flex-row gap-1">
87-
{shortcuts.map((s) => (
88-
<KDB key={s} text={s} />
89-
))}
90-
</div>
91-
)}
92-
<Button
93-
text={t('Change shortcut')}
94-
size="small"
95-
onClick={() => Browser.tabs.create({ url: 'chrome://extensions/shortcuts' })}
96-
/>
97-
</div>
98-
</div>
99-
)
100-
}
101-
10251
function SettingPage() {
10352
const { t } = useTranslation()
10453
const [userConfig, setUserConfig] = useState<UserConfig | undefined>(undefined)

0 commit comments

Comments
 (0)