diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 5f8643a7..c1a7d610 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -10,6 +10,7 @@ import GitSettings from "./pages/GitSettings"; import { NIP19Page } from "./pages/NIP19Page"; import NotFound from "./pages/NotFound"; import { ProjectView } from "./pages/ProjectView"; +import { SettingsLayout } from "./components/SettingsLayout"; export function AppRouter() { return ( @@ -19,9 +20,11 @@ export function AppRouter() { } /> } /> - } /> - } /> - } /> + }> + } /> + } /> + } /> + } /> {/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */} } /> diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx new file mode 100644 index 00000000..90f0a1c7 --- /dev/null +++ b/src/components/SettingsLayout.tsx @@ -0,0 +1,216 @@ +import { useState, useEffect } from 'react'; +import { useNavigate, useLocation, Outlet } from 'react-router-dom'; +import { Button } from '@/components/ui/button'; +import { Menu, Columns2, Settings as SettingsIcon, Bot, GitBranch } 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'; + +interface SettingsItem { + id: string; + title: string; + description: string; + icon: React.ComponentType<{ className?: string }>; + href: string; +} + +const settingsItems: SettingsItem[] = [ + { + id: 'ai', + title: 'AI Settings', + description: 'Configure AI providers and API keys', + icon: Bot, + href: '/settings/ai', + }, + { + id: 'git', + title: 'Git Settings', + description: 'Configure Git credentials for HTTP authentication', + icon: GitBranch, + href: '/settings/git', + }, +]; + +export function SettingsLayout() { + const navigate = useNavigate(); + const location = useLocation(); + const isMobile = useIsMobile(); + const projectsManager = useProjectsManager(); + + const [_projects, setProjects] = useState([]); + const [isSidebarVisible, setIsSidebarVisible] = useState(() => { + // On mobile, always start hidden + if (typeof window !== 'undefined' && window.innerWidth < 768) { + return false; + } + return false; // Default to closed initially + }); + const [hasSetInitialState, setHasSetInitialState] = useState(false); + + const loadProjects = useCallback(async () => { + try { + await projectsManager.init(); + const projectList = await projectsManager.getProjects(); + setProjects(projectList); + + // Set initial sidebar state based on projects and device type + if (!hasSetInitialState && !isMobile) { + // On desktop, show sidebar if there are projects + setIsSidebarVisible(projectList.length > 0); + setHasSetInitialState(true); + } else if (!hasSetInitialState && isMobile) { + // On mobile, always start hidden + setIsSidebarVisible(false); + setHasSetInitialState(true); + } + } catch (error) { + console.error('Failed to load projects:', error); + if (!hasSetInitialState) { + setHasSetInitialState(true); + } + } + }, [projectsManager, hasSetInitialState, isMobile]); + + useEffect(() => { + loadProjects(); + }, [loadProjects]); + + const handleProjectSelect = (project: Project | null) => { + if (project) { + setIsSidebarVisible(false); // Collapse sidebar on mobile navigation + navigate(`/project/${project.id}`); + } else { + navigate('/'); + } + }; + + // Get current settings page + const currentPath = location.pathname; + const currentSettingsId = settingsItems.find(item => item.href === currentPath)?.id; + + if (isMobile) { + return ( +
+ {/* Mobile Header */} +
+
+ +

Settings

+
+
+ + {/* Mobile Sidebar Overlay */} + {isSidebarVisible && ( +
+
setIsSidebarVisible(false)} + /> +
+ { + setIsSidebarVisible(false); + handleProjectSelect(project); + }} + /> +
+
+ )} + + +
+ ); + } + + // Desktop 3-column layout + return ( +
+ {/* Left Column - Projects Sidebar (optionally hidden) */} + {isSidebarVisible && ( +
+ +
+ )} + + {/* Middle Column - Settings Navigation */} +
+ {/* Header with toggle button */} +
+
+ +

+ + Settings +

+
+

+ Manage your application settings and preferences +

