diff --git a/src/components/SettingsPageLayout.tsx b/src/components/SettingsPageLayout.tsx new file mode 100644 index 00000000..8789b890 --- /dev/null +++ b/src/components/SettingsPageLayout.tsx @@ -0,0 +1,78 @@ +import { ArrowLeft, type LucideIcon } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { Button } from '@/components/ui/button'; +import { useIsMobile } from '@/hooks/useIsMobile'; +import { useNavigate } from 'react-router-dom'; +import type { ReactNode } from 'react'; + +interface SettingsPageLayoutProps { + /** The icon component to display next to the title */ + icon: LucideIcon; + /** Translation key for the page title */ + titleKey: string; + /** Translation key for the page description */ + descriptionKey: string; + /** The main content of the settings page */ + children: ReactNode; + /** Optional className for the content container */ + className?: string; +} + +/** + * Shared layout component for all settings pages. + * Provides consistent header structure with mobile back button, icon, title, and description. + */ +export function SettingsPageLayout({ + icon: Icon, + titleKey, + descriptionKey, + children, + className = 'space-y-6', +}: SettingsPageLayoutProps) { + const { t } = useTranslation(); + const isMobile = useIsMobile(); + const navigate = useNavigate(); + + return ( +
+ {isMobile && ( +
+ +
+

+ + {t(titleKey)} +

+

+ {t(descriptionKey)} +

+
+
+ )} + + {!isMobile && ( +
+

+ + {t(titleKey)} +

+

+ {t(descriptionKey)} +

+
+ )} + +
+ {children} +
+
+ ); +} diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index 923c3a63..5c3c0f9a 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -1,6 +1,6 @@ import { useState, useMemo, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown, RotateCcw, FileText, Plus, Edit, X } from 'lucide-react'; +import { Check, Bot, Trash2, GripVertical, ChevronDown, RotateCcw, FileText, Plus, Edit, X } from 'lucide-react'; import { DndContext, closestCenter, @@ -35,10 +35,10 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ import { Separator } from '@/components/ui/separator'; import { Skeleton } from '@/components/ui/skeleton'; import { useAISettings } from '@/hooks/useAISettings'; -import { useIsMobile } from '@/hooks/useIsMobile'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useAppContext } from '@/hooks/useAppContext'; -import { useNavigate, Link } from 'react-router-dom'; +import { Link } from 'react-router-dom'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import type { AIProvider } from '@/contexts/AISettingsContext'; import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets'; import { ExternalFavicon } from '@/components/ExternalFavicon'; @@ -204,8 +204,6 @@ function generateIdFromName(name: string): string { export function AISettings() { const { t } = useTranslation(); const { settings, updateSettings, setProvider, removeProvider, setProviders, isLoading } = useAISettings(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); const { user } = useCurrentUser(); const { config, defaultConfig, updateConfig } = useAppContext(); const [customProviderName, setCustomProviderName] = useState(''); @@ -352,44 +350,13 @@ export function AISettings() { }, []); return ( -
- {isMobile && ( -
- -
-

- - {t('aiSettings')} -

-

- {t('aiSettingsDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('aiSettings')} -

-

- {t('aiSettingsDescription')} -

-
- )} - + {isLoading ? ( -
+ <> {/* Loading skeleton for configured providers */}
@@ -412,9 +379,9 @@ export function AISettings() {
-
+ ) : ( -
+ <> {/* Configured Providers */} {settings.providers.length > 0 && (
@@ -802,7 +769,7 @@ export function AISettings() {
)}
-
+ )} {/* Render credits dialog outside of accordion structure */} @@ -820,7 +787,7 @@ export function AISettings() { /> ); })()} -
+ ); } diff --git a/src/pages/AboutSettings.tsx b/src/pages/AboutSettings.tsx index 333406c6..f8f5efa3 100644 --- a/src/pages/AboutSettings.tsx +++ b/src/pages/AboutSettings.tsx @@ -1,18 +1,15 @@ import { useState, useEffect } from 'react'; -import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Info, ExternalLink, Loader2, AlertTriangle, ArrowLeft, Code, Globe } from 'lucide-react'; +import { Info, ExternalLink, Loader2, AlertTriangle, Code, Globe } from 'lucide-react'; import { Button } from '@/components/ui/button'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Card, CardContent } from '@/components/ui/card'; -import { useIsMobile } from '@/hooks/useIsMobile'; import { EmailSubscription } from '@/components/EmailSubscription'; export function AboutSettings() { const { t } = useTranslation(); - const navigate = useNavigate(); - const isMobile = useIsMobile(); const [license, setLicense] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); @@ -43,41 +40,11 @@ export function AboutSettings() { }, []); return ( -
- {isMobile && ( -
- -
-

- - {t('aboutShakespeare')} -

-

- {t('aboutShakespeareDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('aboutShakespeare')} -

-

- {t('aboutShakespeareDescription')} -

-
- )} +
{/* Email Updates */} @@ -187,7 +154,7 @@ export function AboutSettings() {
)}
- + ); } diff --git a/src/pages/DeploySettings.tsx b/src/pages/DeploySettings.tsx index 73484f6c..25b99f80 100644 --- a/src/pages/DeploySettings.tsx +++ b/src/pages/DeploySettings.tsx @@ -1,6 +1,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Rocket, ArrowLeft, Trash2, Check, GripVertical, ChevronDown, Plus } from 'lucide-react'; +import { Rocket, Trash2, Check, GripVertical, ChevronDown, Plus } from 'lucide-react'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Checkbox } from '@/components/ui/checkbox'; import { DropdownMenu, @@ -40,8 +41,7 @@ import { useDeploySettings } from '@/hooks/useDeploySettings'; import { useNetlifyOAuth } from '@/hooks/useNetlifyOAuth'; import { useVercelOAuth } from '@/hooks/useVercelOAuth'; import { useCurrentUser } from '@/hooks/useCurrentUser'; -import { useIsMobile } from '@/hooks/useIsMobile'; -import { useNavigate, Link } from 'react-router-dom'; +import { Link } from 'react-router-dom'; import type { DeployProvider } from '@/contexts/DeploySettingsContext'; import { ExternalFavicon } from '@/components/ExternalFavicon'; import { normalizeUrl } from '@/lib/url'; @@ -427,8 +427,6 @@ export function DeploySettings() { const { t } = useTranslation(); const { settings, removeProvider, setProviders, isInitialized } = useDeploySettings(); const { user } = useCurrentUser(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); // OAuth hooks const netlifyOAuth = useNetlifyOAuth(); @@ -669,44 +667,13 @@ export function DeploySettings() { const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id)); return ( -
- {isMobile && ( -
- -
-

- - {t('deploySettings')} -

-

- {t('deploySettingsDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('deploySettings')} -

-

- {t('deploySettingsDescription')} -

-
- )} - + {!isInitialized ? ( -
+ <> {/* Loading skeleton for configured providers */}
@@ -730,9 +697,9 @@ export function DeploySettings() {
-
+ ) : ( -
+ <> {/* Configured Providers */} {settings.providers.length > 0 && (
@@ -1180,9 +1147,9 @@ export function DeploySettings() {
-
+ )} -
+
); } diff --git a/src/pages/GitSettings.tsx b/src/pages/GitSettings.tsx index a83813cd..9e1bb4fe 100644 --- a/src/pages/GitSettings.tsx +++ b/src/pages/GitSettings.tsx @@ -1,6 +1,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Check, GitBranch, ArrowLeft, Trash2, ChevronDown, Plus, User, GripVertical } from 'lucide-react'; +import { Check, GitBranch, Trash2, ChevronDown, Plus, User, GripVertical } from 'lucide-react'; import { DndContext, closestCenter, @@ -36,8 +36,7 @@ import { } from '@/components/ui/dropdown-menu'; import { useGitSettings } from '@/hooks/useGitSettings'; import { useGitHubOAuth } from '@/hooks/useGitHubOAuth'; -import { useIsMobile } from '@/hooks/useIsMobile'; -import { useNavigate } from 'react-router-dom'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import type { GitCredential } from '@/contexts/GitSettingsContext'; import { PasswordInput } from '@/components/ui/password-input'; import { ExternalInput } from '@/components/ui/external-input'; @@ -192,8 +191,6 @@ export function GitSettings() { const { t } = useTranslation(); const { settings, addCredential, removeCredential, setCredentials, updateSettings, isInitialized } = useGitSettings(); const { initiateOAuth, isLoading: isOAuthLoading, error: oauthError, isOAuthConfigured } = useGitHubOAuth(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); const [customName, setCustomName] = useState(''); const [customOrigin, setCustomOrigin] = useState(''); const [customUsername, setCustomUsername] = useState(''); @@ -283,44 +280,13 @@ export function GitSettings() { const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredOrigins.includes(preset.origin)); return ( -
- {isMobile && ( -
- -
-

- - {t('gitSettings')} -

-

- {t('gitSettingsDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('gitSettings')} -

-

- {t('gitSettingsDescription')} -

-
- )} - + {!isInitialized ? ( -
+ <> {/* Loading skeleton for configured credentials */}
@@ -348,9 +314,9 @@ export function GitSettings() {
-
+ ) : ( -
+ <> {/* Configured Credentials */} {settings.credentials.length > 0 && (
@@ -645,9 +611,9 @@ export function GitSettings() {
-
+ )} -
+
); } diff --git a/src/pages/NostrSettings.tsx b/src/pages/NostrSettings.tsx index 8950793b..c038a76c 100644 --- a/src/pages/NostrSettings.tsx +++ b/src/pages/NostrSettings.tsx @@ -1,6 +1,7 @@ -import { ArrowLeft, Wifi, Users, UserPlus, LogOut, Trash2, User, Plus, Server, Key } from 'lucide-react'; +import { Wifi, Users, UserPlus, LogOut, Trash2, User, Plus, Server, Key } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Skeleton } from '@/components/ui/skeleton'; import { Separator } from '@/components/ui/separator'; @@ -8,8 +9,6 @@ import { RelayListManager } from '@/components/RelayListManager'; import { GraspListManager } from '@/components/GraspListManager'; import SimpleLoginDialog from '@/components/auth/SimpleLoginDialog'; import SimpleSignupDialog from '@/components/auth/SimpleSignupDialog'; -import { useIsMobile } from '@/hooks/useIsMobile'; -import { useNavigate } from 'react-router-dom'; import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts'; import { genUserName } from '@/lib/genUserName'; import { useState } from 'react'; @@ -22,8 +21,6 @@ const sanitizeFilename = (filename: string) => { export function NostrSettings() { const { t } = useTranslation(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); const { authors, currentUser, setLogin, removeLogin, isLoading } = useLoggedInAccounts(); const [showLoginDialog, setShowLoginDialog] = useState(false); const [showSignupDialog, setShowSignupDialog] = useState(false); @@ -104,43 +101,13 @@ export function NostrSettings() { }; return ( -
- {isMobile && ( -
- -
-

- - {t('nostrSettings')} -

-

- {t('nostrSettingsDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('nostrSettings')} -

-

- {t('nostrSettingsDescription')} -

-
- )} - -
+ <> + {/* Account Management */}
@@ -281,7 +248,7 @@ export function NostrSettings() {
-
+ {/* Login Dialog */} -
+ ); } diff --git a/src/pages/Preferences.tsx b/src/pages/Preferences.tsx index 7e4935fb..c18d6107 100644 --- a/src/pages/Preferences.tsx +++ b/src/pages/Preferences.tsx @@ -1,57 +1,23 @@ -import { Settings2, ArrowLeft } from "lucide-react"; +import { Settings2 } from "lucide-react"; import { useTranslation } from 'react-i18next'; -import { Button } from "@/components/ui/button"; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Card, CardContent } from "@/components/ui/card"; import { ThemePicker } from "@/components/ThemePicker"; import { LanguagePicker } from "@/components/LanguagePicker"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; -import { useIsMobile } from "@/hooks/useIsMobile"; -import { useNavigate } from "react-router-dom"; import { useAppContext } from "@/hooks/useAppContext"; export function Preferences() { const { t } = useTranslation(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); const { config, updateConfig } = useAppContext(); return ( -
- {isMobile && ( -
- -
-

- - {t('preferences')} -

-

- {t('preferencesDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('preferences')} -

-

- {t('preferencesDescription')} -

-
- )} + @@ -101,7 +67,7 @@ export function Preferences() {
-
+ ); } diff --git a/src/pages/StorageSettings.tsx b/src/pages/StorageSettings.tsx index 2e94c6a6..d2be2b2e 100644 --- a/src/pages/StorageSettings.tsx +++ b/src/pages/StorageSettings.tsx @@ -1,15 +1,15 @@ import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Download, Trash2, AlertTriangle, Loader2, Database, Info, ArrowLeft, Shield } from 'lucide-react'; +import { Download, Trash2, AlertTriangle, Loader2, Database, Info, Shield } from 'lucide-react'; import { Button } from '@/components/ui/button'; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { Progress } from '@/components/ui/progress'; import { Switch } from '@/components/ui/switch'; import { useToast } from '@/hooks/useToast'; import { useFS } from '@/hooks/useFS'; -import { useIsMobile } from '@/hooks/useIsMobile'; import { useOffline } from '@/hooks/useOffline'; import { isPersistentStorageSupported, @@ -42,9 +42,8 @@ export function StorageSettings() { const [isPersistent, setIsPersistent] = useState(null); const { toast } = useToast(); const { fs } = useFS(); - const navigate = useNavigate(); - const isMobile = useIsMobile(); const { clearCache } = useOffline(); + const navigate = useNavigate(); // Format bytes to human readable format const formatBytes = (bytes: number): string => { @@ -270,201 +269,169 @@ export function StorageSettings() { }; return ( -
- {isMobile && ( -
- + + {/* Storage Information */} + {storageError ? ( +
+ + {storageError} +
+ ) : storageInfo ? ( +
+ {/* Usage Progress */}
-

- - {t('storageSettings')} -

-

- {t('storageSettingsDescription')} -

+
+ {t('used')}: {formatBytes(storageInfo.usage)} + {t('available')}: {formatBytes(storageInfo.quota)} +
+ 0 ? (storageInfo.usage / storageInfo.quota) * 100 : 0} + className="h-2" + /> +
+ {storageInfo.quota > 0 + ? t('usagePercentage', { percentage: ((storageInfo.usage / storageInfo.quota) * 100).toFixed(1) }) + : t('usageUnavailable') + } +
+ +
+ ) : ( +
+ + {t('loadingStorageInfo')}
)} - {!isMobile && ( -
-

- - {t('storageSettings')} -

-

- {t('storageSettingsDescription')} -

-
- )} - -
- {/* Storage Information */} - {storageError ? ( -
- - {storageError} + {/* Persist Data */} + + + + + {t('persistData')} + + + {t('persistDataDescription')} + + + +
+
- ) : storageInfo ? ( -
- {/* Usage Progress */} -
-
- {t('used')}: {formatBytes(storageInfo.usage)} - {t('available')}: {formatBytes(storageInfo.quota)} -
- 0 ? (storageInfo.usage / storageInfo.quota) * 100 : 0} - className="h-2" - /> -
- {storageInfo.quota > 0 - ? t('usagePercentage', { percentage: ((storageInfo.usage / storageInfo.quota) * 100).toFixed(1) }) - : t('usageUnavailable') - } -
-
+ + -
- ) : ( -
- - {t('loadingStorageInfo')} -
- )} + {/* Export Files */} + + + + + {t('exportFiles')} + + + {t('exportFilesDescription')} + + + + + + - {/* Persist Data */} - - - - - {t('persistData')} - - - {t('persistDataDescription')} - - - -
- -
-
-
- - {/* Export Files */} - - - - - {t('exportFiles')} - - - {t('exportFilesDescription')} - - - - - - - - {/* Clear All Data */} - - - - - {t('clearAllData')} - - - {t('clearAllDataDescription')} - - - - - - + + + + + + {t('areYouSure')} + + +

+ {t('clearDataWarning')} +

+
    +
  • {t('allProjects')}
  • +
  • {t('aiSettingsAndKeys')}
  • +
  • {t('gitCredentialsSettings')}
  • +
  • {t('userPreferences')}
  • +
  • {t('cachedData')}
  • +
+

+ {t('actionCannotBeUndone')} +

+
+
+ + {t('cancel')} + - {isClearing ? ( - <> - - {t('clearing')} - - ) : ( - <> - - {t('clearAllData')} - - )} - - - - - - - {t('areYouSure')} - - -

- {t('clearDataWarning')} -

-
    -
  • {t('allProjects')}
  • -
  • {t('aiSettingsAndKeys')}
  • -
  • {t('gitCredentialsSettings')}
  • -
  • {t('userPreferences')}
  • -
  • {t('cachedData')}
  • -
-

- {t('actionCannotBeUndone')} -

-
-
- - {t('cancel')} - - {t('yesClearAllData')} - - -
-
-
-
-
-
+ {t('yesClearAllData')} + + + + + + +
); } diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index d14e7439..b064c9dd 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -1,13 +1,12 @@ -import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon, GitBranch } from "lucide-react"; +import { Settings, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon, GitBranch } from "lucide-react"; import { useTranslation } from 'react-i18next'; import { useState, useEffect, useMemo } from "react"; import { Button } from "@/components/ui/button"; +import { SettingsPageLayout } from '@/components/SettingsPageLayout'; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; -import { useIsMobile } from "@/hooks/useIsMobile"; -import { useNavigate } from "react-router-dom"; import { useAppContext } from "@/hooks/useAppContext"; import { useOffline } from "@/hooks/useOffline"; import { useToast } from "@/hooks/useToast"; @@ -15,8 +14,6 @@ import { Terminal } from "@/components/Terminal"; export function SystemSettings() { const { t } = useTranslation(); - const isMobile = useIsMobile(); - const navigate = useNavigate(); const { config, defaultConfig, updateConfig } = useAppContext(); const { toast } = useToast(); const { serviceWorkerRegistration, updateServiceWorker, clearCache } = useOffline(); @@ -256,41 +253,11 @@ export function SystemSettings() { }; return ( -
- {isMobile && ( -
- -
-

- - {t('systemSettings')} -

-

- {t('systemSettingsDescription')} -

-
-
- )} - - {!isMobile && ( -
-

- - {t('systemSettings')} -

-

- {t('systemSettingsDescription')} -

-
- )} +
{/* Service Worker Configuration */} @@ -1029,7 +996,7 @@ export function SystemSettings() {
-
+ ); }