mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-04 03:40:33 +08:00
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:
parent
d35d7029f7
commit
d366ec5932
@ -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 { ErrorBoundary } from '@renderer/components/ErrorBoundary'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
import { useOcrProviders } from '@renderer/hooks/useOcrProvider'
|
import { useOcrProviders } from '@renderer/hooks/useOcrProvider'
|
||||||
import type { FC, ReactNode } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useCallback, useMemo, useState } from 'react'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import * as z from 'zod'
|
|
||||||
|
|
||||||
import { SettingDivider, SettingGroup, SettingTitle } from '..'
|
import { SettingDivider, SettingGroup, SettingTitle } from '..'
|
||||||
import OcrImageSettings from './OcrImageSettings'
|
import OcrImageSettings from './OcrImageSettings'
|
||||||
import OcrProviderSettings from './OcrProviderSettings'
|
import OcrProviderSettings from './OcrProviderSettings'
|
||||||
|
|
||||||
const TabSchema = z.enum(['image'])
|
// const TabSchema = z.enum(['image'])
|
||||||
type Tab = z.infer<typeof TabSchema>
|
// type Tab = z.infer<typeof TabSchema>
|
||||||
const isValidTab = (value: string): value is Tab => TabSchema.safeParse(value).success
|
// const isValidTab = (value: string): value is Tab => TabSchema.safeParse(value).success
|
||||||
type TabItem = {
|
// type TabItem = {
|
||||||
name: string
|
// name: string
|
||||||
value: Tab
|
// value: Tab
|
||||||
icon: ReactNode
|
// icon: ReactNode
|
||||||
content: ReactNode
|
// content: ReactNode
|
||||||
}
|
// }
|
||||||
|
|
||||||
const OcrSettings: FC = () => {
|
const OcrSettings: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { theme: themeMode } = useTheme()
|
const { theme: themeMode } = useTheme()
|
||||||
const { imageProvider } = useOcrProviders()
|
const { imageProvider: provider } = useOcrProviders()
|
||||||
const [activeTab, setActiveTab] = useState<Tab>('image')
|
// const [activeTab, setActiveTab] = useState<Tab>('image')
|
||||||
const provider = useMemo(() => {
|
// const provider = useMemo(() => {
|
||||||
switch (activeTab) {
|
// switch (activeTab) {
|
||||||
case 'image':
|
// case 'image':
|
||||||
return imageProvider
|
// return imageProvider
|
||||||
}
|
// default:
|
||||||
}, [imageProvider, activeTab])
|
// return undefined
|
||||||
|
// }
|
||||||
|
// }, [imageProvider, activeTab])
|
||||||
|
|
||||||
const tabs = [
|
// const tabs = [
|
||||||
{
|
// {
|
||||||
name: t('settings.tool.ocr.image.title'),
|
// name: t('settings.tool.ocr.image.title'),
|
||||||
value: 'image',
|
// value: 'image',
|
||||||
icon: <PictureOutlined />,
|
// icon: <PictureOutlined />,
|
||||||
content: <OcrImageSettings />
|
// content: <OcrImageSettings />
|
||||||
}
|
// }
|
||||||
] satisfies TabItem[]
|
// ] satisfies TabItem[]
|
||||||
|
|
||||||
const handleTabChange = useCallback((value: string) => {
|
// const handleTabChange = useCallback((value: string) => {
|
||||||
if (isValidTab(value)) {
|
// if (isValidTab(value)) {
|
||||||
setActiveTab(value)
|
// setActiveTab(value)
|
||||||
} else {
|
// } else {
|
||||||
window.toast.error('Unexpected behavior: Not a valid tab.')
|
// window.toast.error('Unexpected behavior: Not a valid tab.')
|
||||||
}
|
// }
|
||||||
}, [])
|
// }, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<SettingGroup theme={themeMode}>
|
<SettingGroup theme={themeMode}>
|
||||||
<SettingTitle>{t('settings.tool.ocr.title')}</SettingTitle>
|
<SettingTitle>{t('settings.tool.ocr.title')}</SettingTitle>
|
||||||
<SettingDivider />
|
<SettingDivider />
|
||||||
<Tabs value={activeTab} onValueChange={handleTabChange}>
|
{/* <Tabs value={activeTab} onValueChange={handleTabChange}>
|
||||||
<TabsList>
|
<TabsList>
|
||||||
{tabs.map((tab) => {
|
{tabs.map((tab) => {
|
||||||
return (
|
return (
|
||||||
@ -76,7 +74,11 @@ const OcrSettings: FC = () => {
|
|||||||
</TabsContent>
|
</TabsContent>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</Tabs>
|
</Tabs> */}
|
||||||
|
|
||||||
|
{/* Since only image is supported for now, we just don't use tabs component,
|
||||||
|
but keep code of tabs. */}
|
||||||
|
<OcrImageSettings />
|
||||||
</SettingGroup>
|
</SettingGroup>
|
||||||
|
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user