import * as RadixDialog from '@radix-ui/react-dialog'; import { motion } from 'framer-motion'; import { useState, useEffect } from 'react'; import { classNames } from '~/utils/classNames'; import { TabManagement } from './TabManagement'; import { TabTile } from '~/components/settings/shared/TabTile'; import { DialogTitle } from '~/components/ui/Dialog'; import type { TabType, TabVisibilityConfig } from '~/components/settings/settings.types'; import { tabConfigurationStore, updateTabConfiguration } from '~/lib/stores/settings'; import { useStore } from '@nanostores/react'; import { DndProvider, useDrag, useDrop } from 'react-dnd'; import { HTML5Backend } from 'react-dnd-html5-backend'; import DebugTab from '~/components/settings/debug/DebugTab'; import { EventLogsTab } from '~/components/settings/event-logs/EventLogsTab'; import UpdateTab from '~/components/settings/update/UpdateTab'; import { ProvidersTab } from '~/components/settings/providers/ProvidersTab'; import DataTab from '~/components/settings/data/DataTab'; import FeaturesTab from '~/components/settings/features/FeaturesTab'; import NotificationsTab from '~/components/settings/notifications/NotificationsTab'; import SettingsTab from '~/components/settings/settings/SettingsTab'; import ProfileTab from '~/components/settings/profile/ProfileTab'; import ConnectionsTab from '~/components/settings/connections/ConnectionsTab'; import { useUpdateCheck, useFeatures, useNotifications, useConnectionStatus, useDebugStatus } from '~/lib/hooks'; import * as DropdownMenu from '@radix-ui/react-dropdown-menu'; interface DraggableTabTileProps { tab: TabVisibilityConfig; index: number; moveTab: (dragIndex: number, hoverIndex: number) => void; onClick: () => void; isActive: boolean; hasUpdate: boolean; statusMessage: string; description: string; isLoading?: boolean; } const TAB_DESCRIPTIONS: Record = { profile: 'Manage your profile and account settings', settings: 'Configure application preferences', notifications: 'View and manage your notifications', features: 'Explore new and upcoming features', data: 'Manage your data and storage', providers: 'Configure AI providers and models', connection: 'Check connection status and settings', debug: 'Debug tools and system information', 'event-logs': 'View system events and logs', update: 'Check for updates and release notes', }; const DraggableTabTile = ({ tab, index, moveTab, onClick, isActive, hasUpdate, statusMessage, description, isLoading, }: DraggableTabTileProps) => { const [{ isDragging }, drag] = useDrag({ type: 'tab', item: { index }, collect: (monitor) => ({ isDragging: monitor.isDragging(), }), }); const [, drop] = useDrop({ accept: 'tab', hover: (item: { index: number }) => { if (item.index === index) { return; } moveTab(item.index, index); item.index = index; }, }); return (
drag(drop(node))} style={{ opacity: isDragging ? 0.5 : 1 }}>
); }; interface DeveloperWindowProps { open: boolean; onClose: () => void; } export const DeveloperWindow = ({ open, onClose }: DeveloperWindowProps) => { const tabConfiguration = useStore(tabConfigurationStore); const [activeTab, setActiveTab] = useState(null); const [showTabManagement, setShowTabManagement] = useState(false); const [loadingTab, setLoadingTab] = useState(null); const [profile, setProfile] = useState(() => { const saved = localStorage.getItem('bolt_user_profile'); return saved ? JSON.parse(saved) : { avatar: null, notifications: true }; }); // Listen for profile changes useEffect(() => { const handleStorageChange = (e: StorageEvent) => { if (e.key === 'bolt_user_profile') { const newProfile = e.newValue ? JSON.parse(e.newValue) : { avatar: null, notifications: true }; setProfile(newProfile); } }; window.addEventListener('storage', handleStorageChange); return () => window.removeEventListener('storage', handleStorageChange); }, []); // Status hooks const { hasUpdate, currentVersion, acknowledgeUpdate } = useUpdateCheck(); const { hasNewFeatures, unviewedFeatures, acknowledgeAllFeatures } = useFeatures(); const { hasUnreadNotifications, unreadNotifications, markAllAsRead } = useNotifications(); const { hasConnectionIssues, currentIssue, acknowledgeIssue } = useConnectionStatus(); const { hasActiveWarnings, activeIssues, acknowledgeAllIssues } = useDebugStatus(); const handleBack = () => { if (showTabManagement) { setShowTabManagement(false); } else if (activeTab) { setActiveTab(null); } }; // Only show tabs that are assigned to the developer window AND are visible const visibleDeveloperTabs = tabConfiguration.developerTabs .filter((tab) => { // Hide notifications tab if notifications are disabled if (tab.id === 'notifications' && !profile.notifications) { return false; } return tab.visible; }) .sort((a: TabVisibilityConfig, b: TabVisibilityConfig) => (a.order || 0) - (b.order || 0)); const moveTab = (dragIndex: number, hoverIndex: number) => { const draggedTab = visibleDeveloperTabs[dragIndex]; const targetTab = visibleDeveloperTabs[hoverIndex]; // Update the order of the dragged and target tabs const updatedDraggedTab = { ...draggedTab, order: targetTab.order }; const updatedTargetTab = { ...targetTab, order: draggedTab.order }; // Update both tabs in the store updateTabConfiguration(updatedDraggedTab); updateTabConfiguration(updatedTargetTab); }; const handleTabClick = (tabId: TabType) => { // Don't allow clicking notifications tab if disabled if (tabId === 'notifications' && !profile.notifications) { return; } setLoadingTab(tabId); setActiveTab(tabId); // Acknowledge the status based on tab type switch (tabId) { case 'update': acknowledgeUpdate(); break; case 'features': acknowledgeAllFeatures(); break; case 'notifications': markAllAsRead(); break; case 'connection': acknowledgeIssue(); break; case 'debug': acknowledgeAllIssues(); break; } // Clear loading state after a short delay setTimeout(() => { setLoadingTab(null); }, 500); }; const getTabComponent = () => { switch (activeTab) { case 'profile': return ; case 'settings': return ; case 'notifications': return ; case 'features': return ; case 'data': return ; case 'providers': return ; case 'connection': return ; case 'debug': return ; case 'event-logs': return ; case 'update': return ; default: return null; } }; const getTabUpdateStatus = (tabId: TabType): boolean => { switch (tabId) { case 'update': return hasUpdate; case 'features': return hasNewFeatures; case 'notifications': return hasUnreadNotifications; case 'connection': return hasConnectionIssues; case 'debug': return hasActiveWarnings; default: return false; } }; const getStatusMessage = (tabId: TabType): string => { switch (tabId) { case 'update': return `New update available (v${currentVersion})`; case 'features': return `${unviewedFeatures.length} new feature${unviewedFeatures.length === 1 ? '' : 's'} to explore`; case 'notifications': return `${unreadNotifications.length} unread notification${unreadNotifications.length === 1 ? '' : 's'}`; case 'connection': return currentIssue === 'disconnected' ? 'Connection lost' : currentIssue === 'high-latency' ? 'High latency detected' : 'Connection issues detected'; case 'debug': { const warnings = activeIssues.filter((i) => i.type === 'warning').length; const errors = activeIssues.filter((i) => i.type === 'error').length; return `${warnings} warning${warnings === 1 ? '' : 's'}, ${errors} error${errors === 1 ? '' : 's'}`; } default: return ''; } }; return (
{/* Header */}
{activeTab || showTabManagement ? ( ) : ( )} {showTabManagement ? 'Tab Management' : activeTab ? 'Developer Tools' : 'Developer Settings'}
{!activeTab && !showTabManagement && ( setShowTabManagement(true)} className="flex items-center space-x-2 px-3 py-1.5 rounded-lg bg-gray-100 dark:bg-gray-800 hover:bg-purple-500/10 dark:hover:bg-purple-500/20 group transition-all duration-200" whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} >
Manage Tabs )}
handleTabClick('profile')} >
Profile handleTabClick('settings')} >
Settings {profile.notifications && ( <> handleTabClick('notifications')} >
Notifications {hasUnreadNotifications && ( {unreadNotifications.length} )} )}
Close
{/* Content */}
{showTabManagement ? ( ) : activeTab ? ( getTabComponent() ) : (
{visibleDeveloperTabs.map((tab: TabVisibilityConfig, index: number) => ( handleTabClick(tab.id)} isActive={activeTab === tab.id} hasUpdate={getTabUpdateStatus(tab.id)} statusMessage={getStatusMessage(tab.id)} description={TAB_DESCRIPTIONS[tab.id]} isLoading={loadingTab === tab.id} /> ))}
)}
); };