Spaces:
Running
Running
Download algospaced-ui/src/components/desktop/DesktopTaskbar.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 9.96 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/desktop/DesktopTaskbar.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/desktop/DesktopTaskbar.tsx
-
curl -L -o DesktopTaskbar.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/desktop/DesktopTaskbar.tsx
9.96 kB
| 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> | |
| ); | |
| }; | |