mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Recent Imagery: defer the hand-over to a waiting pick instead of skipping it
The previous change skipped the hand-over for good while a user pick was pending. When that pick then probed empty, failed with a terminal error, or lost its source, nothing previewed and the slot stayed blank, where main would have draped the next ranked day. During the arrow-key debounce the empty slot also handed the Esri lease back and took it again 250 ms later. The hand-over is now deferred: the pick keeps first claim on the slot while its probe can still settle, and the next ranked day takes over as soon as the pick turns out empty, errors or loses its source. Turning a source off also drops a followed pick of that source. The layer keeps the current basemap while a deferred pick waits, and Escape releases it. Six tests cover both answer orders, the source toggle, a terminal error, the debounce and the lease.
This commit is contained in:
1 parent
881473cdd2
commit
8eac8bd545
3 files changed
+188
-13
No files matched your search
@@ -147,6 +147,8 @@ export function createRecentImageryLayer({
|
||||
let _pendingTimer = null;
|
||||
/** A focused day still being probed: it previews once present. */
|
||||
let _followKey = null;
|
||||
/** The automatic day was empty and a user pick has first claim on its slot. */
|
||||
let _handoverDeferred = false;
|
||||
let _auto = null;
|
||||
let _notice = null;
|
||||
let _split = DEFAULT_SPLIT;
|
||||
@@ -300,6 +302,15 @@ export function createRecentImageryLayer({
|
||||
else _followKey = key;
|
||||
}
|
||||
|
||||
/** A debounced or followed pick can still take the slot until its probe settles. */
|
||||
function pickWaiting() {
|
||||
if (_pending) return true;
|
||||
const followed = candidateFor(_followKey);
|
||||
if (!followed) return false;
|
||||
const status = thumbnails.get(followed.key)?.status;
|
||||
return status !== 'empty' && status !== 'error';
|
||||
}
|
||||
|
||||
/**
|
||||
* A day whose probe came back empty leaves the map: JPEG products have no
|
||||
* alpha and would drape black "no data" tiles. A pinned day is unpinned and
|
||||
@@ -322,7 +333,10 @@ export function createRecentImageryLayer({
|
||||
changed = true;
|
||||
// A day the user picked meanwhile, still being probed or debounced,
|
||||
// takes the slot instead of the next ranked day.
|
||||
if (wasAuto && !_followKey && !_pending) autoPreview(preview.key);
|
||||
if (wasAuto) {
|
||||
if (pickWaiting()) _handoverDeferred = true;
|
||||
else autoPreview(preview.key);
|
||||
}
|
||||
}
|
||||
// A followed day that turns out empty is dropped; an automatic one hands
|
||||
// over to the next ranked day.
|
||||
@@ -336,6 +350,13 @@ export function createRecentImageryLayer({
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
if (_handoverDeferred && !pickWaiting()) {
|
||||
const failedKey = _followKey || followed?.key || null;
|
||||
_handoverDeferred = false;
|
||||
_followKey = null;
|
||||
autoPreview(failedKey);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -567,7 +588,11 @@ export function createRecentImageryLayer({
|
||||
}
|
||||
if (!comparison) return;
|
||||
if (shown.a || shown.b) acquireComparison();
|
||||
else if (_lease || _comparisonReady || _comparisonError)
|
||||
// Keep the current basemap while the user's pick has first claim on the slot.
|
||||
else if (
|
||||
!_handoverDeferred &&
|
||||
(_lease || _comparisonReady || _comparisonError)
|
||||
)
|
||||
releaseComparison();
|
||||
}
|
||||
|
||||
@@ -609,6 +634,7 @@ export function createRecentImageryLayer({
|
||||
_catalogErrors = [];
|
||||
_catalogError = null;
|
||||
_auto = null;
|
||||
_handoverDeferred = false;
|
||||
}
|
||||
|
||||
function cancelSearch() {
|
||||
@@ -670,7 +696,9 @@ export function createRecentImageryLayer({
|
||||
function applyPreview(key) {
|
||||
clearPending();
|
||||
_followKey = null;
|
||||
if (key === _previewKey) return false;
|
||||
const changed = key !== _previewKey || _handoverDeferred;
|
||||
_handoverDeferred = false;
|
||||
if (!changed) return false;
|
||||
if (_auto?.key !== key) _auto = null;
|
||||
_previewKey = key;
|
||||
if (_enabled) syncRender();
|
||||
@@ -696,7 +724,17 @@ export function createRecentImageryLayer({
|
||||
const pending = _pending;
|
||||
_pending = null;
|
||||
if (_destroyed || !pending) return;
|
||||
if (pending.key && !drapable(candidateFor(pending.key))) return;
|
||||
if (pending.key && !drapable(candidateFor(pending.key))) {
|
||||
if (_handoverDeferred) {
|
||||
// Its empty card may already be hidden. Let focus follow the hand-over.
|
||||
_focusKey = pending.key;
|
||||
_followKey = pending.key;
|
||||
syncRender();
|
||||
requestThumbnails();
|
||||
notify();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (applyPreview(pending.key)) notify();
|
||||
}, FOCUS_DEBOUNCE_MS);
|
||||
}
|
||||
@@ -807,6 +845,15 @@ export function createRecentImageryLayer({
|
||||
const pending = candidateFor(_pending?.key);
|
||||
if (!_sources[id] && pending && sourceOf(pending.product) === id)
|
||||
clearPending();
|
||||
// A followed pick goes too. An automatic day keeps its follow.
|
||||
const followed = candidateFor(_followKey);
|
||||
if (
|
||||
!_sources[id] &&
|
||||
followed &&
|
||||
sourceOf(followed.product) === id &&
|
||||
_auto?.key !== followed.key
|
||||
)
|
||||
_followKey = null;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
@@ -1092,14 +1139,10 @@ export function createRecentImageryLayer({
|
||||
* @returns {boolean} Whether a preview was showing or on its way.
|
||||
*/
|
||||
clearPreview() {
|
||||
const had = Boolean(_pending || _followKey || plan().preview);
|
||||
clearPending();
|
||||
_followKey = null;
|
||||
if (_previewKey) {
|
||||
_previewKey = null;
|
||||
_auto = null;
|
||||
if (_enabled) syncRender();
|
||||
}
|
||||
const had = Boolean(
|
||||
_pending || _followKey || _handoverDeferred || plan().preview,
|
||||
);
|
||||
applyPreview(null);
|
||||
if (had) notify();
|
||||
return had;
|
||||
},
|
||||
@@ -1129,6 +1172,7 @@ export function createRecentImageryLayer({
|
||||
// The preview belonged to the old pins; the next focus move brings it back.
|
||||
clearPending();
|
||||
_followKey = null;
|
||||
_handoverDeferred = false;
|
||||
_previewKey = null;
|
||||
_auto = null;
|
||||
if (_enabled) {
|
||||
@@ -1422,6 +1466,7 @@ export function createRecentImageryLayer({
|
||||
if ('a' in params || 'b' in params) {
|
||||
clearPending();
|
||||
_followKey = null;
|
||||
_handoverDeferred = false;
|
||||
for (const slotId of SLOT_IDS) {
|
||||
if (slotId in params)
|
||||
_assigned[slotId] = parseCandidateKey(params[slotId])
|
||||
|
||||
@@ -1563,3 +1563,133 @@ test('a voice search cancelled mid-flight says so instead of looking empty', asy
|
||||
assert.equal(f.snap().searching, false);
|
||||
assert.equal(f.snap().notice, 'Search cancelled');
|
||||
});
|
||||
|
||||
test('a pick that probes empty after the automatic day lets the next ranked day drape', async () => {
|
||||
for (const order of [
|
||||
[S18, V15],
|
||||
[V15, S18],
|
||||
]) {
|
||||
const f = fixture();
|
||||
await f.ready();
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
assert.equal(f.snap().preview.key, S18);
|
||||
f.layer.preview(V15);
|
||||
assert.equal(f.diag().following, V15);
|
||||
for (const key of order) f.thumbnails.probe(key, 'empty');
|
||||
assert.equal(f.snap().preview.key, L16, `order ${order.join(' then ')}`);
|
||||
assert.equal(f.owned().a?.key, L16, `order ${order.join(' then ')}`);
|
||||
}
|
||||
// A catalog day can also probe empty during the arrow-key debounce.
|
||||
const f = fixture();
|
||||
await f.ready();
|
||||
f.thumbnails.probe(V21, 'present');
|
||||
f.layer.focus(2);
|
||||
assert.equal(f.diag().pending, L16);
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
f.thumbnails.probe(L16, 'empty');
|
||||
assert.equal(f.owned().a, null);
|
||||
f.timers.flush();
|
||||
assert.equal(f.owned().a?.key, V21);
|
||||
assert.equal(f.snap().focus.key, V21);
|
||||
});
|
||||
|
||||
test('a deferred hand-over goes ahead once the pick fails or its source turns off', async () => {
|
||||
const f = fixture();
|
||||
await f.ready();
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
f.layer.preview(V15);
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
assert.equal(f.owned().a, null, 'the pick keeps the slot while it is probed');
|
||||
f.thumbnails.probe(V15, 'error');
|
||||
assert.equal(f.diag().following, null);
|
||||
assert.equal(f.owned().a?.key, L16);
|
||||
assert.equal(f.snap().focus.key, L16, 'focus leaves the failed pick');
|
||||
const g = fixture();
|
||||
await g.ready();
|
||||
g.thumbnails.probe(L16, 'present');
|
||||
g.layer.preview(V15);
|
||||
g.thumbnails.probe(S18, 'empty');
|
||||
g.layer.setSources({ viirs: false });
|
||||
assert.equal(g.diag().following, null);
|
||||
assert.equal(g.owned().a?.key, L16);
|
||||
});
|
||||
|
||||
test('turning off the source of a followed pick does not block the hand-over', async () => {
|
||||
const f = fixture();
|
||||
await f.ready();
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
f.layer.preview(V15);
|
||||
assert.equal(f.diag().following, V15);
|
||||
f.layer.setSources({ viirs: false });
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
assert.notEqual(
|
||||
f.diag().following,
|
||||
V15,
|
||||
'a pick whose source is off is no longer followed',
|
||||
);
|
||||
assert.equal(f.owned().a?.key, L16);
|
||||
});
|
||||
|
||||
// The fake loader's 'error' status stands for the real loader's terminal error (never re-fetched).
|
||||
test('a pick whose probe failed does not block the hand-over', async () => {
|
||||
const f = fixture();
|
||||
await f.ready();
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
f.layer.preview(V15);
|
||||
f.thumbnails.probe(V15, 'error');
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
assert.equal(f.owned().a?.key, L16);
|
||||
});
|
||||
|
||||
test('an arrow-key pick waiting out the debounce keeps Esri through an empty automatic result', async () => {
|
||||
const controller = leasingController();
|
||||
const f = fixture({ controller });
|
||||
await f.ready();
|
||||
await settleTimes();
|
||||
assert.equal(controller.getActiveId(), 'esri-imagery');
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
f.thumbnails.probe(V15, 'present');
|
||||
const before = controller.calls.length;
|
||||
f.layer.focus(3);
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
await settleTimes(8);
|
||||
assert.equal(f.owned().a, null, 'no other day drapes meanwhile');
|
||||
assert.equal(
|
||||
controller.getActiveId(),
|
||||
'esri-imagery',
|
||||
'Esri held during the debounce',
|
||||
);
|
||||
f.timers.flush();
|
||||
await settleTimes(8);
|
||||
assert.equal(f.owned().a?.key, V15);
|
||||
assert.deepEqual(controller.calls.slice(before), [], 'no stack switches');
|
||||
});
|
||||
|
||||
test('Escape ends a deferred hand-over, and a followed pick keeps Esri through it', async () => {
|
||||
const escapeController = leasingController();
|
||||
const f = fixture({ controller: escapeController });
|
||||
await f.ready();
|
||||
await settleTimes();
|
||||
f.thumbnails.probe(L16, 'present');
|
||||
f.layer.preview(V15);
|
||||
f.thumbnails.probe(S18, 'empty');
|
||||
f.layer.clearPreview();
|
||||
await settleTimes(8);
|
||||
assert.equal(escapeController.getActiveId(), 'photoreal');
|
||||
f.thumbnails.probe(V21, 'present');
|
||||
assert.equal(f.owned().a, null, 'nothing drapes after Escape');
|
||||
const controller = leasingController();
|
||||
const g = fixture({ controller });
|
||||
await g.ready();
|
||||
await settleTimes();
|
||||
g.thumbnails.probe(L16, 'present');
|
||||
const before = controller.calls.length;
|
||||
g.layer.preview(V15);
|
||||
g.thumbnails.probe(S18, 'empty');
|
||||
await settleTimes(8);
|
||||
assert.equal(controller.getActiveId(), 'esri-imagery');
|
||||
g.thumbnails.probe(V15, 'empty');
|
||||
await settleTimes(8);
|
||||
assert.equal(g.owned().a?.key, L16);
|
||||
assert.deepEqual(controller.calls.slice(before), [], 'no stack switches');
|
||||
});
|
||||
Reference in new issue
Block a user