refactor(ocr-settings): simplify ocr settings by removing unused tab logic

Since only image OCR is currently supported, remove the tab component and related unused code while keeping the core functionality
This commit is contained in:
icarus 2025-10-19 22:36:40 +08:00
parent d35d7029f7
commit d366ec5932

View File

@ -1,62 +1,60 @@
import { PictureOutlined } from '@ant-design/icons'
import { cn, Tabs, TabsContent, TabsList, TabsTrigger } from '@cherrystudio/ui'
import { ErrorBoundary } from '@renderer/components/ErrorBoundary'
import { useTheme } from '@renderer/context/ThemeProvider'
import { useOcrProviders } from '@renderer/hooks/useOcrProvider'
import type { FC, ReactNode } from 'react'
import { useCallback, useMemo, useState } from 'react'
import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import * as z from 'zod'
import { SettingDivider, SettingGroup, SettingTitle } from '..'
import OcrImageSettings from './OcrImageSettings'
import OcrProviderSettings from './OcrProviderSettings'
const TabSchema = z.enum(['image'])
type Tab = z.infer<typeof TabSchema>
const isValidTab = (value: string): value is Tab => TabSchema.safeParse(value).success
type TabItem = {
name: string
value: Tab
icon: ReactNode
content: ReactNode
}
// const TabSchema = z.enum(['image'])
// type Tab = z.infer<typeof TabSchema>
// const isValidTab = (value: string): value is Tab => TabSchema.safeParse(value).success
// type TabItem = {
// name: string
// value: Tab
// icon: ReactNode
// content: ReactNode
// }
const OcrSettings: FC = () => {
const { t } = useTranslation()
const { theme: themeMode } = useTheme()
const { imageProvider } = useOcrProviders()
const [activeTab, setActiveTab] = useState<Tab>('image')
const provider = useMemo(() => {
switch (activeTab) {
case 'image':
return imageProvider
}
}, [imageProvider, activeTab])
const { imageProvider: provider } = useOcrProviders()
// const [activeTab, setActiveTab] = useState<Tab>('image')
// const provider = useMemo(() => {
// switch (activeTab) {
// case 'image':
// return imageProvider
// default:
// return undefined
// }
// }, [imageProvider, activeTab])
const tabs = [
{
name: t('settings.tool.ocr.image.title'),
value: 'image',
icon: <PictureOutlined />,
content: <OcrImageSettings />
}
] satisfies TabItem[]
// const tabs = [
// {
// name: t('settings.tool.ocr.image.title'),
// value: 'image',
// icon: <PictureOutlined />,
// content: <OcrImageSettings />
// }
// ] satisfies TabItem[]
const handleTabChange = useCallback((value: string) => {
if (isValidTab(value)) {
setActiveTab(value)
} else {
window.toast.error('Unexpected behavior: Not a valid tab.')
}
}, [])
// const handleTabChange = useCallback((value: string) => {
// if (isValidTab(value)) {
// setActiveTab(value)
// } else {
// window.toast.error('Unexpected behavior: Not a valid tab.')
// }
// }, [])
return (
<ErrorBoundary>
<SettingGroup theme={themeMode}>
<SettingTitle>{t('settings.tool.ocr.title')}</SettingTitle>
<SettingDivider />
<Tabs value={activeTab} onValueChange={handleTabChange}>
{/* <Tabs value={activeTab} onValueChange={handleTabChange}>
<TabsList>
{tabs.map((tab) => {
return (
@ -76,7 +74,11 @@ const OcrSettings: FC = () => {
</TabsContent>
)
})}
</Tabs>
</Tabs> */}
{/* Since only image is supported for now, we just don't use tabs component,
but keep code of tabs. */}
<OcrImageSettings />
</SettingGroup>
<ErrorBoundary>