manual submission redesign phase G

This commit is contained in:
Joren de Graaf
2026-10-06 20:04:21 +02:00
parent d112028eb1
commit c0c0bd7db8
11 changed files with 206 additions and 15 deletions
+8 -7
View File
@@ -1,4 +1,5 @@
const form = document.querySelector("#manual-report-form");
const form = document.querySelector("#manual-report-form");
const t = window.BOOMCAST_I18N || {};
export function createBurstListener() {
if (!form) return null;
@@ -47,12 +48,12 @@ export function createBurstListener() {
state = next;
if (container) container.dataset.state = next;
if (section) section.dataset.state = next;
if (stateLabel) stateLabel.textContent = next === "listening" ? "Listening for the next bang" : next === "tail" ? "Sound detected" : next === "captured" ? "Sound captured" : "Not listening";
if (stateLabel) stateLabel.textContent = next === "listening" ? (t.listeningNextBang || "Listening for the next bang") : next === "tail" ? (t.soundDetected || "Sound detected") : next === "captured" ? (t.soundCaptured || "Sound captured") : (t.notListening || "Not listening");
start.hidden = next !== "off";
panel.hidden = next === "off";
resume.hidden = discard.hidden = next !== "captured";
heading.textContent = next === "captured" ? "Sound captured" : next === "tail" ? "Sound detected — finishing clip…" : "Listening for the next sound…";
detail.textContent = next === "listening" ? "Keeping the most recent ~10 seconds" : next === "captured" ? "Preview the clip or send your report." : "";
heading.textContent = next === "captured" ? (t.soundCaptured || "Sound captured") : next === "tail" ? (t.soundDetectedFinishing || "Sound detected — finishing clip…") : (t.listeningNextSound || "Listening for the next sound…");
detail.textContent = next === "listening" ? (t.keepingRecentAudio || "Keeping the most recent ~10 seconds") : next === "captured" ? (t.previewClipOrSend || "Preview the clip or send your report.") : "";
}
function wav(samples, rate) {
@@ -81,7 +82,7 @@ export function createBurstListener() {
start.disabled = true;
if (container) container.dataset.state = "starting";
if (section) section.dataset.state = "starting";
if (stateLabel) stateLabel.textContent = "Starting microphone…";
if (stateLabel) stateLabel.textContent = t.startingMicrophone || "Starting microphone…";
try {
if (!navigator.mediaDevices?.getUserMedia || !window.AudioWorkletNode) throw new Error("Microphone listening is unavailable in this browser or connection.");
stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 }, video: false });
@@ -122,8 +123,8 @@ export function createBurstListener() {
await end();
if (container) container.dataset.state = "error";
if (section) section.dataset.state = "error";
if (stateLabel) stateLabel.textContent = "Microphone unavailable";
error.textContent = cause.name === "NotAllowedError" ? "Microphone permission was denied. Manual reporting is still available." : (cause.message || "Microphone capture failed.");
if (stateLabel) stateLabel.textContent = t.microphoneUnavailable || "Microphone unavailable";
error.textContent = cause.name === "NotAllowedError" ? (t.microphoneDenied || "Microphone permission was denied. Manual reporting is still available.") : (t.microphoneFailed || "Microphone capture failed.");
error.hidden = false;
} finally {
start.disabled = false;
+4 -1
View File
@@ -25,7 +25,10 @@
const burstListener = createBurstListener();
const isUsableNumber = (value) => Number.isFinite(value);
const cardinalDirection = (heading) => ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(((heading + 22.5) % 360) / 45)];
const cardinalDirection = (heading) => [
t.north || "North", t.northeast || "Northeast", t.east || "East", t.southeast || "Southeast",
t.south || "South", t.southwest || "Southwest", t.west || "West", t.northwest || "Northwest",
][Math.floor(((heading + 22.5) % 360) / 45)];
const displayDegrees = (value) => Number(value.toFixed(1)).toString();
const updateReportTime = () => {
if (!reportTime) return;
+35 -3
View File
@@ -16,7 +16,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide
<button id="burst-stop" type="button"></button><p id="burst-error"></p>
</form>
<div id="manual-submission"></div>
<div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div>
<div id="manual-compass-home"><div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div></div>
</body></html>`, { url: "https://example.test/" });
const { window } = dom;
Object.defineProperty(window, "isSecureContext", { value: true });
@@ -24,8 +24,10 @@ test("compass stays hidden until permission and a heading, then rotates and hide
class MockOrientation {}
MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; });
window.DeviceOrientationEvent = MockOrientation;
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation })) {
let submissions = 0;
window.htmx = { ajax: () => { submissions++; } };
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent", "htmx", "DOMParser"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation, htmx: window.htmx, DOMParser: window.DOMParser })) {
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
}
try {
@@ -51,6 +53,36 @@ test("compass stays hidden until permission and a heading, then rotates and hide
assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1");
button.click();
assert.equal(compass.hidden, true);
window.document.querySelector("#manual-increase").click();
assert.equal(window.document.querySelector("#manual-occurrences").value, "2");
window.document.querySelector("#manual-decrease").click();
assert.equal(window.document.querySelector("#manual-occurrences").value, "1");
window.document.querySelector("#manual-direction-panel").outerHTML = '<div id="manual-direction-panel"><p class="manual-direction-panel__copy"></p><button id="manual-capture-direction"></button><div id="manual-direction-status"></div></div>';
const opened = window.document.querySelector("#manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: opened } }));
assert.equal(compass.parentElement.id, "manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:beforeSwap", { detail: { target: opened } }));
assert.equal(compass.parentElement.id, "manual-compass-home");
opened.outerHTML = '<div id="manual-direction-panel"><p id="manual-direction-summary">Not captured</p></div>';
const closed = window.document.querySelector("#manual-direction-panel");
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: closed } }));
assert.equal(window.document.querySelector("#manual-direction-summary").textContent, "North · 1°");
const submit = window.document.querySelector("#manual-submit");
const form = window.document.querySelector("#manual-report-form");
submit.click();
submit.click();
assert.equal(submissions, 1);
assert.equal(submit.disabled, true);
window.document.querySelector("#manual-submission").outerHTML = '<div id="manual-submission" data-result="success">Received</div>';
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 200 } } }));
assert.equal(submit.disabled, false);
submit.click();
assert.equal(submissions, 2);
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 400, responseText: '<div id="manual-submission" data-result="error">Try again</div>' } } }));
assert.equal(window.document.querySelector("#manual-submission").dataset.result, "error");
assert.equal(submit.disabled, false);
} finally {
for (const [key, descriptor] of Object.entries(previous)) {
if (descriptor === undefined) delete globalThis[key];