manual submission redesign phase C
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -23,10 +23,16 @@
|
||||
{% include "fireworks_detect/includes/manual_direction_panel.html" %}
|
||||
<button id="manual-submit" class="manual-report__submit" type="button"><span aria-hidden="true">🔥</span> {% trans "I heard fireworks" %}</button>
|
||||
</div>
|
||||
<section class="manual-report__supporting" aria-labelledby="manual-listening-title">
|
||||
<h3 id="manual-listening-title">{% trans "Automatic detection" %}</h3>
|
||||
<div class="burst-listener">
|
||||
<button id="burst-start" class="burst-listener__button" type="button">{% trans "Listen for next bang" %}</button>
|
||||
<section class="manual-report__supporting" data-state="off" aria-labelledby="manual-listening-title">
|
||||
<div class="manual-report__supporting-header">
|
||||
<span class="manual-report__microphone" aria-hidden="true">🎙</span>
|
||||
<div>
|
||||
<h3 id="manual-listening-title">{% trans "Automatic detection" %}</h3>
|
||||
<span id="burst-state" class="burst-listener__state" aria-live="polite">{% trans "Not listening" %}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="burst-listener" data-state="off">
|
||||
<button id="burst-start" class="burst-listener__button" type="button">{% trans "Start listening" %}</button>
|
||||
<div id="burst-panel" class="burst-listener__panel" hidden>
|
||||
<strong id="burst-heading" aria-live="polite"></strong>
|
||||
<canvas id="burst-waveform" width="600" height="90" aria-label="{% trans 'Live microphone waveform' %}"></canvas>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
const form = document.querySelector("#manual-report-form");
|
||||
const form = document.querySelector("#manual-report-form");
|
||||
|
||||
export function createBurstListener() {
|
||||
if (!form) return null;
|
||||
const start = document.querySelector("#burst-start");
|
||||
const container = start.closest(".burst-listener");
|
||||
const section = start.closest(".manual-report__supporting");
|
||||
const stateLabel = document.querySelector("#burst-state");
|
||||
const panel = document.querySelector("#burst-panel");
|
||||
const heading = document.querySelector("#burst-heading");
|
||||
const detail = document.querySelector("#burst-detail");
|
||||
@@ -42,6 +45,9 @@ export function createBurstListener() {
|
||||
|
||||
function setState(next) {
|
||||
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";
|
||||
start.hidden = next !== "off";
|
||||
panel.hidden = next === "off";
|
||||
resume.hidden = discard.hidden = next !== "captured";
|
||||
@@ -73,6 +79,9 @@ export function createBurstListener() {
|
||||
async function begin() {
|
||||
error.hidden = true;
|
||||
start.disabled = true;
|
||||
if (container) container.dataset.state = "starting";
|
||||
if (section) section.dataset.state = "starting";
|
||||
if (stateLabel) stateLabel.textContent = "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 });
|
||||
@@ -111,6 +120,9 @@ export function createBurstListener() {
|
||||
setState("listening");
|
||||
} catch (cause) {
|
||||
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.");
|
||||
error.hidden = false;
|
||||
} finally {
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
.burst-listener { width:min(100%,36rem); margin-top:1rem; }
|
||||
.burst-listener__button,.burst-listener__actions button { min-height:2.75rem; padding:.65rem 1rem; border:1px solid #ffd18c; border-radius:.7rem; color:#fff2df; font:inherit; font-weight:750; background:#39243a; cursor:pointer; }
|
||||
.burst-listener__panel { margin-top:.8rem; padding:1rem; border:1px solid #aa7294; border-radius:.8rem; background:#1b1730; color:#fff2df; }
|
||||
.burst-listener__panel canvas { display:block; width:100%; height:90px; margin:.8rem 0; background:#171225; border-radius:.4rem; }
|
||||
.burst-listener__panel p { margin:.5rem 0 1rem; color:#efc9dc; }
|
||||
.burst-listener__panel audio { width:100%; margin-bottom:1rem; }
|
||||
.burst-listener__actions { display:flex; flex-wrap:wrap; gap:.5rem; }
|
||||
.burst-listener [hidden] { display:none !important; }
|
||||
.burst-listener [role="alert"] { color:#ffd18c; }
|
||||
.manual-report__supporting { padding: 1rem; border: 1px solid #514282; border-radius: 1rem; background: #11152c; }
|
||||
.manual-report__supporting-header { display: flex; align-items: center; gap: .7rem; }
|
||||
.manual-report__microphone { display: grid; width: 2.5rem; height: 2.5rem; flex: none; place-items: center; border-radius: .7rem; background: #2a2051; font-size: 1.3rem; }
|
||||
.burst-listener__state { display: block; margin-top: .15rem; color: #b9addb; font-size: .84rem; }
|
||||
.manual-report__supporting[data-state="listening"] .burst-listener__state { color: #8fe5cc; }
|
||||
.manual-report__supporting[data-state="error"] .burst-listener__state { color: #ffbd9d; }
|
||||
.burst-listener { width: 100%; margin-top: .85rem; }
|
||||
.burst-listener__button, .burst-listener__actions button { min-height: 2.75rem; padding: .65rem 1rem; border: 1px solid #8d77d2; border-radius: .7rem; color: #e8dcff; font: inherit; font-weight: 750; background: #292148; cursor: pointer; }
|
||||
.burst-listener__button { width: 100%; }
|
||||
.burst-listener__panel { color: #f0eaff; }
|
||||
.burst-listener__panel strong { font-size: .92rem; }
|
||||
.burst-listener__panel canvas { display: block; width: 100%; height: 4rem; margin: .7rem 0 .35rem; border-radius: .5rem; background: linear-gradient(90deg, #191738, #241b44); }
|
||||
.burst-listener__panel p { margin: .35rem 0 .75rem; color: #b9addb; font-size: .82rem; }
|
||||
.burst-listener__panel audio { width: 100%; margin-bottom: .75rem; }
|
||||
.burst-listener__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
|
||||
.burst-listener__actions button { flex: 1 1 10rem; }
|
||||
.burst-listener__actions #burst-stop { border-color: #fb9b72; color: #ffd8c4; background: #2e1b31; }
|
||||
.burst-listener [hidden] { display: none !important; }
|
||||
.burst-listener [role="alert"] { margin: .65rem 0 0; color: #ffd1b6; }
|
||||
.burst-listener button:focus-visible { outline: 3px solid #c9b4ff; outline-offset: 3px; }
|
||||
:root[data-theme="light"] .manual-report__supporting { border-color: #d9b4d8; background: #fff8fb; }
|
||||
:root[data-theme="light"] .manual-report__microphone { background: #ead2eb; }
|
||||
:root[data-theme="light"] .burst-listener__state, :root[data-theme="light"] .burst-listener__panel p { color: #694b68; }
|
||||
:root[data-theme="light"] .burst-listener__panel { color: #321d42; }
|
||||
:root[data-theme="light"] .burst-listener__button, :root[data-theme="light"] .burst-listener__actions button { border-color: #b68bb5; color: #321d42; background: #ead2eb; }
|
||||
:root[data-theme="light"] .burst-listener__actions #burst-stop { border-color: #cf7957; color: #71331d; background: #ffe9de; }
|
||||
|
||||
Reference in New Issue
Block a user