-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (274 loc) · 11.9 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Events Terminal</title>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@media screen and (-webkit-min-device-pixel-ratio: 0) {
select, textarea, input {
font-size: 16px !important;
}
}
.terminal-body {
height: 24rem;
overflow-y: auto;
padding: 1rem;
scroll-behavior: smooth;
-webkit-text-size-adjust: 100%;
}
.terminal-body::-webkit-scrollbar {
width: 8px;
}
.terminal-body::-webkit-scrollbar-track {
background: transparent;
}
.terminal-body::-webkit-scrollbar-thumb {
background: rgb(75, 85, 99);
border-radius: 4px;
}
.terminal-input {
caret-color: white;
background: transparent !important;
border: none !important;
outline: none !important;
box-shadow: none !important;
color: rgb(229, 231, 235) !important;
width: 100%;
font-size: 16px !important;
touch-action: manipulation;
}
.terminal-input:focus {
outline: none !important;
border: none !important;
box-shadow: none !important;
zoom: 100% !important;
}
.animated-emoji {
display: inline-block;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const Terminal = () => {
const [logs, setLogs] = React.useState(['Welcome to Events Logger v1.0.0', 'Type "help" for available commands']);
const [command, setCommand] = React.useState('');
const [events, setEvents] = React.useState([]);
const [loading, setLoading] = React.useState(true);
const terminalRef = React.useRef(null);
React.useEffect(() => {
const loadEvents = async () => {
setLoading(true);
try {
const content = await window.fs.readFile('/files/events.json', { encoding: 'utf8' });
const data = JSON.parse(content);
const allEvents = data.events.flatMap(category =>
category.events.map(event => ({
...event,
category: category.category
}))
);
setEvents(allEvents);
setLogs(prev => [...prev, `Loaded ${allEvents.length} events from database`]);
} catch (error) {
console.error('Error loading events:', error);
setLogs(prev => [...prev, 'Error: Failed to load events database']);
} finally {
setLoading(false);
}
};
loadEvents();
}, []);
React.useEffect(() => {
if (terminalRef.current) {
terminalRef.current.scrollTop = terminalRef.current.scrollHeight;
}
}, [logs]);
const formatEvent = (event) => {
const emojiSpan = event.animated ?
`<span class="animated-emoji">${event.emoji}</span>` :
event.emoji;
return `${event.date} - ${event.name} ${emojiSpan}: ${event.description}`;
};
// Rest of the terminal code remains the same...
const handleCommand = (input) => {
if (loading) {
setLogs(prev => [...prev, 'Please wait, loading events database...']);
return;
}
const cmd = input.trim().toLowerCase();
if (cmd === 'help') {
setLogs(prev => [...prev,
'Available commands:',
' help - Show this help message',
' clear - Clear the terminal',
' types - List all event types',
' categories - List all event categories',
' list <type> - List all events of a specific type',
' cat <category> - List events in a category',
' search <term> - Search events by name or description',
'',
'Examples:',
' list crypto - Show all crypto events',
' cat "Crypto Events" - Show events in Crypto category',
' search bitcoin - Search for Bitcoin-related events'
]);
return;
}
if (cmd === 'clear') {
setLogs([]);
return;
}
if (cmd === 'types') {
const types = [...new Set(events.map(event => event.type))].sort();
setLogs(prev => [
...prev,
'Available event types:',
...types.map(type => ` ${type}`)
]);
return;
}
if (cmd === 'categories') {
const categories = [...new Set(events.map(event => event.category))].sort();
setLogs(prev => [
...prev,
'Available categories:',
...categories.map(cat => ` ${cat}`)
]);
return;
}
if (cmd.startsWith('cat ')) {
const categoryName = input.slice(4).trim();
const categoryEvents = events.filter(event =>
event.category.toLowerCase() === categoryName.toLowerCase()
).sort((a, b) => {
const [aDay, aMonth] = a.date.split('.').map(Number);
const [bDay, bMonth] = b.date.split('.').map(Number);
return aMonth - bMonth || aDay - bDay;
});
if (categoryEvents.length > 0) {
setLogs(prev => [
...prev,
`Events in category '${categoryName}':`,
...categoryEvents.map(event => ` ${formatEvent(event)}`)
]);
} else {
setLogs(prev => [...prev, `No events found in category '${categoryName}'`]);
}
return;
}
if (cmd.startsWith('list ')) {
const type = cmd.slice(5).toLowerCase();
const filteredEvents = events.filter(event =>
event.type.toLowerCase() === type
).sort((a, b) => {
const [aDay, aMonth] = a.date.split('.').map(Number);
const [bDay, bMonth] = b.date.split('.').map(Number);
return aMonth - bMonth || aDay - bDay;
});
if (filteredEvents.length > 0) {
setLogs(prev => [
...prev,
`Events of type '${type}':`,
...filteredEvents.map(event => ` ${formatEvent(event)}`)
]);
} else {
setLogs(prev => [...prev, `No events found for type '${type}'`]);
}
return;
}
if (cmd.startsWith('search ')) {
const term = cmd.slice(7).toLowerCase();
const results = events.filter(event =>
event.name.toLowerCase().includes(term) ||
event.description.toLowerCase().includes(term)
);
if (results.length > 0) {
setLogs(prev => [
...prev,
`Found ${results.length} matching event(s):`,
...results.map(event => ` ${formatEvent(event)}`)
]);
} else {
setLogs(prev => [...prev, `No events found matching '${term}'`]);
}
return;
}
// Direct event name search
const matchingEvents = events.filter(event =>
event.name.toLowerCase().includes(cmd)
);
if (matchingEvents.length > 0) {
setLogs(prev => [
...prev,
...matchingEvents.map(event => formatEvent(event))
]);
return;
}
setLogs(prev => [...prev, `Unknown command: ${cmd}`]);
};
const handleInput = (e) => {
if (e.key === 'Enter') {
const userInput = command.trim();
if (userInput) {
setLogs(prev => [...prev, `$ ${userInput}`]);
handleCommand(userInput);
setCommand('');
}
}
};
return (
<div className="max-w-2xl mx-auto p-4">
<div className="bg-black border border-gray-600 rounded-lg overflow-hidden">
<div className="bg-gray-800 px-4 py-2 text-sm text-gray-300">
System.Events.Logger v1.0.0
</div>
<div
ref={terminalRef}
className="terminal-body bg-black text-gray-200 font-mono text-sm"
dangerouslySetInnerHTML={{
__html: logs.map(log =>
`<div class="mb-1">${log}</div>`
).join('')
}}
/>
<div className="border-t border-gray-600 p-4 flex items-center bg-black">
<span className="text-green-500 mr-2">$</span>
<input
type="text"
value={command}
onChange={(e) => setCommand(e.target.value)}
onKeyDown={handleInput}
className="terminal-input font-mono text-sm"
inputMode="text"
disabled={loading}
placeholder={loading ? 'Loading events...' : ''}
/>
</div>
</div>
</div>
);
};
const App = () => {
return (
<div className="min-h-screen bg-gray-900 py-8">
<Terminal />
</div>
);
};
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
</script>
</body>
</html>