Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix/remove-setting-codeblock
Faisal Amirab8c231ff728
diff --git a/web-app/src/containers/CodeBlockExample.tsx b/web-app/src/containers/CodeBlockExample.tsxdeleted file mode 100644index 47934dd44..000000000--- a/web-app/src/containers/CodeBlockExample.tsx+++ /dev/null@@ -1,27 +0,0 @@-import { RenderMarkdown } from './RenderMarkdown'-import { useTranslation } from '@/i18n/react-i18next-compat'--const EXAMPLE_CODE = `\`\`\`typescript-// Example code for preview-function greeting(name: string) {- return \`Hello, \${name}!\`;-}--// Call the function-const message = greeting('Jan');-console.log(message); // Outputs: Hello, Jan!-\`\`\``--export function CodeBlockExample() {- const { t } = useTranslation()- return (- <div className="w-full overflow-hidden border border-main-view-fg/10 rounded-md my-2">- <div className="flex items-center justify-between px-4 py-2 bg-main-view-fg/10">- <span className="font-medium text-xs font-sans">{t('preview')}</span>- </div>- <div className="overflow-auto p-2">- <RenderMarkdown content={EXAMPLE_CODE} />- </div>- </div>- )-}diff --git a/web-app/src/containers/CodeBlockStyleSwitcher.tsx b/web-app/src/containers/CodeBlockStyleSwitcher.tsxdeleted file mode 100644index d1299949b..000000000--- a/web-app/src/containers/CodeBlockStyleSwitcher.tsx+++ /dev/null@@ -1,272 +0,0 @@-// Available Shiki themes-// https://shiki.style/themes--const CODE_BLOCK_STYLES = [- // Dark themes- 'andromeeda',- 'aurora-x',- 'ayu-dark',- 'catppuccin-frappe',- 'catppuccin-macchiato',- 'catppuccin-mocha',- 'dark-plus',- 'dracula',- 'dracula-soft',- 'everforest-dark',- 'github-dark',- 'github-dark-default',- 'github-dark-dimmed',- 'github-dark-high-contrast',- 'gruvbox-dark-hard',- 'gruvbox-dark-medium',- 'gruvbox-dark-soft',- 'houston',- 'kanagawa-dragon',- 'kanagawa-wave',- 'laserwave',- 'material-theme',- 'material-theme-darker',- 'material-theme-ocean',- 'material-theme-palenight',- 'min-dark',- 'monokai',- 'night-owl',- 'nord',- 'one-dark-pro',- 'plastic',- 'poimandres',- 'red',- 'rose-pine',- 'rose-pine-moon',- 'slack-dark',- 'slack-ochin',- 'solarized-dark',- 'synthwave-84',- 'tokyo-night',- 'vesper',- 'vitesse-black',- 'vitesse-dark',-- // Light themes- 'catppuccin-latte',- 'everforest-light',- 'github-light',- 'github-light-default',- 'github-light-high-contrast',- 'gruvbox-light-hard',- 'gruvbox-light-medium',- 'gruvbox-light-soft',- 'kanagawa-lotus',- 'light-plus',- 'material-theme-lighter',- 'min-light',- 'one-light',- 'rose-pine-dawn',- 'snazzy-light',- 'solarized-light',- 'vitesse-light',-]--import { useCodeblock } from '@/hooks/useCodeblock'-import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,- DropdownMenuLabel,-} from '@/components/ui/dropdown-menu'-import { cn } from '@/lib/utils'-import { useState } from 'react'-import { IconSearch } from '@tabler/icons-react'-import { Input } from '@/components/ui/input'--// Function to format style names to be more readable-function formatStyleName(style: string): string {- // Direct mappings for Shiki theme names- const directMappings: Record<string, string> = {- 'andromeeda': 'Andromeeda',- 'aurora-x': 'Aurora X',- 'ayu-dark': 'Ayu Dark',- 'catppuccin-frappe': 'Catppuccin Frappé',- 'catppuccin-latte': 'Catppuccin Latte',- 'catppuccin-macchiato': 'Catppuccin Macchiato',- 'catppuccin-mocha': 'Catppuccin Mocha',- 'dark-plus': 'Dark Plus',- 'dracula': 'Dracula',- 'dracula-soft': 'Dracula Soft',- 'everforest-dark': 'Everforest Dark',- 'everforest-light': 'Everforest Light',- 'github-dark': 'GitHub Dark',- 'github-dark-default': 'GitHub Dark Default',- 'github-dark-dimmed': 'GitHub Dark Dimmed',- 'github-dark-high-contrast': 'GitHub Dark High Contrast',- 'github-light': 'GitHub Light',- 'github-light-default': 'GitHub Light Default',- 'github-light-high-contrast': 'GitHub Light High Contrast',- 'gruvbox-dark-hard': 'Gruvbox Dark Hard',- 'gruvbox-dark-medium': 'Gruvbox Dark Medium',- 'gruvbox-dark-soft': 'Gruvbox Dark Soft',- 'gruvbox-light-hard': 'Gruvbox Light Hard',- 'gruvbox-light-medium': 'Gruvbox Light Medium',- 'gruvbox-light-soft': 'Gruvbox Light Soft',- 'houston': 'Houston',- 'kanagawa-dragon': 'Kanagawa Dragon',- 'kanagawa-lotus': 'Kanagawa Lotus',- 'kanagawa-wave': 'Kanagawa Wave',- 'laserwave': 'LaserWave',- 'light-plus': 'Light Plus',- 'material-theme': 'Material Theme',- 'material-theme-darker': 'Material Theme Darker',- 'material-theme-lighter': 'Material Theme Lighter',- 'material-theme-ocean': 'Material Theme Ocean',- 'material-theme-palenight': 'Material Theme Palenight',- 'min-dark': 'Min Dark',- 'min-light': 'Min Light',- 'monokai': 'Monokai',- 'night-owl': 'Night Owl',- 'nord': 'Nord',- 'one-dark-pro': 'One Dark Pro',- 'one-light': 'One Light',- 'plastic': 'Plastic',- 'poimandres': 'Poimandres',- 'red': 'Red',- 'rose-pine': 'Rosé Pine',- 'rose-pine-dawn': 'Rosé Pine Dawn',- 'rose-pine-moon': 'Rosé Pine Moon',- 'slack-dark': 'Slack Dark',- 'slack-ochin': 'Slack Ochin',- 'snazzy-light': 'Snazzy Light',- 'solarized-dark': 'Solarized Dark',- 'solarized-light': 'Solarized Light',- 'synthwave-84': "Synthwave '84",- 'tokyo-night': 'Tokyo Night',- 'vesper': 'Vesper',- 'vitesse-black': 'Vitesse Black',- 'vitesse-dark': 'Vitesse Dark',- 'vitesse-light': 'Vitesse Light',- }-- // Check for direct mappings first- if (directMappings[style]) {- return directMappings[style]- }-- // Fallback: capitalize each word- return style- .split('-')- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))- .join(' ')-}--export default function CodeBlockStyleSwitcher() {- const { codeBlockStyle, setCodeBlockStyle } = useCodeblock()- const [searchQuery, setSearchQuery] = useState('')-- const changeCodeBlockStyle = (style: string) => {- setCodeBlockStyle(style)- }-- // Extract styles by category (44 dark themes, 17 light themes)- const darkThemes = CODE_BLOCK_STYLES.slice(0, 44)- const lightThemes = CODE_BLOCK_STYLES.slice(44)-- // Filter styles based on search query- const filteredDarkThemes = darkThemes.filter((style) =>- formatStyleName(style).toLowerCase().includes(searchQuery.toLowerCase())- )-- const filteredLightThemes = lightThemes.filter((style) =>- formatStyleName(style).toLowerCase().includes(searchQuery.toLowerCase())- )-- return (- <DropdownMenu>- <DropdownMenuTrigger asChild>- <span- title="Edit Code Block Style"- className="flex cursor-pointer items-center gap-1 px-2 py-1 rounded-sm bg-main-view-fg/15 text-sm outline-none text-main-view-fg font-medium"- >- {formatStyleName(codeBlockStyle || 'github-light')}- </span>- </DropdownMenuTrigger>- <DropdownMenuContent- align="end"- className="w-64 max-h-80 overflow-y-auto"- >- {/* Search input */}- <div className="px-2 py-2 sticky -top-1 bg-main-view z-10">- <div className="relative">- <IconSearch className="absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4" />- <Input- type="text"- placeholder="Search styles..."- value={searchQuery}- onClick={(e) => {- e.stopPropagation()- }}- onKeyDown={(e) => {- e.stopPropagation()- }}- onChange={(e) => {- e.preventDefault()- e.stopPropagation()- setSearchQuery(e.target.value)- }}- className="w-full pl-8 pr-2"- autoFocus- />- </div>- </div>-- {/* Dark themes */}- {filteredDarkThemes.length > 0 && (- <>- <DropdownMenuLabel className="font-medium text-xs px-2 pt-2 text-main-view-fg/60">- Dark Themes- </DropdownMenuLabel>- {filteredDarkThemes.map((style) => (- <DropdownMenuItem- key={style}- className={cn(- 'cursor-pointer my-0.5',- codeBlockStyle === style && 'bg-main-view-fg/5'- )}- onClick={() => changeCodeBlockStyle(style)}- >- {formatStyleName(style)}- </DropdownMenuItem>- ))}- </>- )}-- {/* Light themes */}- {filteredLightThemes.length > 0 && (- <>- <DropdownMenuLabel className="font-medium text-xs px-2 pt-2 text-main-view-fg/60">- Light Themes- </DropdownMenuLabel>- {filteredLightThemes.map((style) => (- <DropdownMenuItem- key={style}- className={cn(- 'cursor-pointer my-0.5',- codeBlockStyle === style && 'bg-main-view-fg/5'- )}- onClick={() => changeCodeBlockStyle(style)}- >- {formatStyleName(style)}- </DropdownMenuItem>- ))}- </>- )}-- {/* No results message */}- {filteredDarkThemes.length === 0 && filteredLightThemes.length === 0 && (- <div className="px-2 py-4 text-center text-sm text-muted-foreground">- No styles found- </div>- )}- </DropdownMenuContent>- </DropdownMenu>- )-}diff --git a/web-app/src/containers/LineNumbersSwitcher.tsx b/web-app/src/containers/LineNumbersSwitcher.tsxdeleted file mode 100644index c01380a8a..000000000--- a/web-app/src/containers/LineNumbersSwitcher.tsx+++ /dev/null@@ -1,14 +0,0 @@-import { useCodeblock } from '@/hooks/useCodeblock'-import { Switch } from '@/components/ui/switch'--export function LineNumbersSwitcher() {- const { showLineNumbers, setShowLineNumbers } = useCodeblock()-- const toggleLineNumbers = () => {- setShowLineNumbers(!showLineNumbers)- }-- return (- <Switch checked={showLineNumbers} onCheckedChange={toggleLineNumbers} />- )-}diff --git a/web-app/src/containers/RenderMarkdown.tsx b/web-app/src/containers/RenderMarkdown.tsxindex 62cc1cd80..74786d15c 100644--- a/web-app/src/containers/RenderMarkdown.tsx+++ b/web-app/src/containers/RenderMarkdown.tsx@@ -7,7 +7,6 @@ import { defaultRehypePlugins, Streamdown } from 'streamdown'import remarkGfm from 'remark-gfm'import remarkMath from 'remark-math'import { MermaidError } from '@/components/MermaidError'-import { useCodeblock } from '@/hooks/useCodeblock'interface MarkdownProps {content: string@@ -81,7 +80,6 @@ function RenderMarkdownComponent({components,messageId,}: MarkdownProps) {- const { codeBlockStyle } = useCodeblock()// Memoize the normalized content to avoid reprocessing on every renderconst normalizedContent = useMemo(() => normalizeLatex(content), [content])@@ -107,7 +105,6 @@ function RenderMarkdownComponent({defaultRehypePlugins.katex,defaultRehypePlugins.harden,]}- shikiTheme={[codeBlockStyle, codeBlockStyle] as any}components={components}mermaid={messageIddiff --git a/web-app/src/hooks/useCodeblock.ts b/web-app/src/hooks/useCodeblock.tsdeleted file mode 100644index a74741014..000000000--- a/web-app/src/hooks/useCodeblock.ts+++ /dev/null@@ -1,46 +0,0 @@-import { create } from 'zustand'-import { persist, createJSONStorage } from 'zustand/middleware'-import { localStorageKey } from '@/constants/localStorage'--export type CodeBlockStyle = string--interface CodeBlockState {- codeBlockStyle: CodeBlockStyle- showLineNumbers: boolean- setCodeBlockStyle: (style: CodeBlockStyle) => void- setShowLineNumbers: (show: boolean) => void- resetCodeBlockStyle: () => void-}--const defaultCodeBlockStyle: CodeBlockStyle = 'github-light'-const defaultShowLineNumbers: boolean = true--export const useCodeblock = create<CodeBlockState>()(- persist(- (set) => {- return {- codeBlockStyle: defaultCodeBlockStyle,- showLineNumbers: defaultShowLineNumbers,-- setCodeBlockStyle: (style: CodeBlockStyle) => {- set({ codeBlockStyle: style })- },-- setShowLineNumbers: (show: boolean) => {- set({ showLineNumbers: show })- },-- resetCodeBlockStyle: () => {- set({- codeBlockStyle: defaultCodeBlockStyle,- showLineNumbers: defaultShowLineNumbers,- })- },- }- },- {- name: localStorageKey.settingCodeBlock,- storage: createJSONStorage(() => localStorage),- }- )-)diff --git a/web-app/src/routes/settings/__tests__/interface.test.tsx b/web-app/src/routes/settings/__tests__/interface.test.tsxindex aff7fa714..17a5b771b 100644--- a/web-app/src/routes/settings/__tests__/interface.test.tsx+++ b/web-app/src/routes/settings/__tests__/interface.test.tsx@@ -61,17 +61,6 @@ vi.mock('@/containers/ChatWidthSwitcher', () => ({ChatWidthSwitcher: () => <div data-testid="chat-width-switcher">Chat Width Switcher</div>,}))-vi.mock('@/containers/CodeBlockStyleSwitcher', () => ({- default: () => <div data-testid="code-block-style-switcher">Code Block Style Switcher</div>,-}))--vi.mock('@/containers/LineNumbersSwitcher', () => ({- LineNumbersSwitcher: () => <div data-testid="line-numbers-switcher">Line Numbers Switcher</div>,-}))--vi.mock('@/containers/CodeBlockExample', () => ({- CodeBlockExample: () => <div data-testid="code-block-example">Code Block Example</div>,-}))vi.mock('@/hooks/useInterfaceSettings', () => ({useInterfaceSettings: () => ({@@ -79,12 +68,6 @@ vi.mock('@/hooks/useInterfaceSettings', () => ({}),}))-vi.mock('@/hooks/useCodeblock', () => ({- useCodeblock: () => ({- resetCodeBlockStyle: vi.fn(),- }),-}))-vi.mock('@/i18n/react-i18next-compat', () => ({useTranslation: () => ({t: (key: string) => key,@@ -154,15 +137,6 @@ describe('Interface Settings Route', () => {expect(screen.getByTestId('chat-width-switcher')).toBeInTheDocument()})- it('should render code block controls', () => {- const Component = InterfaceRoute.component as React.ComponentType- render(<Component />)-- expect(screen.getByTestId('code-block-style-switcher')).toBeInTheDocument()- expect(screen.getByTestId('code-block-example')).toBeInTheDocument()- expect(screen.getByTestId('line-numbers-switcher')).toBeInTheDocument()- })-it('should render reset interface button', () => {const Component = InterfaceRoute.component as React.ComponentTyperender(<Component />)diff --git a/web-app/src/routes/settings/interface.tsx b/web-app/src/routes/settings/interface.tsxindex 270a890ee..ccb271c15 100644--- a/web-app/src/routes/settings/interface.tsx+++ b/web-app/src/routes/settings/interface.tsx@@ -12,11 +12,8 @@ import { ColorPickerAppPrimaryColor } from '@/containers/ColorPickerAppPrimaryCoimport { ColorPickerAppAccentColor } from '@/containers/ColorPickerAppAccentColor'import { ColorPickerAppDestructiveColor } from '@/containers/ColorPickerAppDestructiveColor'import { useInterfaceSettings } from '@/hooks/useInterfaceSettings'-import { useCodeblock } from '@/hooks/useCodeblock'+import { Button } from '@/components/ui/button'-import CodeBlockStyleSwitcher from '@/containers/CodeBlockStyleSwitcher'-import { LineNumbersSwitcher } from '@/containers/LineNumbersSwitcher'-import { CodeBlockExample } from '@/containers/CodeBlockExample'import { toast } from 'sonner'import { ChatWidthSwitcher } from '@/containers/ChatWidthSwitcher'import { TokenCounterCompactSwitcher } from '@/containers/TokenCounterCompactSwitcher'@@ -29,7 +26,6 @@ export const Route = createFileRoute(route.settings.interface as any)({function InterfaceSettings() {const { t } = useTranslation()const { resetInterface } = useInterfaceSettings()- const { resetCodeBlockStyle } = useCodeblock()return (<div className="flex flex-col h-full pb-[calc(env(safe-area-inset-bottom)+env(safe-area-inset-top))]">@@ -122,45 +118,6 @@ function InterfaceSettings() {actions={<TokenCounterCompactSwitcher />}/></Card>-- {/* Codeblock */}- <Card>- <CardItem- title={t('settings:interface.codeBlockTitle')}- description={t('settings:interface.codeBlockDesc')}- actions={<CodeBlockStyleSwitcher />}- />- <CodeBlockExample />- <CardItem- title={t('settings:interface.showLineNumbers')}- description={t('settings:interface.showLineNumbersDesc')}- actions={<LineNumbersSwitcher />}- />- <CardItem- title={t('settings:interface.resetCodeBlockStyle')}- description={t('settings:interface.resetCodeBlockStyleDesc')}- actions={- <Button- variant="destructive"- size="sm"- onClick={() => {- resetCodeBlockStyle()- toast.success(- t('settings:interface.resetCodeBlockSuccess'),- {- id: 'code-block-style',- description: t(- 'settings:interface.resetCodeBlockSuccessDesc'- ),- }- )- }}- >- {t('common:reset')}- </Button>- }- />- </Card></div></div></div>