-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.html
More file actions
392 lines (330 loc) · 13.6 KB
/
index.html
File metadata and controls
392 lines (330 loc) · 13.6 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Course Preview</title>
<style>
:root {
--bg-primary: #1e1e1e;
--bg-secondary: #252526;
--text-primary: #e0e0e0;
--text-secondary: #a0a0a0;
--border-color: #3e3e42;
--accent-color: #0e639c;
--accent-hover: #1177bb;
--button-color: #2c7ad6;
--button-hover: #3889e4;
--refresh-button: #6435c9;
--refresh-hover: #7145d9;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
margin: 0;
padding: 0;
display: grid;
grid-template-columns: 300px 1fr;
height: 100vh;
overflow: hidden;
background-color: var(--bg-primary);
color: var(--text-primary);
}
.sidebar {
background-color: var(--bg-secondary);
padding: 20px;
overflow-y: auto;
border-right: 1px solid var(--border-color);
}
.content {
overflow: hidden;
display: flex;
flex-direction: column;
background-color: var(--bg-primary);
}
h1 {
font-size: 20px;
margin-top: 0;
margin-bottom: 20px;
color: var(--text-primary);
}
h2 {
font-size: 16px;
margin-top: 20px;
margin-bottom: 10px;
color: var(--text-primary);
}
select {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border-radius: 4px;
border: 1px solid var(--border-color);
background-color: var(--bg-primary);
color: var(--text-primary);
}
select option {
background-color: var(--bg-primary);
color: var(--text-primary);
}
label {
color: var(--text-secondary);
display: block;
margin-bottom: 5px;
}
.iframe-container {
flex-grow: 1;
position: relative;
overflow: hidden;
background-color: var(--bg-primary);
}
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
background-color: var(--bg-primary);
}
.loading {
display: flex;
justify-content: center;
align-items: center;
height: 100px;
font-style: italic;
color: var(--text-secondary);
}
button {
background-color: var(--button-color);
color: var(--text-primary);
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-bottom: 15px;
}
button:hover {
background-color: var(--button-hover);
}
.refresh-button {
background-color: var(--refresh-button);
}
.refresh-button:hover {
background-color: var(--refresh-hover);
}
#current-selection {
padding: 10px;
border-radius: 4px;
background-color: var(--bg-primary);
color: var(--text-primary);
white-space: pre-line;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="sidebar">
<h1>Course Navigator</h1>
<div>
<label for="project-select">Select Project:</label>
<select id="project-select">
<option value="">Loading projects...</option>
</select>
</div>
<div>
<label for="stage-select">Select Stage:</label>
<select id="stage-select">
<option value="">First select a project</option>
</select>
</div>
<button id="refresh-button" class="refresh-button">Refresh File List</button>
<div>
<h2>Current Selection:</h2>
<div id="current-selection">None selected</div>
</div>
</div>
<div class="content">
<div class="iframe-container">
<iframe id="preview-iframe" src="https://enlightby.ai/preview"></iframe>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const projectSelect = document.getElementById('project-select');
const stageSelect = document.getElementById('stage-select');
const refreshButton = document.getElementById('refresh-button');
const currentSelection = document.getElementById('current-selection');
const previewIframe = document.getElementById('preview-iframe');
let projects = [];
let hashLoaded = false;
// Setup iframe onload handler
previewIframe.onload = function() {
setTimeout(() => {
loadPreview();
}, 1000);
};
// Update URL hash
function updateHash(projectIndex, stageIndex) {
if (projectIndex !== undefined && stageIndex !== undefined) {
window.location.hash = `project=${projectIndex}&stage=${stageIndex}`;
} else if (projectIndex !== undefined) {
window.location.hash = `project=${projectIndex}`;
} else {
window.location.hash = '';
}
}
// Parse URL hash
function parseHash() {
if (!window.location.hash) return {};
const hash = window.location.hash.substring(1);
const params = {};
hash.split('&').forEach(part => {
const [key, value] = part.split('=');
if (key && value) {
params[key] = value;
}
});
return params;
}
// Restore state from hash
async function restoreFromHash() {
const params = parseHash();
if (params.project) {
const projectIndex = params.project;
// Wait for projects to be loaded
if (projects.length === 0) {
// Projects not loaded yet, wait for them
return false;
}
// Set project select
if (projectIndex >= 0 && projectIndex < projects.length) {
projectSelect.value = projectIndex;
// Populate stage select
populateStageSelect(projectIndex);
// Set stage if available
if (params.stage) {
const stageIndex = params.stage;
const stages = projects[projectIndex].stages;
if (stageIndex >= 0 && stageIndex < stages.length) {
stageSelect.value = stageIndex;
loadPreview();
return true;
}
} else {
// Auto-select first stage if no stage in hash
stageSelect.value = "0";
loadPreview();
return true;
}
}
}
return false;
}
// Populate stage select
function populateStageSelect(projectIndex) {
stageSelect.innerHTML = '';
if (!projectIndex) {
stageSelect.innerHTML = '<option value="">First select a project</option>';
return;
}
const stages = projects[projectIndex].stages;
if (stages.length === 0) {
stageSelect.innerHTML = '<option value="">No stages found</option>';
} else {
stages.forEach((stage, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = `${stage.order}. ${stage.title}`;
stageSelect.appendChild(option);
});
}
}
// Fetch projects and stages
async function fetchProjects() {
try {
const response = await fetch('/api/files');
projects = await response.json();
// Clear and populate project select
projectSelect.innerHTML = '';
if (projects.length === 0) {
projectSelect.innerHTML = '<option value="">No projects found</option>';
} else {
projectSelect.innerHTML = '<option value="">Select a project</option>';
projects.forEach((project, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = project.name;
projectSelect.appendChild(option);
});
// Try to restore from hash after projects are loaded
if (!hashLoaded) {
hashLoaded = await restoreFromHash();
}
}
} catch (error) {
console.error('Error fetching projects:', error);
projectSelect.innerHTML = '<option value="">Error loading projects</option>';
}
}
// Load preview based on selected project and stage
async function loadPreview() {
const projectIndex = projectSelect.value;
const stageIndex = stageSelect.value;
if (!projectIndex || !stageIndex) {
return;
}
// Update hash
updateHash(projectIndex, stageIndex);
const project = projects[projectIndex];
const stage = project.stages[stageIndex];
// Update current selection
currentSelection.textContent = `Project: ${project.name}\nStage: ${stage.stage}`;
try {
// Fetch the actual HTML content using the API
const response = await fetch(`/api/content?path=${encodeURIComponent(stage.path)}`);
if (!response.ok) {
throw new Error(`Failed to fetch content: ${response.statusText}`);
}
const htmlContent = await response.text();
// Store the content in the iframe's dataset
previewIframe.dataset.content = htmlContent;
// If the iframe is already loaded, send a message immediately
if (previewIframe.contentWindow) {
previewIframe.contentWindow.postMessage({
type: 'update-content',
content: htmlContent
}, '*');
}
} catch (error) {
console.error('Error loading HTML content:', error);
}
}
// Update stages when project changes
projectSelect.addEventListener('change', function() {
const projectIndex = this.value;
// Update hash with just project
updateHash(projectIndex);
// Populate stage select
populateStageSelect(projectIndex);
if (projectIndex && projects[projectIndex].stages.length > 0) {
// Automatically select the first stage
stageSelect.value = "0";
// Trigger the loadPreview function to load content
loadPreview();
}
});
// Load preview when stage is selected
stageSelect.addEventListener('change', loadPreview);
// Refresh file list button
refreshButton.addEventListener('click', fetchProjects);
// Handle hash change
window.addEventListener('hashchange', function() {
restoreFromHash();
});
// Initial fetch
fetchProjects();
});
</script>
</body>
</html>