Commit the shown CCTV camera with FOCUS, not a hidden picker option

The picker no longer keeps a hidden, disabled copy of the opening camera.
That copy could be re-picked with ArrowDown on a closed list, could show
twice in the iOS picker, and left Firefox without an accessible value.
The list now selects the camera's own option, as before. A native list
sends no change for the option it already shows, so FOCUS (or NEAREST,
when that camera is the nearest) keeps the shown camera. Closing the list
without a choice keeps automatic selection.
This commit is contained in:
German Khokhlov committed 2026-11-20 12:55:52 +04:00
1 parent a6eecee157
commit 09588b98bf
13 files changed
+56 -105

No files matched your search

+1 -10
View File
@@ -5,9 +5,7 @@ import { useCctvStore } from '../stores/cctv.js';
// The camera picker: the cameras in view and a closing note for those the
// view leaves out. It renders only when CctvControls publishes a picker,
// which re-applies the active camera, as on every layer notification. The
// opening camera, which follows the view until someone picks one, shows in a
// hidden first option: choosing that camera from the list is a change.
// which re-applies the active camera, as on every layer notification.
const { picker } = storeToRefs(useCctvStore());
// The selection, applied once the options are in place.
@@ -23,13 +21,6 @@ const vPick = { mounted: pick, updated: pick };
<template>
<UiSelect v-pick="picker?.selection" :disabled="picker?.disabled"
><option
v-if="picker?.opening"
value=""
hidden
disabled
data-cctv-opening
>{{ picker.opening }}</option
><option
v-for="option in picker?.options"
:key="option.value"
-24
View File
@@ -226,27 +226,3 @@ test('an active id without its camera record leaves the pick alone', async (t) =
});
assert.equal(select.value, 'b');
});
test('the opening camera shows in a hidden first option', async (t) => {
const { select, render, values } = fixture(t);
const [a, b] = [camera('a'), camera('b')];
const state = {
enabled: true,
count: 2,
cameraIndex: [b, a],
activeCameraId: 'b',
activeCamera: b,
};
await render({ ...state, activeCameraProvisional: true });
assert.deepEqual(values(), ['', 'b', 'a']);
assert.equal(select.selectedIndex, 0);
const opening = select.options[0];
assert.equal(opening.textContent, 'Austin · Cam b');
assert.equal(opening.hidden, true);
assert.equal(opening.disabled, true);
assert.equal(opening.dataset.cctvOpening, '');
await render(state);
assert.deepEqual(values(), ['b', 'a'], 'a picked camera has no hidden option');
assert.equal(select.value, 'b');
});
+25 -33
View File
@@ -1,8 +1,8 @@
// src/ui/cctvPickerOpening.test.mjs — the picker can pick the opening camera.
// The opening camera follows the view until someone picks one. A native
// select fires no change for the option it already shows, so the picker keeps
// that camera in a hidden first option: choosing it from the list is a change
// and ends the opening pick, while closing the list leaves it.
// src/ui/cctvPickerOpening.test.mjs — the picker and the opening camera.
// The opening camera follows the view until someone picks one. The picker
// shows it as its own option; a native select fires no change for the
// option it already shows, so FOCUS keeps that camera, and leaving the list
// without a choice lets it follow the view.
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
@@ -122,6 +122,7 @@ async function reopenedAtCambridge(t) {
elements: {
_cctvPanel: document.getElementById('cctv-panel'),
_cctvSelect: select,
_cctvFocusBtn: document.getElementById('cctv-focus-btn'),
},
cctv: cctvLayer,
actions: {
@@ -154,52 +155,43 @@ async function reopenedAtCambridge(t) {
return { viewer, select };
}
/** The label of the opening camera's hidden option, or null. */
function openingLabel(select) {
return (
select.querySelector('option[data-cctv-opening]')?.textContent ?? null
);
}
test('the opening camera shows as itself, from a hidden option', async (t) => {
test('the opening camera shows as its own option', async (t) => {
const { select } = await reopenedAtCambridge(t);
assert.equal(openingLabel(select), 'London · Camera b-cambridge');
assert.equal(select.selectedIndex, 0, 'the closed picker shows it');
const opening = select.options[0];
assert.equal(opening.dataset.cctvOpening, '');
assert.equal(opening.hidden, true, 'the open list does not show it twice');
assert.equal(opening.disabled, true);
assert.ok(
[...select.options].some((option) => option.value === 'b-cambridge'),
'the camera itself stays in the list to be picked',
assert.equal(select.value, 'b-cambridge');
const shown = select.options[select.selectedIndex];
assert.equal(shown.hidden, false);
assert.equal(shown.disabled, false);
assert.equal(
[...select.options].filter((option) => option.value === 'b-cambridge')
.length,
1,
'the list shows the camera once',
);
assert.ok([...select.options].every((option) => !option.hidden));
});
test('choosing the shown camera from the picker keeps it after a pan', async (t) => {
test('FOCUS on the shown camera keeps it after a pan', async (t) => {
const { viewer, select } = await reopenedAtCambridge(t);
select.value = 'b-cambridge';
select.dispatchEvent(new Event('change'));
// The change handler waits for the layer switch before it picks.
const focus = document.getElementById('cctv-focus-btn');
assert.equal(focus.disabled, false);
focus.click();
// The click handler waits for the layer switch before it picks.
await new Promise((resolve) => setTimeout(resolve, 0));
await nextTick();
assert.equal(cctvLayer.getUIState().activeCameraProvisional, false);
assert.equal(openingLabel(select), null);
assert.equal(select.value, 'b-cambridge');
assert.equal(settleOver(viewer, TRAFALGAR), false);
assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge');
assert.equal(select.value, 'b-cambridge');
});
test('closing the picker without a choice lets the camera follow a pan', async (t) => {
test('leaving the picker without a pick lets the camera follow a pan', async (t) => {
const { viewer, select } = await reopenedAtCambridge(t);
select.focus();
select.blur();
await nextTick();
assert.equal(cctvLayer.getUIState().activeCameraProvisional, true);
assert.equal(settleOver(viewer, TRAFALGAR), true);
await nextTick();
assert.equal(cctvLayer.getUIState().activeCameraId, 'a-trafalgar');
assert.equal(openingLabel(select), 'London · Camera a-trafalgar');
assert.equal(select.selectedIndex, 0);
assert.equal(select.value, 'a-trafalgar');
});
+2 -10
View File
@@ -253,23 +253,15 @@ export function _renderCctvState(state) {
};
}
this._picker = picker;
// The opening camera follows the view until someone picks one. The picker
// shows it in a hidden first option, so choosing it from the list changes
// the value and counts as that pick; closing the list leaves it as is.
const opening = Boolean(
state?.activeCameraProvisional && activeId && activeCamera,
);
this.store.setPicker({
options: picker?.options || [],
note: picker?.note || '',
opening: opening ? pickerOption(activeCamera, activeId).label : '',
disabled,
// The active camera is always one of the listed records. With nothing
// active the closed picker shows the note when nothing is in view; a
// focused picker keeps its old options, so it only clears.
selection: opening
? { index: 0 }
: activeId && activeCamera
selection:
activeId && activeCamera
? { value: activeId }
: !activeId
? { index: !picking && cameras.length === 0 && outside ? 0 : -1 }
+2 -3
View File
@@ -25,9 +25,8 @@ export const useCctvStore = defineStore('gev-cctv', () => {
/** `{label, state}` for the source badge; null until first synced. */
const sourceBadge = shallowRef(null);
/**
* The camera picker: `{options: [{value, label}], note, opening, disabled,
* selection: {value}|{index}|null}`; null until first rendered. `opening`
* labels the opening camera's hidden first option, or is empty.
* The camera picker: `{options: [{value, label}], note, disabled,
* selection: {value}|{index}|null}`; null until first rendered.
*/
const picker = shallowRef(null);
/** The scene summary as typed so far; null until the first one. */