diff options
Diffstat (limited to 'static/modules/assistant.js')
| -rw-r--r-- | static/modules/assistant.js | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/static/modules/assistant.js b/static/modules/assistant.js index 3213aa6..e47fe4b 100644 --- a/static/modules/assistant.js +++ b/static/modules/assistant.js @@ -150,6 +150,11 @@ function renderPicking(box, st, el) { box.append(cancel); } +const KIND_LABELS = { + pdf: "PDF", text: "Text", code: "Code", image: "Images", video: "Video", + archive: "Archives", many: "Several files", any: "Any file", +}; + // The presets and ops, in an overlay opened from the header, so the // transcript keeps the screen. function renderStrip(strip, st, el) { @@ -174,20 +179,31 @@ function renderStrip(strip, st, el) { head.firstElementChild.textContent = title; head.lastElementChild.textContent = hint; strip.append(head); - const row = document.createElement("div"); - row.className = `as-row ${kind}`; - for (const item of items) { - const b = document.createElement("button"); - b.className = "as-tile"; - b.title = item.prompt ?? item.label; - b.setAttribute("aria-label", item.label); - b.innerHTML = `<i class="nf"></i><span></span>`; - b.querySelector("i").textContent = item.icon || G.fallback; - b.querySelector("span").textContent = item.label; - b.onclick = () => { strip.hidden = true; act(el, "pick", { [kind]: item.label }); }; - row.append(b); + // One group per kind of file; an item taking several kinds is in each. + const groups = new Map(Object.keys(KIND_LABELS).map((k) => [k, []])); + for (const item of items) for (const k of item.kinds ?? ["any"]) { + if (!groups.has(k)) groups.set(k, []); + groups.get(k).push(item); + } + for (const [k, list] of groups) { + if (!list.length) continue; + const group = document.createElement("div"); + group.className = `as-group ${kind}`; + group.innerHTML = `<small></small><div class="as-tiles"></div>`; + group.firstElementChild.textContent = KIND_LABELS[k] ?? k; + for (const item of list) { + const b = document.createElement("button"); + b.className = "as-tile"; + b.title = item.prompt ?? item.label; + b.setAttribute("aria-label", item.label); + b.innerHTML = `<i class="nf"></i><span></span>`; + b.querySelector("i").textContent = item.icon || G.fallback; + b.querySelector("span").textContent = item.label; + b.onclick = () => { strip.hidden = true; act(el, "pick", { [kind]: item.label }); }; + group.lastElementChild.append(b); + } + strip.append(group); } - strip.append(row); } } |
