feat(flights): show the tracked aircraft's Planespotters photo in Contacts

Tracking a civil flight asks Planespotters for that aircraft's photo, once
per aircraft, straight from the browser. The CONTEXT panel's CONTACTS view
shows it under the flight's name with the photographer's credit, as a plain
link to the photo's page. Only images on plnspttrs.net and pages on
www.planespotters.net are ever shown or linked. Military aircraft and a
converted TR-3B are never looked up.

Flight lookups (type, route, photo) whose source failed temporarily are
asked again after a 60-second cool-down; an answer, found or not, and a
permanent refusal stay final for the session. A route belongs to the
callsign it was looked up for, so a callsign change drops the old route.

Browser QA scripts that track a flight answer the photo lookup themselves,
so they never call the third party.
This commit is contained in:
Sameh Khamis committed 2026-11-09 20:36:03 -08:00
1 parent 78c5b6c245
commit 1a8defbfc8
52 files changed
+1781 -46

No files matched your search

+70
View File
@@ -245,3 +245,73 @@ test('a repaint that leaves focus outside the panel does not pull it back', asyn
'an empty cohort renders no list',
);
});
const photo = (extra = {}) => ({
src: 'https://t.plnspttrs.net/1/abc123_280.jpg',
width: 280,
height: 186,
link: 'https://www.planespotters.net/photo/1/n123ab',
credit: 'Photo © Jane Doe',
...extra,
});
test('a tracked flight’s photo shows under its name, credited and linked to its page', async (t) => {
const { panel, publish } = fixture(t);
await publish({ ...results(), photo: photo() });
const root = panel();
const link = root.querySelector('a.military-awareness-photo');
assert.ok(link, 'the photo renders');
assert.equal(
root.querySelector('.military-awareness-subject').nextElementSibling,
link,
'directly under the subject line',
);
assert.equal(link.getAttribute('href'), photo().link);
assert.equal(link.getAttribute('target'), '_blank');
assert.equal(link.getAttribute('rel'), 'noopener');
const img = link.querySelector('img');
assert.equal(img.getAttribute('src'), photo().src);
assert.equal(img.getAttribute('alt'), '');
assert.equal(img.getAttribute('width'), '280');
assert.equal(img.getAttribute('height'), '186');
assert.equal(link.querySelector('small').textContent, 'Photo © Jane Doe');
});
test('no photo renders without one', async (t) => {
const { panel, publish } = fixture(t);
await publish({ ...results(), photo: null });
assert.equal(panel().querySelector('.military-awareness-photo'), null);
});
test('a photo whose image fails to load is hidden until another arrives', async (t) => {
const { panel, publish } = fixture(t);
await publish({ ...results(), photo: photo() });
panel()
.querySelector('.military-awareness-photo img')
.dispatchEvent(new Event('error'));
await nextTick();
assert.equal(panel().querySelector('.military-awareness-photo'), null);
// A repaint with the same photo keeps it hidden.
await publish({ ...results({ previousDisabled: false }), photo: photo() });
assert.equal(panel().querySelector('.military-awareness-photo'), null);
// Another plane's photo shows.
const next = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' });
await publish({ ...results(), photo: next });
assert.equal(
panel().querySelector('.military-awareness-photo img').getAttribute('src'),
next.src,
);
});
test('a late error from a previous photo’s image does not hide the current one', async (t) => {
const { panel, publish } = fixture(t);
const previous = photo();
const current = photo({ src: 'https://t.plnspttrs.net/2/def456_280.jpg' });
await publish({ ...results(), photo: current });
// The error belongs to the image that failed: here, one still on the old src.
const img = panel().querySelector('.military-awareness-photo img');
img.setAttribute('src', previous.src);
img.dispatchEvent(new Event('error'));
await nextTick();
assert.ok(panel().querySelector('.military-awareness-photo'));
});
+25
View File
@@ -360,6 +360,31 @@ html:not([lang='en']) .radio-transport button {
margin: 0 0 7px;
color: #fff;
}
.military-awareness-photo {
display: block;
margin: 0 0 8px;
color: #a9b7c7;
text-decoration: none;
}
.military-awareness-photo img {
display: block;
width: 100%;
height: auto;
border: 1px solid rgba(98, 181, 255, 0.34);
border-radius: 4px;
}
.military-awareness-photo small {
display: block;
margin-top: 3px;
}
.military-awareness-photo:hover small,
.military-awareness-photo:focus-visible small {
color: #fff;
}
.military-awareness-photo:focus-visible {
outline: 1px solid rgba(127, 200, 255, 0.85);
outline-offset: 2px;
}
.military-awareness-controls {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
+11
View File
@@ -11,6 +11,13 @@ import AwarenessNames from './AwarenessNames.vue';
const { awareness: view, awarenessLayer: layer } = storeToRefs(useContextStore());
const user = { origin: 'user' };
const root = ref(null);
// A photo whose image failed to load stays hidden until another one arrives.
// The failing image's own src is recorded, so a late error from a previous
// photo never hides the current one.
const failedPhoto = ref('');
const fail = (event) => {
failedPhoto.value = event.target.getAttribute('src');
};
// A live repaint keeps focus on the same control by identity: browsers drop
// focus from a node Vue moves, removes or disables, so the control is found
@@ -52,6 +59,10 @@ onUpdated(() => {
</div>
<template v-else-if="view.kind === 'results'">
<div class="military-awareness-subject">{{ view.subject }}</div>
<a v-if="view.photo && view.photo.src !== failedPhoto" class="military-awareness-photo" :href="view.photo.link" target="_blank" rel="noopener">
<img :src="view.photo.src" :width="view.photo.width ?? undefined" :height="view.photo.height ?? undefined" alt="" @error="fail" />
<small>{{ view.photo.credit }}</small>
</a>
<AwarenessNames v-if="view.subjectNames" :names="view.subjectNames" />
<div class="military-awareness-controls" role="group" :aria-label="view.navigation.label">
<button type="button" data-awareness-action="previous" :title="view.navigation.previous.title" :disabled="view.navigation.previous.disabled" @click="layer?.navigatePrevious(user)">{{ view.navigation.previous.text }}</button>