Download task_009/solution/code/index.html from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 5.87 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_009/solution/code/index.html
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_009/solution/code/index.html
-
curl -L -o index.html https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_009/solution/code/index.html
5.87 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Multi Block Prompt Solution</title> | |
| <style> | |
| :root { --sidebar-width: 240px; --content-max-width: 900px; --sidebar-gap: 32px; } | |
| body { margin: 0; font-family: Arial, sans-serif; } | |
| .app { display: flex; gap: var(--sidebar-gap); height: 100vh; overflow: hidden; background: #f7f8fb; } | |
| [data-testid="sidebar"] { width: var(--sidebar-width); flex-shrink: 0; padding: 16px; background: #1f2937; color: white; overflow-y: auto; box-sizing: border-box; } | |
| [data-testid="sidebar"]::-webkit-scrollbar { width: 8px; } | |
| [data-testid="sidebar"]::-webkit-scrollbar-thumb { background: #64748b; border-radius: 4px; } | |
| [data-testid="content"] { flex: 1; min-width: 0; max-width: var(--content-max-width); margin: 0 auto; padding: 16px; box-sizing: border-box; overflow-y: auto; } | |
| .custom-scrollbar::-webkit-scrollbar { width: 8px; } | |
| .custom-scrollbar::-webkit-scrollbar-thumb { background: #64748b; border-radius: 4px; } | |
| @media (max-width: 600px) { .app { gap: 8px; } [data-testid="sidebar"] { width: 120px; padding: 8px; } } | |
| [data-testid="prompt-response-block"] { border: 1px solid #c5cbd5; background: white; padding: 12px; margin-bottom: 12px; border-radius: 6px; } | |
| textarea { width: 100%; min-height: 56px; box-sizing: border-box; } | |
| output { display: block; margin-top: 8px; } | |
| [data-testid="new-block-placeholder"] { display: none; padding: 10px 12px; border: 1px dashed #7c8798; background: white; } | |
| [data-testid="new-block-placeholder"].visible { display: inline-block; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="app"> | |
| <aside class="custom-scrollbar" data-testid="sidebar"><h2>Blocks</h2><ol data-testid="sidebar-list"></ol></aside> | |
| <main class="custom-scrollbar" data-testid="content"> | |
| <section data-testid="blocks"></section> | |
| <button data-testid="new-block-placeholder">New block</button> | |
| </main> | |
| </div> | |
| <script> | |
| class PromptBlock { | |
| constructor(id) { | |
| this.id = id; | |
| this.prompt = ''; | |
| this.status = 'idle'; | |
| this.requestVersion = 0; | |
| this.element = document.createElement('article'); | |
| this.element.dataset.testid = 'prompt-response-block'; | |
| this.element.dataset.blockId = id; | |
| this.element.innerHTML = '<textarea data-testid="prompt-input" placeholder="Prompt"></textarea><button data-testid="send-button">Send</button><output data-testid="response">not sent</output>'; | |
| this.input = this.element.querySelector('[data-testid="prompt-input"]'); | |
| this.response = this.element.querySelector('[data-testid="response"]'); | |
| this.element.querySelector('[data-testid="send-button"]').addEventListener('click', () => this.send()); | |
| this.input.addEventListener('input', () => { blockManager.updateBlockState(this, { prompt: this.input.value }); blockManager.renderPlaceholder(); }); | |
| } | |
| async send() { | |
| const prompt = this.input.value.trim(); | |
| if (!prompt) return; | |
| const version = this.requestVersion + 1; | |
| blockManager.updateBlockState(this, { prompt, requestVersion: version }); | |
| blockManager.transitionBlockState(this, 'loading'); | |
| this.response.textContent = 'Loading...'; | |
| try { | |
| const result = await blockManager.generate(prompt, this.id); | |
| if (version !== this.requestVersion) return; | |
| this.response.textContent = String(result); | |
| blockManager.transitionBlockState(this, 'sent'); | |
| } catch (error) { | |
| if (version !== this.requestVersion) return; | |
| this.response.textContent = `Failed: ${error.message || error}`; | |
| blockManager.transitionBlockState(this, 'error'); | |
| } | |
| } | |
| } | |
| class BlockManager { | |
| constructor() { | |
| this.blocks = []; | |
| this.listeners = new Set(); | |
| this.container = document.querySelector('[data-testid="blocks"]'); | |
| this.sidebar = document.querySelector('[data-testid="sidebar-list"]'); | |
| this.placeholder = document.querySelector('[data-testid="new-block-placeholder"]'); | |
| this.placeholder.addEventListener('click', () => this.createNewBlock(true)); | |
| this.generate = (prompt) => new Promise(resolve => | |
| setTimeout(() => resolve(`response for ${prompt}`), 40)); | |
| this.subscribe(() => { this.renderSidebar(); this.renderPlaceholder(); }); | |
| } | |
| subscribe(listener) { | |
| this.listeners.add(listener); | |
| return () => this.listeners.delete(listener); | |
| } | |
| notify() { | |
| for (const listener of this.listeners) listener(this.blocks); | |
| } | |
| updateBlockState(block, patch) { | |
| Object.assign(block, patch); | |
| this.notify(); | |
| } | |
| transitionBlockState(block, status) { | |
| this.updateBlockState(block, { status }); | |
| } | |
| createNewBlock(autoFocus = false) { | |
| return this.createBlock(autoFocus); | |
| } | |
| createBlock(autofocus = false) { | |
| const block = new PromptBlock(`block-${this.blocks.length + 1}`); | |
| this.blocks.push(block); | |
| this.container.appendChild(block.element); | |
| this.notify(); | |
| if (autofocus) block.input.focus(); | |
| return block; | |
| } | |
| renderSidebar() { | |
| this.sidebar.innerHTML = this.blocks.map(block => `<li>${block.id} ${block.status}</li>`).join(''); | |
| } | |
| renderPlaceholder() { | |
| const ready = this.blocks.length > 0 && this.blocks.every(block => ['loading', 'sent', 'error'].includes(block.status)); | |
| this.placeholder.classList.toggle('visible', ready); | |
| } | |
| } | |
| const blockManager = new BlockManager(); | |
| window.BlockManager = BlockManager; | |
| window.blockManager = blockManager; | |
| window.__setMockGenerate = (fn) => { blockManager.generate = fn; }; | |
| blockManager.createBlock(false); | |
| </script> | |
| </body> | |
| </html> | |