|
220 | 220 | const GITHUB_RAW_BASE = isLocal |
221 | 221 | ? '../workshop/' |
222 | 222 | : 'https://raw.githubusercontent.com/copilot-dev-days/agent-lab-python/main/workshop/'; |
| 223 | + const CHECKBOX_STORAGE_KEY = 'agent-lab-checkboxes-v1'; |
| 224 | + let checkboxSaveTimeout; |
223 | 225 |
|
224 | 226 | // Get current step from URL |
225 | 227 | function getCurrentStepId() { |
|
232 | 234 | return steps.findIndex(s => s.id === stepId); |
233 | 235 | } |
234 | 236 |
|
| 237 | + function readCheckboxState() { |
| 238 | + try { |
| 239 | + return JSON.parse(localStorage.getItem(CHECKBOX_STORAGE_KEY) || '{}'); |
| 240 | + } catch { |
| 241 | + return {}; |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + function writeCheckboxState(state) { |
| 246 | + try { |
| 247 | + localStorage.setItem(CHECKBOX_STORAGE_KEY, JSON.stringify(state)); |
| 248 | + } catch { |
| 249 | + // Ignore storage failures (private mode / blocked storage) |
| 250 | + } |
| 251 | + } |
| 252 | + |
| 253 | + function writeCheckboxStateDebounced(state) { |
| 254 | + clearTimeout(checkboxSaveTimeout); |
| 255 | + checkboxSaveTimeout = setTimeout(() => writeCheckboxState(state), 100); |
| 256 | + } |
| 257 | + |
| 258 | + function initializeTaskListCheckboxes(stepId) { |
| 259 | + const container = document.getElementById('markdown-content'); |
| 260 | + if (!container) return; |
| 261 | + const checkboxes = container.querySelectorAll('input[type="checkbox"]'); |
| 262 | + if (checkboxes.length === 0) return; |
| 263 | + |
| 264 | + const allState = readCheckboxState(); |
| 265 | + if (!Array.isArray(allState[stepId])) { |
| 266 | + allState[stepId] = []; |
| 267 | + } |
| 268 | + const stepState = allState[stepId]; |
| 269 | + |
| 270 | + checkboxes.forEach((checkbox, index) => { |
| 271 | + checkbox.disabled = false; |
| 272 | + |
| 273 | + if (typeof stepState[index] === 'boolean') { |
| 274 | + checkbox.checked = stepState[index]; |
| 275 | + } |
| 276 | + |
| 277 | + checkbox.addEventListener('change', () => { |
| 278 | + stepState[index] = checkbox.checked; |
| 279 | + allState[stepId] = stepState; |
| 280 | + writeCheckboxStateDebounced(allState); |
| 281 | + }); |
| 282 | + }); |
| 283 | + } |
| 284 | + |
235 | 285 | // Build sidebar navigation |
236 | 286 | function buildSidebar() { |
237 | 287 | const nav = document.getElementById('stepNav'); |
|
339 | 389 | }); |
340 | 390 |
|
341 | 391 | document.getElementById('markdown-content').innerHTML = marked.parse(md); |
| 392 | + initializeTaskListCheckboxes(step.id); |
342 | 393 |
|
343 | 394 | // If this is the completion page, add confetti! |
344 | 395 | if (step.id === '05-complete') { |
|
0 commit comments