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

@@ -95,7 +95,6 @@ function withReopenedLayer(fn) {
moveViewer(viewer, 51.5131, -0.1291);
assert.equal(reopenNearestCamera(), true);
assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge');
assert.equal(cctvLayer.getUIState().activeCameraProvisional, true);
fn(viewer);
} finally {
globalThis.document = originalDocument;
@@ -121,7 +120,6 @@ for (const [name, pick] of [
withReopenedLayer((viewer) => {
pick();
assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge');
assert.equal(cctvLayer.getUIState().activeCameraProvisional, false);
// A later settled move (a pan, or the landing of the pick's own flight)
// leaves the explicit choice alone.
moveViewer(viewer, 51.5081, -0.1281);
@@ -130,3 +128,11 @@ for (const [name, pick] of [
});
});
}
test('without a pick, the next settled move still follows the view', () => {
withReopenedLayer((viewer) => {
moveViewer(viewer, 51.5081, -0.1281);
assert.equal(reopenNearestCamera(), true);
assert.equal(cctvLayer.getUIState().activeCameraId, 'a-trafalgar');
});
});
+1 -1
View File
@@ -73,7 +73,7 @@ export function createNavigation({
return false;
const nearest = nearestCameraIdToViewer();
if (!nearest || nearest === layerState._activeCameraId) return false;
// Still the opening pick: its notification tells the picker so.
// Still the opening pick: later settled moves may replace it.
parts.selection.setActiveCamera(nearest, { opening: true });
return true;
}
-4
View File
@@ -286,10 +286,6 @@ export function createPresentation({
hoverId: layerState._hoverCardId,
},
activeCameraId: activeId,
// The camera CCTV opened on, following the view until someone picks one.
activeCameraProvisional: Boolean(
activeId && layerState._openingCameraProvisional,
),
activeCameraReselection: layerState._activeCameraReselection,
activeCamera: active ? getPublicCameraState(active, activeId) : null,
cameraIndex: cameraIndex(),
+3 -6
View File
@@ -73,17 +73,14 @@ export function createSelection({
record,
)
) {
// Picking the camera a settled move re-opened is still a choice: later
// settled moves must leave it alone, and the picker learns it.
const endsOpening = layerState._openingCameraProvisional && !opening;
if (endsOpening) layerState._openingCameraProvisional = false;
// Picking the camera a settled move re-opened is still a pick: later
// settled moves must leave it alone.
if (!opening) layerState._openingCameraProvisional = false;
// Browser-only feeds have a separate player; a reselect retries it
// without re-running activation or touching the projection geometry.
if (parts.model.isBrowserOverlayCamera(record.camera)) {
layerState._activeCameraReselection += 1;
parts.presentation.notifyListeners();
} else if (endsOpening) {
parts.presentation.notifyListeners();
}
return CCTV_ACTIVATION_RESULT.UNCHANGED;
}
+2 -2
View File
@@ -53,7 +53,7 @@ test('same-camera selection notifies browser-overlay feeds so playback can retry
assert.equal(fixture.notifications(), 1);
});
test('same-camera selection ends the opening pick and tells the panel once', () => {
test('same-camera selection ends the opening pick without notifying snapshot feeds', () => {
const fixture = makeSelection('tripcheck-odot');
fixture.state._openingCameraProvisional = true;
@@ -63,5 +63,5 @@ test('same-camera selection ends the opening pick and tells the panel once', ()
);
assert.equal(fixture.state._openingCameraProvisional, false);
assert.equal(fixture.state._activeCameraReselection, 0);
assert.equal(fixture.notifications(), 1);
assert.equal(fixture.notifications(), 0);
});
+1
View File
@@ -105,6 +105,7 @@ export function createTesting({ state: layerState, services, parts, source }) {
} = {}) {
layerState._viewer = viewer;
layerState._records = Array.isArray(records) ? records : [];
layerState._count = layerState._records.length;
layerState._recordById = new Map(
layerState._records
.filter((record) => record?.camera?.id)
+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. */