+
+ + {/* Settings Navigation */} +
+
+ {settingsItems.map((item) => { + const Icon = item.icon; + const isActive = currentSettingsId === item.id; + + return ( + + ); + })} +
+
+
+ + {/* Right Column - Settings Content */} +
+
+ +
+
+
+ ); +} \ No newline at end of file diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index ca0c8c49..0b343098 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -3,13 +3,12 @@ import { Check, Bot, ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Card, CardContent } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { Badge } from '@/components/ui/badge'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { useAISettings } from '@/hooks/useAISettings'; -import { AppLayout } from '@/components/AppLayout'; +import { useIsMobile } from '@/hooks/useIsMobile'; import { useNavigate } from 'react-router-dom'; import type { AIConnection } from '@/contexts/AISettingsContext'; @@ -74,6 +73,7 @@ const PRESET_PROVIDERS: PresetProvider[] = [ export function AISettings() { const { settings, addProvider, removeProvider, updateProvider } = useAISettings(); + const isMobile = useIsMobile(); const navigate = useNavigate(); const [customProviderName, setCustomProviderName] = useState(''); const [customBaseURL, setCustomBaseURL] = useState(''); @@ -137,254 +137,259 @@ export function AISettings() { const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id)); return ( - -
- - -
-
- -

- - AI Settings -

-
-

- Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser. -

-
+
+ {isMobile && ( +
+ +
+

+ + AI Settings +

+

+ Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser. +

+
+
+ )} -
- {/* Configured Providers */} - {configuredProviderIds.length > 0 && ( -
-

Configured Providers

- - {configuredProviderIds.map((providerId) => { - const preset = PRESET_PROVIDERS.find(p => p.id === providerId); - const provider = settings.providers[providerId]; - const isCustom = !preset; + {!isMobile && ( +
+

+ + AI Settings +

+

+ Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser. +

+
+ )} - return ( - - -
-
- - {preset?.name || providerId} - - {isCustom && Custom} -
- +
+ {/* Configured Providers */} + {configuredProviderIds.length > 0 && ( +
+

Configured Providers

+ + {configuredProviderIds.map((providerId) => { + const preset = PRESET_PROVIDERS.find(p => p.id === providerId); + const provider = settings.providers[providerId]; + const isCustom = !preset; + + return ( + + +
+
+ + {preset?.name || providerId} + + {isCustom && Custom}
- - -
-
- - handleUpdateProvider(providerId, { baseURL: e.target.value })} - /> -
-
- - -
- {!provider?.nostr && ( -
- - handleUpdateProvider(providerId, { apiKey: e.target.value })} - /> -
- )} -
-
- - ); - })} - -
- )} - - {configuredProviderIds.length > 0 && availablePresets.length > 0 && } - - {/* Available Preset Providers */} - {availablePresets.length > 0 && ( -
-

Add Provider

-
- {availablePresets.map((preset) => ( - - -
-
{preset.name}
- {preset.apiKeysURL && ( - - )} -
-
- {!preset.nostr && ( - setPresetApiKeys(prev => ({ - ...prev, - [preset.id]: e.target.value, - }))} - onKeyDown={(e) => { - if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) { - handleAddPresetProvider(preset); - } - }} - /> - )}
-
-
- ))} -
-
- )} - - {availablePresets.length > 0 && } - - {/* Custom Provider */} -
-

Add Custom Provider

- - -
- - setCustomProviderName(e.target.value)} - /> -
-
- - setCustomBaseURL(e.target.value)} - /> -
-
- - -
- {customAuthMethod === 'api-key' && ( -
- - setCustomApiKey(e.target.value)} - /> -
- )} - - {customProviderName.trim() in settings.providers && ( -

- Provider with this name already exists -

- )} -
-
+ + +
+
+ + handleUpdateProvider(providerId, { baseURL: e.target.value })} + /> +
+
+ + +
+ {!provider?.nostr && ( +
+ + handleUpdateProvider(providerId, { apiKey: e.target.value })} + /> +
+ )} +
+
+ + ); + })} +
+ )} + + {configuredProviderIds.length > 0 && availablePresets.length > 0 && } + + {/* Available Preset Providers */} + {availablePresets.length > 0 && ( +
+

Add Provider

+
+ {availablePresets.map((preset) => ( +
+
+
{preset.name}
+ {preset.apiKeysURL && ( + + )} +
+
+ {!preset.nostr && ( + setPresetApiKeys(prev => ({ + ...prev, + [preset.id]: e.target.value, + }))} + onKeyDown={(e) => { + if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) { + handleAddPresetProvider(preset); + } + }} + /> + )} + +
+
+ ))}
- - +
+ )} + + {availablePresets.length > 0 && } + + {/* Custom Provider */} +
+

