Spaces:
Running
Running
File size: 9,962 Bytes
e937b05 5c86297 8800c81 5c86297 e937b05 5c86297 f0175ec 5c86297 664a5eb aa1fcca 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 e937b05 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 8800c81 664a5eb 5c86297 b53e6f3 8800c81 5c86297 8800c81 5c86297 8800c81 5c86297 b53e6f3 5c86297 664a5eb 5c86297 e937b05 5c86297 e937b05 5c86297 e937b05 5c86297 8800c81 | 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | import React, { useState, useEffect } from 'react';
import {
useFloating,
offset,
flip,
shift,
autoUpdate,
useDismiss,
useRole,
useInteractions,
FloatingPortal,
} from '@floating-ui/react';
import type { WindowsMap, WindowId } from '../../types/windowTypes';
import { useOSStore } from '../../stores/useOSStore';
import { useProcessStore } from '../../stores/useProcessStore';
import { TaskbarWindowItem } from './TaskbarWindowItem';
import { SystemTrayProcessFlyout } from './SystemTrayProcessFlyout';
import { DesktopStartMenu } from './DesktopStartMenu';
import { isOfflineOrUnreachable } from '../../firebaseClient';
interface TaskbarItemDef {
id: WindowId;
title: string;
shortTitle: string;
icon: string;
color?: string;
}
const TASKBAR_ITEMS: TaskbarItemDef[] = [
{ id: 'queue', title: 'Daily Queue', shortTitle: 'Queue', icon: 'view_list' },
{ id: 'cardManager', title: 'Card Manager', shortTitle: 'Cards', icon: 'style', color: '#0284c7' },
{ id: 'journey', title: 'Journey Path', shortTitle: 'Journey', icon: 'route' },
{ id: 'terminal', title: 'Terminal', shortTitle: 'Terminal', icon: 'terminal' },
{ id: 'sync', title: 'Drive Sync', shortTitle: 'Sync', icon: 'cloud_sync' },
{ id: 'computer', title: 'My Computer', shortTitle: 'Comp', icon: 'desktop_windows' },
{ id: 'createProblem', title: 'Create Problem', shortTitle: 'New File', icon: 'note_add' },
{ id: 'editProblem', title: 'Edit Problem', shortTitle: 'Edit', icon: 'edit_note', color: '#059669' },
{ id: 'python', title: 'Python Challenge', shortTitle: 'Python', icon: 'sports_esports' },
{ id: 'mysql', title: 'MySQL Playground', shortTitle: 'SQL', icon: 'database' },
{ id: 'companion', title: 'Auri', shortTitle: 'Auri', icon: 'castle', color: '#d97706' },
{ id: 'store', title: "Store", shortTitle: 'Store', icon: 'storefront', color: '#d97706' },
{ id: 'settings', title: 'API Config', shortTitle: 'API', icon: 'key', color: '#10b981' },
];
interface DesktopTaskbarProps {
isStartOpen?: boolean;
onToggleStart?: () => void;
onCloseStart?: () => void;
isMobile: boolean;
windows?: WindowsMap;
activeWindow?: string;
onToggleWindow?: (id: WindowId | string) => void;
time: string;
onOpenWindow?: (id: string) => void;
onTriggerSync?: () => void;
onSignOut?: () => void;
}
export const DesktopTaskbar: React.FC<DesktopTaskbarProps> = ({
isStartOpen: propsIsStartOpen,
onToggleStart,
onCloseStart,
isMobile,
windows: propsWindows,
activeWindow: propsActiveWindow,
onToggleWindow: propsOnToggleWindow,
time,
onOpenWindow,
onTriggerSync,
onSignOut,
}) => {
const storeWindows = useOSStore(s => s.windows);
const storeActiveWindow = useOSStore(s => s.activeWindow);
const storeToggle = useOSStore(s => s.toggleWindowMinimize);
const storeOpenWindow = useOSStore(s => s.openWindow);
const processes = useProcessStore(s => s.processes);
const activeProcesses = React.useMemo(
() => Object.values(processes).filter(p => p.status === 'running'),
[processes]
);
const windows = propsWindows ?? storeWindows;
const activeWindow = propsActiveWindow ?? storeActiveWindow;
const onToggleWindow = propsOnToggleWindow ?? storeToggle;
// Reactive network connectivity state
const [isOffline, setIsOffline] = useState(() => isOfflineOrUnreachable());
useEffect(() => {
const handleOnline = () => setIsOffline(false);
const handleOffline = () => setIsOffline(true);
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
}, []);
// Start menu floating state
const [internalStartOpen, setInternalStartOpen] = useState(false);
const isStartOpen = propsIsStartOpen ?? internalStartOpen;
const handleCloseStart = () => {
if (onCloseStart) onCloseStart();
setInternalStartOpen(false);
};
const handleToggleStart = () => {
if (isStartOpen) {
handleCloseStart();
} else {
if (onToggleStart) onToggleStart();
setInternalStartOpen(true);
}
};
const {
refs: { setReference: setStartReference, setFloating: setStartFloating },
floatingStyles: startFloatingStyles,
context: startContext,
} = useFloating({
open: isStartOpen,
onOpenChange: (open) => {
if (!open) handleCloseStart();
},
placement: 'top-start',
middleware: [
offset(10),
flip({ padding: 8 }),
shift({ padding: 8 }),
],
whileElementsMounted: autoUpdate,
});
const startDismiss = useDismiss(startContext, { outsidePress: true, escapeKey: true });
const startRole = useRole(startContext, { role: 'menu' });
const { getReferenceProps: getStartRefProps, getFloatingProps: getStartFloatingProps } =
useInteractions([startDismiss, startRole]);
// System tray process flyout state
const [isProcFlyoutOpen, setIsProcFlyoutOpen] = useState(false);
return (
<div
onClick={handleCloseStart}
className="fixed bottom-0 left-0 w-full z-50 flex items-center justify-between h-14 border-t-[4px] border-ink-black bg-[#0ea5e9] px-0 select-none shadow-[0_-4px_0_0_rgba(30,41,59,0.1)]"
>
<div className="flex items-center h-full overflow-x-auto custom-scrollbar">
{/* Start button anchored with @floating-ui/react */}
<button
ref={setStartReference}
{...getStartRefProps()}
onClick={(e) => {
e.stopPropagation();
handleToggleStart();
}}
className={`h-full ${isMobile ? 'px-3' : 'px-6'
} flex items-center gap-2 border-r-[4px] border-ink-black bg-[#39ff14] text-ink-black hover:bg-[#28e007] active:bg-[#1fb304] transition-colors shadow-[inset_-3px_-3px_0px_rgba(0,0,0,0.2),inset_3px_3px_0px_rgba(255,255,255,0.5)] font-bold cursor-pointer`}
title="Start Menu"
aria-label="Start Menu"
>
<span className="material-symbols-outlined text-2xl font-bold" style={{ fontVariationSettings: "'FILL' 1" }}>
sports_esports
</span>
<span className={`font-display-lg ${isMobile ? 'text-sm' : 'text-lg'} italic tracking-wide`}>Start</span>
</button>
{/* Start Menu Floating Overlay */}
{isStartOpen && (
<FloatingPortal>
<DesktopStartMenu
ref={setStartFloating}
style={startFloatingStyles}
{...getStartFloatingProps()}
isOpen={isStartOpen}
onOpenWindow={(id) => {
handleCloseStart();
if (onOpenWindow) onOpenWindow(id);
else storeOpenWindow(id);
}}
onTriggerSync={() => {
handleCloseStart();
onTriggerSync?.();
}}
onSignOut={() => {
handleCloseStart();
onSignOut?.();
}}
/>
</FloatingPortal>
)}
{/* Windows tabs with @floating-ui/react hover previews */}
{TASKBAR_ITEMS.map((item) => {
const win = windows[item.id];
if (!win?.isOpen) return null;
return (
<TaskbarWindowItem
key={item.id}
id={item.id}
title={item.title}
shortTitle={item.shortTitle}
icon={item.icon}
color={item.color}
isOpen={win.isOpen}
isMinimized={win.isMinimized}
isActive={activeWindow === item.id}
isMobile={isMobile}
onToggle={onToggleWindow}
/>
);
})}
</div>
{/* System tray (process status, wifi, clock, volume) */}
<div className="flex items-center h-full border-l-[4px] border-ink-black bg-[#0369a1] text-white px-3 md:px-4 gap-3 md:gap-4 shadow-[inset_3px_3px_0px_rgba(0,0,0,0.2)]">
{/* Process Monitor badge with @floating-ui flyout */}
<SystemTrayProcessFlyout
isOpen={isProcFlyoutOpen}
onOpenChange={setIsProcFlyoutOpen}
>
{(ref, props) => (
activeProcesses.length > 0 ? (
<div
ref={ref}
{...props}
onClick={(e) => {
e.stopPropagation();
setIsProcFlyoutOpen(prev => !prev);
}}
title={`Active background processes: ${activeProcesses.map(p => p.title).join(', ')} (click to inspect)`}
className="flex items-center gap-1.5 bg-[#facc15] text-ink-black px-2 py-0.5 border-2 border-ink-black font-arcade text-[8px] font-bold shadow-[1px_1px_0px_0px_#1E293B] animate-pulse select-none cursor-pointer hover:bg-yellow-300"
>
<span className="material-symbols-outlined text-[12px] animate-spin">autorenew</span>
<span>{activeProcesses.length} PROC</span>
</div>
) : null
)}
</SystemTrayProcessFlyout>
<span
className="material-symbols-outlined cursor-pointer select-none text-lg hover:text-cyan-200 transition-colors"
title="Sound: ON"
>
volume_up
</span>
<span
className={`material-symbols-outlined cursor-pointer select-none text-lg transition-colors ${isOffline ? 'text-orange-300 animate-pulse' : 'hover:text-cyan-200'
}`}
title={isOffline ? 'Offline (Reconnecting...)' : 'Online'}
>
{isOffline ? 'wifi_off' : 'network_wifi'}
</span>
<div
className="font-arcade text-[9px] font-bold flex flex-col items-center leading-none justify-center select-none pt-0.5 cursor-default"
title="System Time"
>
<span>{time}</span>
</div>
</div>
</div>
);
};
|