-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConspiracyBoardPage.jsx
More file actions
376 lines (353 loc) · 13 KB
/
ConspiracyBoardPage.jsx
File metadata and controls
376 lines (353 loc) · 13 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import React, { useState, useRef } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { Link } from 'react-router-dom';
import {
ArrowLeftIcon,
PushPinIcon,
TrashIcon,
LinkBreakIcon,
CameraIcon,
NotePencilIcon,
TextTIcon,
DownloadSimpleIcon,
} from '@phosphor-icons/react';
import domtoimage from 'dom-to-image-more';
import Seo from '../../components/Seo';
import GenerativeArt from '../../components/GenerativeArt';
import BreadcrumbTitle from '../../components/BreadcrumbTitle';
const BOARD_TEXTURE = `radial-gradient(#d2a679 1px, transparent 1px), radial-gradient(#d2a679 1px, transparent 1px)`;
const ConspiracyBoardPage = () => {
const [items, setItems] = useState([
{
id: 'header-note',
type: 'header',
text: 'PROJECT: UNVEILING THE HIDDEN ARCHITECTURE',
x: 200,
y: 40,
rotation: -2,
},
{
id: '1',
type: 'note',
text: 'THEY ARE WATCHING',
x: 100,
y: 150,
color: '#fff9c4',
rotation: -5,
},
{ id: '2', type: 'polaroid', src: '', x: 400, y: 100, rotation: 10 },
{
id: '3',
type: 'note',
text: 'FOLLOW THE WHITE RABBIT',
x: 250,
y: 400,
color: '#ffccbc',
rotation: 2,
},
]);
const [connections, setConnections] = useState([
{ from: '1', to: '2' },
{ from: '2', to: '3' },
]);
const [linkingFrom, setLinkingFrom] = useState(null);
const [draggingId, setDraggingId] = useState(null);
const dragOffset = useRef({ x: 0, y: 0 });
const fileInputRef = useRef(null);
const boardRef = useRef(null);
const downloadBoard = async () => {
if (boardRef.current) {
const buttons = boardRef.current.querySelectorAll('.item-actions');
const toolbar = boardRef.current.querySelector('.toolbar');
const ambientText = boardRef.current.querySelector('.ambient-text');
buttons.forEach((b) => (b.style.display = 'none'));
if (toolbar) toolbar.style.display = 'none';
if (ambientText) ambientText.style.display = 'none';
try {
const dataUrl = await domtoimage.toPng(boardRef.current, {
quality: 1,
bgcolor: '#8b5e3c',
width: boardRef.current.scrollWidth,
height: boardRef.current.scrollHeight,
});
const link = document.createElement('a');
link.download = `conspiracy-${Date.now()}.png`;
link.href = dataUrl;
link.click();
} catch (error) {
console.error('Download failed', error);
} finally {
buttons.forEach((b) => (b.style.display = ''));
if (toolbar) toolbar.style.display = '';
if (ambientText) ambientText.style.display = '';
}
}
};
const handlePointerDown = (e, item) => {
if (e.target.closest('button') || e.target.tagName === 'TEXTAREA') return;
e.preventDefault();
setDraggingId(item.id);
dragOffset.current = { x: e.clientX - item.x, y: e.clientY - item.y };
};
const handlePointerMove = (e) => {
if (draggingId) {
setItems((prev) =>
prev.map((item) =>
item.id === draggingId
? {
...item,
x: e.clientX - dragOffset.current.x,
y: e.clientY - dragOffset.current.y,
}
: item,
),
);
}
};
const handlePointerUp = () => setDraggingId(null);
const handleImageUpload = (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (event) => addItem('polaroid', event.target.result);
reader.readAsDataURL(file);
}
e.target.value = null;
};
const addItem = (type, imgSrc = null) => {
const newItem = {
id: Date.now().toString(),
type: type,
text:
type === 'note'
? 'New Evidence...'
: type === 'header'
? 'TOP SECRET'
: '',
src: imgSrc || '',
x: Math.random() * 400 + 50,
y: Math.random() * 300 + 50,
color: ['#fff9c4', '#ffccbc', '#c8e6c9', '#bbdefb'][
Math.floor(Math.random() * 4)
],
rotation: (Math.random() - 0.5) * 20,
};
setItems([...items, newItem]);
};
const deleteItem = (id) => {
setItems(items.filter((i) => i.id !== id));
setConnections(connections.filter((c) => c.from !== id && c.to !== id));
};
const toggleLink = (id) => {
if (!linkingFrom) {
setLinkingFrom(id);
} else if (linkingFrom === id) {
setLinkingFrom(null);
} else {
const exists = connections.find(
(c) =>
(c.from === linkingFrom && c.to === id) ||
(c.from === id && c.to === linkingFrom),
);
if (exists) {
setConnections(connections.filter((c) => c !== exists));
} else {
setConnections([...connections, { from: linkingFrom, to: id }]);
}
setLinkingFrom(null);
}
};
return (
<div
ref={boardRef}
className="min-h-screen relative overflow-hidden bg-[#8b5e3c] cursor-crosshair"
style={{
backgroundImage: BOARD_TEXTURE,
backgroundSize: '40px 40px',
backgroundPosition: '0 0, 20px 20px',
}}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerLeave={handlePointerUp}
>
<Seo
title="The Conspiracy Board | Fezcodex"
description="Connect the dots, find the truth. A digital corkboard for your wildest theories."
keywords={[
'conspiracy',
'detective',
'board',
'mindmap',
'red string',
'theory',
]}
/>
<div className="absolute inset-0 bg-black/10 pointer-events-none shadow-inner" />
<div className="toolbar absolute top-6 left-6 z-50 flex gap-4 pointer-events-auto transition-opacity duration-300">
<Link
to="/apps"
className="bg-[#5d4037] text-[#efebe9] px-6 py-3 font-mono border-2 border-[#3e2723] shadow-[4px_4px_0px_#3e2723] hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none transition-all flex items-center gap-2"
>
<ArrowLeftIcon weight="bold" />
<span>EXIT BOARD</span>
</Link>
<button
onClick={() => addItem('note')}
className="bg-[#fff9c4] text-[#3e2723] p-3 border-2 border-[#3e2723] shadow-[4px_4px_0px_#3e2723] hover:scale-105 transition-transform"
>
<NotePencilIcon size={24} weight="bold" />
</button>
<button
onClick={() => addItem('header')}
className="bg-[#efebe9] text-[#3e2723] p-3 border-2 border-[#3e2723] shadow-[4px_4px_0px_#3e2723] hover:scale-105 transition-transform"
>
<TextTIcon size={24} weight="bold" />
</button>
<button
onClick={() => fileInputRef.current.click()}
className="bg-white text-[#3e2723] p-3 border-2 border-[#3e2723] shadow-[4px_4px_0px_#3e2723] hover:scale-105 transition-transform"
>
<CameraIcon size={24} weight="bold" />
</button>
<button
onClick={downloadBoard}
className="bg-blue-100 text-[#3e2723] p-3 border-2 border-[#3e2723] shadow-[4px_4px_0px_#3e2723] hover:scale-105 transition-transform"
>
<DownloadSimpleIcon size={24} weight="bold" />
</button>
<input
type="file"
ref={fileInputRef}
onChange={handleImageUpload}
accept="image/*"
className="hidden"
/>
</div>
<svg className="absolute inset-0 w-full h-full pointer-events-none z-10 overflow-visible">
{connections.map((conn) => {
const from = items.find((it) => it.id === conn.from);
const to = items.find((it) => it.id === conn.to);
if (!from || !to) return null;
const fromX =
from.x +
(from.type === 'note' ? 96 : from.type === 'header' ? 300 : 112);
const toX =
to.x + (to.type === 'note' ? 96 : to.type === 'header' ? 300 : 112);
return (
<motion.line
key={`${conn.from}-${conn.to}`}
x1={fromX}
y1={from.y + 5}
x2={toX}
y2={to.y + 5}
stroke="#d32f2f"
strokeWidth="3"
strokeLinecap="round"
initial={{ pathLength: 0, opacity: 0 }}
animate={{ pathLength: 1, opacity: 0.8 }}
style={{ filter: 'drop-shadow(2px 2px 2px rgba(0,0,0,0.5))' }}
/>
);
})}
</svg>
<div className="absolute inset-0 w-full h-full">
<AnimatePresence>
{items.map((item) => (
<motion.div
key={item.id}
initial={{ scale: 0, rotate: item.rotation - 20 }}
animate={{ scale: 1, rotate: item.rotation }}
exit={{ scale: 0, opacity: 0 }}
onPointerDown={(e) => handlePointerDown(e, item)}
className={`absolute cursor-grab active:cursor-grabbing shadow-2xl select-none z-20 ${
item.type === 'note'
? 'w-48 bg-transparent'
: item.type === 'header'
? 'w-[600px] bg-[#efebe9]'
: 'w-56 bg-white'
} ${linkingFrom === item.id ? 'ring-4 ring-red-500' : ''}`}
style={{
left: item.x,
top: item.y,
backgroundColor: item.type === 'note' ? item.color : undefined,
zIndex: draggingId === item.id ? 50 : 20,
}}
>
<div className="absolute -top-3 left-1/2 -translate-x-1/2 text-red-600 drop-shadow-md z-30 pointer-events-none">
<PushPinIcon weight="fill" size={32} />
</div>
{item.type === 'header' ? (
<div className="py-4 px-4 border-b-4 border-double border-[#3e2723]">
<textarea
className="bg-transparent border-none outline-none w-full text-4xl font-playfairDisplay font-black text-[#3e2723] leading-tight text-center resize-none overflow-hidden"
defaultValue={item.text}
rows={2}
onChange={(e) => {
item.text = e.target.value;
}}
/>
</div>
) : item.type === 'note' ? (
<div className="p-6">
<textarea
className="bg-transparent border-none outline-none w-full h-24 text-[#3e2723] font-arvo font-bold text-lg resize-none"
defaultValue={item.text}
onChange={(e) => {
item.text = e.target.value;
}}
/>
</div>
) : (
<div className="p-4 pb-10">
<div className="aspect-square bg-gray-200 overflow-hidden mb-4 border border-gray-100 relative">
{item.src ? (
<img
src={item.src}
alt="Evidence"
className="w-full h-full object-cover grayscale sepia contrast-125"
draggable={false}
/>
) : (
<GenerativeArt
seed={item.id}
className="w-full h-full grayscale sepia contrast-125"
/>
)}
<div className="absolute inset-0 bg-[#3e2723] mix-blend-overlay opacity-20 pointer-events-none" />
</div>
<p className="font-mono text-[10px] text-gray-400 text-center uppercase tracking-widest">
FILE_ID: {item.id.slice(-6)}
</p>
</div>
)}
<div className="item-actions absolute -bottom-10 left-0 right-0 flex justify-center gap-2 opacity-0 hover:opacity-100 transition-opacity">
<button
onClick={() => toggleLink(item.id)}
className={`p-2 rounded-full shadow-lg ${linkingFrom === item.id ? 'bg-red-500 text-white' : 'bg-white text-gray-800'}`}
>
<LinkBreakIcon weight="bold" />
</button>
<button
onClick={() => deleteItem(item.id)}
className="p-2 bg-white text-red-600 rounded-full shadow-lg"
>
<TrashIcon weight="bold" />
</button>
</div>
</motion.div>
))}
</AnimatePresence>
</div>
<div className="ambient-text absolute bottom-6 right-6 font-mono text-sm text-[#5d4037] opacity-50 uppercase tracking-[0.5em] pointer-events-none transition-opacity duration-300 flex flex-col items-end gap-2">
<BreadcrumbTitle
title="Conspiracy Board"
slug="cb"
variant="brutalist"
className="!text-[#5d4037]"
/>
<span>Everything is connected</span>
</div>
</div>
);
};
export default ConspiracyBoardPage;