Let the News panel narrow the window to 12, 6, 3 or 1 hours

The panel's window label becomes a choice of the server's window and each
shorter one. The feed and map filter to it locally; the hotspot counts are
read again for it (/api/news/hotspots?hours=N, now on the allowlist). A
server names the longest window it serves as maxWindowHours.
This commit is contained in:
Denis Groshev committed 2026-11-06 00:45:28 +01:00
1 parent ee3593cfbd
commit 4817d2a648
22 files changed
+198 -21

No files matched your search

+20 -2
View File
@@ -8,7 +8,8 @@ import RailChips from '../rail/RailChips.vue';
import NewsCard from './NewsCard.vue';
// The News panel: the window the server serves only (the last 24 hours, or
// fewer where the host serves less). Hotspot chips, filters, the chosen
// fewer where the host serves less), or a shorter one chosen at the
// top (24/12/6/3/1 h). Hotspot chips, filters, the chosen
// event, "In view" (reports near the view centre while the camera is low)
// and a continuous feed, newest first. It renders the `feed` view the news
// layer publishes and acts only through `onParams`.
@@ -44,6 +45,15 @@ const categoryOptions = computed(() => [
{ value: 'all', label: t('All categories') },
...(props.view?.categories ?? []),
]);
const windowOptions = computed(() =>
(props.view?.windowChoices ?? []).map((hours) => ({
value: String(hours),
label: t('Last {hours} h', { hours }),
})),
);
// The longest choice is the server's whole window, kept as no choice.
const chooseWindow = (hours) =>
setFilter('hours', hours === props.view?.windowChoices?.[0] ? null : hours);
const selectedId = computed(() => props.view?.selected?.id ?? null);
// The chosen event leads the panel unless the feed already shows it open.
const selectedApart = computed(() => {
@@ -78,7 +88,15 @@ const clear = () => props.onParams({ clear: true });
class="news-readout"
:aria-label="t('News, last {hours} hours', { hours: view.windowHours })"
>
<p class="news-readout__window ui-mono">{{
<UiSelect
v-if="windowOptions.length > 1"
class="gev-field news-filter news-readout__window-choice"
:aria-label="t('Time window')"
:model-value="String(view.windowHours)"
:options="windowOptions"
@update:model-value="chooseWindow(Number($event))"
/>
<p v-else class="news-readout__window ui-mono">{{
t('Last {hours} h', { hours: view.windowHours })
}}</p>
<div class="news-readout__chips" role="group" :aria-label="t('Hotspots')">
+18
View File
@@ -278,6 +278,24 @@ test('scrolling to the end asks once per page, again after a filter change or a
news.destroy();
});
test('the window choice offers shorter windows; the longest is the server window', () => {
const { news, panel, calls } = fixture();
news.update(view({ windowHours: 12, windowChoices: [12, 6, 3, 1] }));
assert.equal(panel.querySelector('.news-readout__window'), null);
const choice = panel.querySelector('select[aria-label="Time window"]');
assert.deepEqual(
[...choice.options].map((option) => option.textContent),
['Last 12 h', 'Last 6 h', 'Last 3 h', 'Last 1 h'],
);
assert.equal(choice.value, '12');
choice.value = '3';
choice.dispatchEvent(new Event('change'));
assert.deepEqual(calls.at(-1)[1], { filters: { hours: 3 } });
choice.value = '12';
choice.dispatchEvent(new Event('change'));
assert.deepEqual(calls.at(-1)[1], { filters: { hours: null } });
});
test('the panel names the window the server serves', () => {
const { news, panel } = fixture();
news.update(view({ windowHours: 12 }));
+5
View File
@@ -131,6 +131,11 @@
.news-filter {
min-width: 0;
}
/* The window choice sits where the window label does, as narrow as its text. */
.news-readout__window-choice {
align-self: flex-start;
font-family: var(--font-mono);
}
.news-toggle {
display: flex;
align-items: center;