Spaces:
Configuration error
Configuration error
File size: 6,778 Bytes
01ae808 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import React, { Suspense, useCallback, useMemo, useState, useEffect } from 'react';
import { ErrorBoundary } from './components/ErrorBoundary.tsx';
import { useGlobalState } from './contexts/GlobalStateContext.tsx';
import { logEvent } from './services/telemetryService.ts';
import { ALL_FEATURES, FEATURES_MAP } from './components/features/index.ts';
import type { ViewType, FeatureId, SidebarItem } from './types.ts';
import { DownloadManager } from './components/DownloadManager.tsx';
import { LeftSidebar } from './components/LeftSidebar.tsx';
import { StatusBar } from './components/StatusBar.tsx';
import { CommandPalette } from './components/CommandPalette.tsx';
import { SettingsView } from './components/SettingsView.tsx';
import { Cog6ToothIcon, HomeIcon } from './components/icons/InterfaceIcons.tsx';
import { AiCommandCenter } from './components/features/AiCommandCenter.tsx';
import { LoginView } from './components/LoginView.tsx';
export const LoadingIndicator: React.FC = () => (
<div className="w-full h-full flex items-center justify-center bg-surface">
<div className="flex items-center justify-center space-x-2">
<div className="w-4 h-4 rounded-full bg-primary animate-pulse" style={{ animationDelay: '0s' }}></div>
<div className="w-4 h-4 rounded-full bg-primary animate-pulse" style={{ animationDelay: '0.2s' }}></div>
<div className="w-4 h-4 rounded-full bg-primary animate-pulse" style={{ animationDelay: '0.4s' }}></div>
<span className="text-text-secondary ml-2">Loading Feature...</span>
</div>
</div>
);
interface LocalStorageConsentModalProps {
onAccept: () => void;
onDecline: () => void;
}
const LocalStorageConsentModal: React.FC<LocalStorageConsentModalProps> = ({ onAccept, onDecline }) => {
return (
<div className="fixed inset-0 bg-gray-900/80 backdrop-blur-sm z-50 flex items-center justify-center fade-in">
<div
className="bg-surface border border-border rounded-2xl shadow-2xl shadow-black/50 w-full max-w-md m-4 p-8 text-center animate-pop-in"
>
<h2 className="text-2xl mb-4">Store Data Locally?</h2>
<p className="text-text-secondary mb-6">
This application uses your browser's local storage to save your settings and remember your progress between sessions. This data stays on your computer and is not shared.
</p>
<div className="flex justify-center gap-4">
<button
onClick={onDecline}
className="px-6 py-2 bg-surface border border-border text-text-primary font-bold rounded-md hover:bg-gray-100 transition-colors"
>
Decline
</button>
<button
onClick={onAccept}
className="btn-primary px-6 py-2"
>
Accept
</button>
</div>
</div>
</div>
);
};
const App: React.FC = () => {
const { state, dispatch } = useGlobalState();
const { activeView, viewProps, hiddenFeatures, isAuthenticated } = state;
const [isCommandPaletteOpen, setCommandPaletteOpen] = useState(false);
const [showConsentModal, setShowConsentModal] = useState(false);
useEffect(() => {
try {
const consent = localStorage.getItem('devcore_ls_consent');
if (!consent) {
setShowConsentModal(true);
}
} catch (e) {
console.warn("Could not access localStorage.", e);
}
}, []);
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault();
setCommandPaletteOpen(isOpen => !isOpen);
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, []);
const handleAcceptConsent = () => {
try {
localStorage.setItem('devcore_ls_consent', 'granted');
window.location.reload();
} catch (e) {
console.error("Could not write to localStorage.", e);
setShowConsentModal(false);
}
};
const handleDeclineConsent = () => {
try {
localStorage.setItem('devcore_ls_consent', 'denied');
} catch (e) {
console.error("Could not write to localStorage.", e);
}
setShowConsentModal(false);
};
const handleViewChange = useCallback((view: ViewType, props: any = {}) => {
dispatch({ type: 'SET_VIEW', payload: { view, props } });
logEvent('view_changed', { view });
setCommandPaletteOpen(false);
}, [dispatch]);
const sidebarItems: SidebarItem[] = useMemo(() => [
{ id: 'ai-command-center', label: 'Command Center', icon: <HomeIcon />, view: 'ai-command-center' },
...ALL_FEATURES
.filter(feature => !hiddenFeatures.includes(feature.id) && feature.id !== 'ai-command-center')
.map(feature => ({
id: feature.id,
label: feature.name,
icon: feature.icon,
view: feature.id as ViewType,
})),
{ id: 'settings', label: 'Settings', icon: <Cog6ToothIcon />, view: 'settings' },
], [hiddenFeatures]);
const ActiveComponent = useMemo(() => {
if (activeView === 'settings') return SettingsView;
// Fallback to command center if no view is matched.
return FEATURES_MAP.get(activeView as string)?.component ?? AiCommandCenter;
}, [activeView]);
if (!isAuthenticated) {
return <LoginView />;
}
return (
<div className="h-screen w-screen font-sans overflow-hidden bg-background">
{showConsentModal && <LocalStorageConsentModal onAccept={handleAcceptConsent} onDecline={handleDeclineConsent} />}
<div className="relative flex h-full w-full">
<LeftSidebar items={sidebarItems} activeView={state.activeView} onNavigate={handleViewChange} />
<div className="flex-1 flex min-w-0">
<div className="flex-1 flex flex-col min-w-0">
<main className="relative flex-1 min-w-0 bg-surface/50 overflow-y-auto">
<ErrorBoundary>
<Suspense fallback={<LoadingIndicator />}>
<div key={activeView} className="fade-in w-full h-full">
<ActiveComponent {...viewProps} />
</div>
</Suspense>
</ErrorBoundary>
<DownloadManager />
</main>
<StatusBar bgImageStatus="loaded" />
</div>
</div>
<CommandPalette isOpen={isCommandPaletteOpen} onClose={() => setCommandPaletteOpen(false)} onSelect={handleViewChange} />
</div>
</div>
);
};
export default App; |