first version of proper braindump composer

This commit is contained in:
Joren de Graaf
2026-09-07 18:01:49 +02:00
parent b129794b06
commit 5bfcf61cc8
10 changed files with 696 additions and 207 deletions
+52 -3
View File
@@ -1,18 +1,67 @@
import './styles/app.scss';
import './styles/brain-dump.scss';
import htmx from 'htmx.org';
window.htmx = htmx;
document.body.addEventListener('htmx:beforeRequest', function () {
document.getElementById('request-failed').hidden = true;
const error = document.getElementById('request-failed');
if (error) error.hidden = true;
});
document.body.addEventListener('htmx:responseError', function () {
document.getElementById('request-failed').hidden = false;
const error = document.getElementById('request-failed');
if (error) error.hidden = false;
});
document.body.addEventListener('htmx:sendError', function () {
document.getElementById('request-failed').hidden = false;
const error = document.getElementById('request-failed');
if (error) error.hidden = false;
});
function activateComposerTab(tab) {
const composer = tab.closest('.task-composer');
if (!composer) return;
composer.querySelectorAll('[role="tab"]').forEach((candidate) => {
const selected = candidate === tab;
candidate.setAttribute('aria-selected', String(selected));
candidate.tabIndex = selected ? 0 : -1;
const panel = document.getElementById(candidate.getAttribute('aria-controls'));
if (panel) panel.hidden = !selected;
});
}
document.addEventListener('click', (event) => {
const tab = event.target.closest('.task-composer [role="tab"]');
if (tab) activateComposerTab(tab);
const closeButton = event.target.closest('[data-close-brain-dump-dialog]');
if (closeButton) closeButton.closest('dialog')?.close();
});
document.addEventListener('keydown', (event) => {
const tab = event.target.closest?.('.task-composer [role="tab"]');
if (!tab || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
const tabs = [...tab.closest('[role="tablist"]').querySelectorAll('[role="tab"]')];
const currentIndex = tabs.indexOf(tab);
const nextIndex = event.key === 'Home' ? 0
: event.key === 'End' ? tabs.length - 1
: (currentIndex + (event.key === 'ArrowRight' ? 1 : -1) + tabs.length) % tabs.length;
event.preventDefault();
tabs[nextIndex].focus();
activateComposerTab(tabs[nextIndex]);
});
document.body.addEventListener('htmx:afterSwap', (event) => {
const dialog = event.detail.target?.querySelector('.brain-dump-proposal-dialog');
if (!dialog) return;
dialog.addEventListener('close', () => dialog.remove(), {once: true});
if (typeof dialog.showModal === 'function' && !dialog.open) dialog.showModal();
});
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-weather-location]');
if (!button) return;