File size: 6,540 Bytes
5c86297
 
 
 
 
 
 
 
 
 
 
 
8800c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c86297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8800c81
 
5c86297
 
8800c81
5c86297
 
 
8800c81
5c86297
8800c81
 
5c86297
 
 
 
 
 
8800c81
5c86297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0175ec
 
 
 
 
 
 
 
 
 
 
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
import { useEffect, useMemo } from 'react';
import {
  useFloating,
  shift,
  flip,
  offset,
  autoUpdate,
  useDismiss,
  useRole,
  useInteractions,
  FloatingPortal,
} from '@floating-ui/react';

interface DesktopContextMenuProps {
  x: number;
  y: number;
  isOpen: boolean;
  onClose: () => void;
  onAutoArrange: () => void;
  onResetLayout: () => void;
  onChangeWallpaper: () => void;
  onOpenWindow: (id: string) => void;
  onTriggerSync: () => void;
  onToggleFullscreen: () => void;
  isFullscreen: boolean;
}

export default function DesktopContextMenu({
  x,
  y,
  isOpen,
  onClose,
  onAutoArrange,
  onResetLayout,
  onChangeWallpaper,
  onOpenWindow,
  onTriggerSync,
  onToggleFullscreen,
  isFullscreen,
}: DesktopContextMenuProps) {
  // Virtual reference element for cursor click coordinates
  const virtualReference = useMemo(
    () => ({
      getBoundingClientRect: () => ({
        x,
        y,
        top: y,
        left: x,
        bottom: y,
        right: x,
        width: 0,
        height: 0,
      }),
    }),
    [x, y]
  );

  const {
    refs: { setReference, setFloating },
    floatingStyles,
    context,
  } = useFloating({
    open: isOpen,
    onOpenChange: (open) => {
      if (!open) onClose();
    },
    placement: 'bottom-start',
    middleware: [
      offset(2),
      flip({ padding: 12 }),
      shift({ padding: 12 }),
    ],
    whileElementsMounted: autoUpdate,
  });

  useEffect(() => {
    setReference(virtualReference);
  }, [virtualReference, setReference]);

  const dismiss = useDismiss(context, { outsidePress: true, escapeKey: true });
  const role = useRole(context, { role: 'menu' });
  const { getFloatingProps } = useInteractions([dismiss, role]);

  if (!isOpen) return null;

  return (
    <FloatingPortal>
      <div
        ref={setFloating}
        style={floatingStyles}
        {...getFloatingProps()}
        className="z-[100] w-56 bg-paper-white border-[3px] border-ink-black gadget-shadow py-1.5 flex flex-col select-none text-ink-black animate-fade-in shadow-[4px_4px_0px_0px_#1E293B]"
      >
        <div className="px-3 py-1 bg-[#0ea5e9] text-white border-b-2 border-ink-black flex items-center justify-between mb-1 -mt-1.5 -mx-0">
          <span className="font-window-title text-[11px] font-bold tracking-wider uppercase">Desktop Options</span>
          <span className="material-symbols-outlined text-xs">desktop_windows</span>
        </div>

        {/* Icon Layout actions */}
        <button
          onClick={() => {
            onAutoArrange();
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#fde047] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">grid_view</span>
          Auto Arrange Icons
        </button>

        <button
          onClick={() => {
            onResetLayout();
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#fde047] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">restart_alt</span>
          Reset Icon Layout
        </button>

        <div className="h-[2px] bg-ink-black/20 my-1 mx-2" />

        {/* Wallpaper & View */}
        <button
          onClick={() => {
            onChangeWallpaper();
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#39ff14] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">wallpaper</span>
          Change Wallpaper...
        </button>

        <button
          onClick={() => {
            onToggleFullscreen();
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#39ff14] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">
            {isFullscreen ? 'fullscreen_exit' : 'fullscreen'}
          </span>
          {isFullscreen ? 'Exit Fullscreen' : 'Enter Fullscreen'}
        </button>

        <div className="h-[2px] bg-ink-black/20 my-1 mx-2" />

        {/* Quick Launchers */}
        <button
          onClick={() => {
            onOpenWindow('queue');
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#4cc9f0] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">view_list</span>
          Daily Queue
        </button>

        <button
          onClick={() => {
            onOpenWindow('cardManager');
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#38bdf8] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">style</span>
          Card Manager
        </button>

        <button
          onClick={() => {
            onOpenWindow('terminal');
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#4cc9f0] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">terminal</span>
          Terminal Emulator
        </button>

        <button
          onClick={() => {
            onOpenWindow('computer');
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#4cc9f0] hover:text-ink-black flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">folder</span>
          My Computer
        </button>

        <div className="h-[2px] bg-ink-black/20 my-1 mx-2" />

        <button
          onClick={() => {
            onTriggerSync();
            onClose();
          }}
          className="px-3 py-1.5 hover:bg-[#f72585] hover:text-white flex items-center gap-2 text-xs font-bold transition-colors text-left cursor-pointer"
        >
          <span className="material-symbols-outlined text-base">cloud_sync</span>
          Sync with Drive
        </button>
      </div>
    </FloatingPortal>
  );
}