Add Custom Provider

+
+
+ + setCustomProviderName(e.target.value)} + /> +
+
+ + setCustomBaseURL(e.target.value)} + /> +
+
+ + +
+ {customAuthMethod === 'api-key' && ( +
+ + setCustomApiKey(e.target.value)} + /> +
+ )} + + {customProviderName.trim() in settings.providers && ( +

+ Provider with this name already exists +

+ )} +
+
- +
); } diff --git a/src/pages/GitSettings.tsx b/src/pages/GitSettings.tsx index b43c237c..16aec66d 100644 --- a/src/pages/GitSettings.tsx +++ b/src/pages/GitSettings.tsx @@ -3,12 +3,11 @@ import { Check, GitBranch, ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Card, CardContent } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { Badge } from '@/components/ui/badge'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { useGitSettings } from '@/hooks/useGitSettings'; -import { AppLayout } from '@/components/AppLayout'; +import { useIsMobile } from '@/hooks/useIsMobile'; import { useNavigate } from 'react-router-dom'; import type { GitCredential } from '@/contexts/GitSettingsContext'; @@ -39,6 +38,7 @@ const PRESET_PROVIDERS: PresetProvider[] = [ export function GitSettings() { const { settings, addCredential, removeCredential, updateCredential } = useGitSettings(); + const isMobile = useIsMobile(); const navigate = useNavigate(); const [customOrigin, setCustomOrigin] = useState(''); const [customUsername, setCustomUsername] = useState(''); @@ -95,220 +95,225 @@ export function GitSettings() { const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredOrigins.includes(preset.origin)); return ( - -
- - -
-
- -

- - Git Settings -

-
-

- Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser. -

-
- -
- {/* Configured Credentials */} - {configuredOrigins.length > 0 && ( -
-

Configured Credentials

- - {configuredOrigins.map((origin) => { - const preset = PRESET_PROVIDERS.find(p => p.origin === origin); - const credential = settings.credentials[origin]; - const isCustom = !preset; - - return ( - - -
-
- - {preset?.name || new URL(origin).hostname} - - {isCustom && Custom} -
- -
-
- -
-
- - -
-
- - handleUpdateCredential(origin, { username: e.target.value })} - /> -
-
- - handleUpdateCredential(origin, { password: e.target.value })} - /> -
-
-
-
- ); - })} -
-
- )} - - {configuredOrigins.length > 0 && availablePresets.length > 0 && } - - {/* Available Preset Providers */} - {availablePresets.length > 0 && ( -
-

Add Provider

-
- {availablePresets.map((preset) => ( - - -
-
{preset.name}
- {preset.tokenURL && ( - - )} -
-
- setPresetTokens(prev => ({ - ...prev, - [preset.id]: e.target.value, - }))} - onKeyDown={(e) => { - if (e.key === 'Enter' && presetTokens[preset.id]?.trim()) { - handleAddPresetProvider(preset); - } - }} - /> - -
-
-
- ))} -
-
- )} - - {availablePresets.length > 0 && } - - {/* Custom Provider */} -
-

Add Custom Provider

