Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
import { createFileRoute } from '@tanstack/react-router'
import { route } from '@/constants/routes'
import SettingsMenu from '@/containers/SettingsMenu'
import HeaderPage from '@/containers/HeaderPage'
import { Card, CardItem } from '@/containers/Card'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { ThemeSwitcher } from '@/containers/ThemeSwitcher'
import { FontSizeSwitcher } from '@/containers/FontSizeSwitcher'
import { AccentColorPicker } from '@/containers/AccentColorPicker'
import { NotificationPositionSwitcher } from '@/containers/NotificationPositionSwitcher'
import { useInterfaceSettings } from '@/hooks/useInterfaceSettings'
import { useTheme } from '@/hooks/useTheme'
import { Button } from '@/components/ui/button'
import { Switch } from '@/components/ui/switch'
import { toast } from 'sonner'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const Route = createFileRoute(route.settings.interface as any)({
component: InterfaceSettings,
})
function InterfaceSettings() {
const { t } = useTranslation()
const {
resetInterface,
showTokenSpeed,
setShowTokenSpeed,
coloredUserBubble,
setColoredUserBubble,
renderHtmlArtifacts,
setRenderHtmlArtifacts,
autoGenerateTitle,
setAutoGenerateTitle,
runNotifications,
setRunNotifications,
} = useInterfaceSettings()
const { activeTheme } = useTheme()
return (
<div className="flex flex-col h-svh w-full">
<HeaderPage>
<div className="flex items-center gap-2 w-full">
<span className='font-medium text-base font-studio'>{t('common:settings')}</span>
</div>
</HeaderPage>
<div className="flex h-[calc(100%-60px)]">
<SettingsMenu />
<div className="p-4 pt-0 w-full overflow-y-auto">
<div className="flex flex-col justify-between gap-4 gap-y-3 w-full">
{/* Interface */}
<Card title={t('settings:interface.title')}>
<CardItem
title={t('settings:interface.theme')}
description={
// "Match the OS theme" only describes System; a fixed Light or
// Dark choice must not claim to follow the OS.
activeTheme === 'auto'
? t('settings:interface.themeDesc')
: t('settings:interface.themeDescFixed')
}
actions={<ThemeSwitcher />}
/>
<CardItem
title={t('settings:interface.fontSize')}
description={t('settings:interface.fontSizeDesc')}
actions={<FontSizeSwitcher />}
/>
<CardItem
title="Accent color"
description="Customize the accent color of the application."
className="flex-col sm:flex-row items-start sm:items-center sm:justify-between gap-y-2"
actions={<AccentColorPicker />}
/>
<CardItem
title={t('settings:interface.notificationPosition')}
description={t('settings:interface.notificationPositionDesc')}
actions={<NotificationPositionSwitcher />}
/>
<CardItem
title={t('settings:interface.showTokenSpeed')}
description={t('settings:interface.showTokenSpeedDesc')}
actions={
<Switch
checked={showTokenSpeed}
onCheckedChange={setShowTokenSpeed}
/>
}
/>
<CardItem
title={t('settings:interface.coloredUserBubble')}
description={t('settings:interface.coloredUserBubbleDesc')}
actions={
<Switch
checked={coloredUserBubble}
onCheckedChange={setColoredUserBubble}
/>
}
/>
<CardItem
title={
<span className="inline-flex items-center gap-2">
<span>{t('settings:interface.renderHtmlArtifacts')}</span>
<span className="text-xs bg-secondary border text-muted-foreground rounded-full py-0.5 px-2">
{t('common:experimental')}
</span>
</span>
}
description={t('settings:interface.renderHtmlArtifactsDesc')}
actions={
<Switch
checked={renderHtmlArtifacts}
onCheckedChange={setRenderHtmlArtifacts}
/>
}
/>
<CardItem
title={t('settings:interface.autoGenerateTitle')}
description={t('settings:interface.autoGenerateTitleDesc')}
actions={
<Switch
checked={autoGenerateTitle}
onCheckedChange={setAutoGenerateTitle}
/>
}
/>
<CardItem
title={t('settings:interface.runNotifications')}
description={t('settings:interface.runNotificationsDesc')}
actions={
<Switch
checked={runNotifications.enabled}
onCheckedChange={(enabled) =>
setRunNotifications({ enabled })
}
/>
}
/>
{runNotifications.enabled && (
<CardItem
title={t('settings:interface.runNotificationsFinish')}
actions={
<Switch
checked={runNotifications.onFinish}
onCheckedChange={(onFinish) =>
setRunNotifications({ onFinish })
}
/>
}
/>
)}
{runNotifications.enabled && (
<CardItem
title={t('settings:interface.runNotificationsError')}
actions={
<Switch
checked={runNotifications.onError}
onCheckedChange={(onError) =>
setRunNotifications({ onError })
}
/>
}
/>
)}
{runNotifications.enabled && (
<CardItem
title={t('settings:interface.runNotificationsApproval')}
actions={
<Switch
checked={runNotifications.onApproval}
onCheckedChange={(onApproval) =>
setRunNotifications({ onApproval })
}
/>
}
/>
)}
{runNotifications.enabled && (
<CardItem
title={t('settings:interface.runNotificationsCancel')}
actions={
<Switch
checked={runNotifications.onCancel}
onCheckedChange={(onCancel) =>
setRunNotifications({ onCancel })
}
/>
}
/>
)}
<CardItem
title={t('settings:interface.resetToDefault')}
description={t('settings:interface.resetToDefaultDesc')}
actions={
<Button
variant="destructive"
size="sm"
onClick={() => {
resetInterface()
toast.success(
t('settings:interface.resetInterfaceSuccess'),
{
id: 'reset-interface',
description: t(
'settings:interface.resetInterfaceSuccessDesc'
),
}
)
}}
>
{t('common:reset')}
</Button>
}
/>
</Card>
</div>
</div>
</div>
</div>
)
}