From c95a41dd016c9ec7e2e4189def8f9bef1cde6edc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 8 Oct 2025 13:36:43 -0500 Subject: [PATCH] Make settings DRY --- src/components/SettingsLayout.tsx | 67 ++----------------------------- src/lib/settingsItems.ts | 66 ++++++++++++++++++++++++++++++ src/pages/Settings.tsx | 63 +---------------------------- 3 files changed, 70 insertions(+), 126 deletions(-) create mode 100644 src/lib/settingsItems.ts diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index 25d7f74d..636e7ce0 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -1,76 +1,15 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useCallback } from 'react'; import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Menu, Bot, GitBranch, Database, Wifi, Settings2, Info, Settings } from 'lucide-react'; +import { Menu } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; import { type Project } from '@/lib/ProjectsManager'; -import { useCallback } from 'react'; import { cn } from '@/lib/utils'; - -interface SettingsItem { - id: string; - title: string; - description: string; - icon: React.ComponentType<{ className?: string }>; - href: string; -} - -// Define settings items as a function to get fresh translations -const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ - { - id: 'preferences', - title: t('preferences'), - description: t('preferencesDescription'), - icon: Settings2, - href: '/settings/preferences', - }, - { - id: 'ai', - title: t('aiSettings'), - description: t('aiSettingsDescription'), - icon: Bot, - href: '/settings/ai', - }, - { - id: 'git', - title: t('gitSettings'), - description: t('gitSettingsDescription'), - icon: GitBranch, - href: '/settings/git', - }, - { - id: 'nostr', - title: t('nostrSettings'), - description: t('nostrSettingsDescription'), - icon: Wifi, - href: '/settings/nostr', - }, - { - id: 'data', - title: t('dataSettings'), - description: t('dataSettingsDescription'), - icon: Database, - href: '/settings/data', - }, - { - id: 'system', - title: t('systemSettings'), - description: t('systemSettingsDescription'), - icon: Settings, - href: '/settings/system', - }, - { - id: 'about', - title: t('aboutShakespeare'), - description: t('aboutShakespeareDescription'), - icon: Info, - href: '/settings/about', - }, -]; +import { getSettingsItems } from '@/lib/settingsItems'; export function SettingsLayout() { const { t } = useTranslation(); diff --git a/src/lib/settingsItems.ts b/src/lib/settingsItems.ts new file mode 100644 index 00000000..3e27c8db --- /dev/null +++ b/src/lib/settingsItems.ts @@ -0,0 +1,66 @@ +import { Bot, GitBranch, Database, Wifi, Settings2, Info, Settings } from 'lucide-react'; + +export interface SettingsItem { + id: string; + title: string; + description: string; + icon: React.ComponentType<{ className?: string }>; + href: string; +} + +/** + * Get the list of settings items with translations + * @param t - Translation function from useTranslation hook + * @returns Array of settings items + */ +export const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ + { + id: 'preferences', + title: t('preferences'), + description: t('preferencesDescription'), + icon: Settings2, + href: '/settings/preferences', + }, + { + id: 'ai', + title: t('aiSettings'), + description: t('aiSettingsDescription'), + icon: Bot, + href: '/settings/ai', + }, + { + id: 'git', + title: t('gitSettings'), + description: t('gitSettingsDescription'), + icon: GitBranch, + href: '/settings/git', + }, + { + id: 'nostr', + title: t('nostrSettings'), + description: t('nostrSettingsDescription'), + icon: Wifi, + href: '/settings/nostr', + }, + { + id: 'data', + title: t('dataSettings'), + description: t('dataSettingsDescription'), + icon: Database, + href: '/settings/data', + }, + { + id: 'system', + title: t('systemSettings'), + description: t('systemSettingsDescription'), + icon: Settings, + href: '/settings/system', + }, + { + id: 'about', + title: t('aboutShakespeare'), + description: t('aboutShakespeareDescription'), + icon: Info, + href: '/settings/about', + }, +]; diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index c8da3d66..6d421de8 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,68 +1,7 @@ import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; - -interface SettingsItem { - id: string; - title: string; - description: string; - icon: React.ComponentType<{ className?: string }>; - href: string; -} - -// Define settings items as a function to get fresh translations -const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [ - { - id: 'preferences', - title: t('preferences'), - description: t('preferencesDescription'), - icon: Settings2, - href: '/settings/preferences', - }, - { - id: 'ai', - title: t('aiSettings'), - description: t('aiSettingsDescription'), - icon: Bot, - href: '/settings/ai', - }, - { - id: 'git', - title: t('gitSettings'), - description: t('gitSettingsDescription'), - icon: GitBranch, - href: '/settings/git', - }, - { - id: 'nostr', - title: t('nostrSettings'), - description: t('nostrSettingsDescription'), - icon: Wifi, - href: '/settings/nostr', - }, - { - id: 'data', - title: t('dataSettings'), - description: t('dataSettingsDescription'), - icon: Database, - href: '/settings/data', - }, - { - id: 'system', - title: t('systemSettings'), - description: t('systemSettingsDescription'), - icon: Settings, - href: '/settings/system', - }, - { - id: 'about', - title: t('aboutShakespeare'), - description: t('aboutShakespeareDescription'), - icon: Info, - href: '/settings/about', - }, -]; +import { getSettingsItems } from '@/lib/settingsItems'; export function Settings() { const { t } = useTranslation();