- - -
- - setCustomOrigin(e.target.value)} - /> -
-
- - setCustomUsername(e.target.value)} - /> -
-
- - setCustomPassword(e.target.value)} - /> -
- - {customOrigin.trim() in settings.credentials && ( -

- Credentials for this origin already exist -

- )} -
-
+
+ {isMobile && ( +
+ +
+

+ + Git Settings +

+

+ Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser. +

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

+ + Git Settings +

+

+ Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser. +

+
+ )} + +
+ {/* Configured Credentials */} + {configuredOrigins.length > 0 && ( +
+

Configured Credentials

+ + {configuredOrigins.map((origin) => { + const preset = PRESET_PROVIDERS.find(p => p.origin === origin); + const credential = settings.credentials[origin]; + const isCustom = !preset; + + return ( + + +
+
+ + {preset?.name || new URL(origin).hostname} + + {isCustom && Custom} +
+ +
+
+ +
+
+ + +
+
+ + handleUpdateCredential(origin, { username: e.target.value })} + /> +
+
+ + handleUpdateCredential(origin, { password: e.target.value })} + /> +
+
+
+
+ ); + })} +
+
+ )} + + {configuredOrigins.length > 0 && availablePresets.length > 0 && } + + {/* Available Preset Providers */} + {availablePresets.length > 0 && ( +
+

Add Provider

+
+ {availablePresets.map((preset) => ( +
+
+
{preset.name}
+ {preset.tokenURL && ( + + )} +
+
+ setPresetTokens(prev => ({ + ...prev, + [preset.id]: e.target.value, + }))} + onKeyDown={(e) => { + if (e.key === 'Enter' && presetTokens[preset.id]?.trim()) { + handleAddPresetProvider(preset); + } + }} + /> + +
+
+ ))}
- - +
+ )} + + {availablePresets.length > 0 && } + + {/* Custom Provider */} +
+

Add Custom Provider

+
+
+ + setCustomOrigin(e.target.value)} + /> +
+
+ + setCustomUsername(e.target.value)} + /> +
+
+ + setCustomPassword(e.target.value)} + /> +
+ + {customOrigin.trim() in settings.credentials && ( +

+ Credentials for this origin already exist +

+ )} +
+
- +
); } diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index c3735db8..e0ffe48c 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,72 +1,66 @@ -import { AppLayout } from '@/components/AppLayout'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Button } from '@/components/ui/button'; -import { Settings as SettingsIcon, Bot, GitBranch } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; +import { Bot, GitBranch } from 'lucide-react'; +import { useIsMobile } from '@/hooks/useIsMobile'; + +interface SettingsItem { + id: string; + title: string; + description: string; + icon: React.ComponentType<{ className?: string }>; + href: string; +} + +const settingsItems: SettingsItem[] = [ + { + id: 'ai', + title: 'AI Settings', + description: 'Configure AI providers and API keys', + icon: Bot, + href: '/settings/ai', + }, + { + id: 'git', + title: 'Git Settings', + description: 'Configure Git credentials for HTTP authentication', + icon: GitBranch, + href: '/settings/git', + }, +]; export function Settings() { const navigate = useNavigate(); + const isMobile = useIsMobile(); - const settingsItems = [ - { - title: 'AI Settings', - description: 'Configure AI providers and API keys', - icon: Bot, - href: '/settings/ai', - }, - { - title: 'Git Settings', - description: 'Configure Git credentials for HTTP authentication', - icon: GitBranch, - href: '/settings/git', - }, - ]; - - return ( - -
- - -
-

- - Settings -

-

- Manage your application settings and preferences. -

-
- -
- {settingsItems.map((item) => { - const Icon = item.icon; - return ( - navigate(item.href)} - > - - - - {item.title} - - {item.description} - - - - - - ); - })} -
-
-
+ if (isMobile) { + return ( +
+
+

Settings

+

+ Manage your application settings and preferences. +

+
+
+ {settingsItems.map((item) => { + const Icon = item.icon; + return ( +
navigate(item.href)} + > + +
+
{item.title}
+
{item.description}
+
+
+ ); + })} +
- - ); + ); + } } export default Settings; \ No newline at end of file