mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Put news on the globe, with a feed panel in the right rail
Events ▸ News draws the last 24 hours of reports from curated hotspots (Ukraine–Russia, Israel–Gaza–Lebanon, Iran–Hormuz, Yemen–Red Sea, Sudan, Sahel) and developing situations elsewhere, from any server that answers the `/api/news` read routes. - Globe: one marker per merged event, clamped to the ground and culled at the horizon; one beacon per hotspot when zoomed out and a pulsing beacon for a developing situation; hotspot outlines with disputed areas dotted and labelled by who administers and who claims them; picture cards for at most ten major or fast-growing events with two or more sources, never overlapping, switchable off. - Panel: hotspot chips, a severity filter (significant and above by default), categories, minor news off by default, and a scrolling list of event cards with picture, headline, place, sources, age and the sides that reported it. "In view" lists what is near the map below 3,000 km once the camera settles. A card flies the globe to its event and opens it with a link to the publisher. Reduced motion stops the pulse and the flights. - Core serves no news itself: the local server proxies GEV_NEWS_ORIGIN when it is set, and answers 503 unavailable otherwise, so the layer reads "not configured" once instead of retrying. - Share token 9 (enabled-only); voice stays off for this layer.
This commit is contained in:
1 parent
2d9d518946
commit
5bb489d1fb
48 files changed
+3394
-53
No files matched your search
@@ -0,0 +1,223 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createNewsPanel } from './newsPanel.js';
|
||||
import {
|
||||
NEWS_CATEGORIES,
|
||||
NEWS_SEVERITY,
|
||||
categoryLabel,
|
||||
feedCardView,
|
||||
normalizeFilters,
|
||||
} from '../layers/news/model.js';
|
||||
|
||||
const NOW = Date.parse('2026-10-28T10:00:00Z');
|
||||
const report = (id, extra = {}) => ({
|
||||
id,
|
||||
title: `Report ${id}`,
|
||||
url: `https://www.example.com/${id}`,
|
||||
publishedAt: '2026-10-28T09:00:00.000Z',
|
||||
publisher: 'Example',
|
||||
side: 'UA',
|
||||
category: 'strike',
|
||||
severity: 2,
|
||||
geo: { lat: 50, lon: 36, place: 'Kharkiv', mappable: true },
|
||||
pins: [{ lat: 50, lon: 36, place: 'Kharkiv', mappable: true }],
|
||||
event: null,
|
||||
media: [],
|
||||
...extra,
|
||||
});
|
||||
const big = report('big', {
|
||||
severity: 3,
|
||||
titleEn: 'Strike on Kharkiv',
|
||||
title: 'Удар по Харкову',
|
||||
media: ['video'],
|
||||
event: {
|
||||
size: 4,
|
||||
severity: 3,
|
||||
status: 'both-sides',
|
||||
lastAt: '2026-10-28T09:50:00.000Z',
|
||||
sides: [
|
||||
{ side: 'UA', title: 'a', url: 'https://a.test/', publisher: 'A' },
|
||||
{ side: 'RU', title: 'b', url: 'https://b.test/', publisher: 'B' },
|
||||
],
|
||||
image: { url: 'https://a.test/p.jpg', publisher: 'A' },
|
||||
},
|
||||
});
|
||||
|
||||
function view(extra = {}) {
|
||||
return {
|
||||
filters: normalizeFilters(),
|
||||
hotspots: [
|
||||
{ id: 'all', label: 'All', count: 7, active: true },
|
||||
{ id: 'ua-ru-war', label: 'Ukraine–Russia', count: 7, active: false },
|
||||
],
|
||||
categories: Object.keys(NEWS_CATEGORIES).map((id) => ({
|
||||
value: id,
|
||||
label: categoryLabel(id),
|
||||
})),
|
||||
severities: NEWS_SEVERITY.map((level, index) => ({
|
||||
value: index,
|
||||
label: level.label,
|
||||
color: level.color,
|
||||
})),
|
||||
items: [feedCardView(big, NOW), feedCardView(report('lone'), NOW)],
|
||||
inView: { active: false, loading: false, error: null, items: [] },
|
||||
selected: null,
|
||||
hasMore: true,
|
||||
loading: false,
|
||||
error: null,
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
function fixture() {
|
||||
document.body.innerHTML = `
|
||||
<div id="news-panel" class="collapsed" hidden>
|
||||
<span id="news-panel-count">0</span>
|
||||
<button data-collapse-target="news-panel"></button>
|
||||
<div id="news-panel-body"></div>
|
||||
</div>`;
|
||||
const panel = document.getElementById('news-panel');
|
||||
let opened = 0;
|
||||
panel
|
||||
.querySelector('[data-collapse-target]')
|
||||
.addEventListener('click', () => {
|
||||
opened++;
|
||||
panel.classList.remove('collapsed');
|
||||
});
|
||||
const calls = [];
|
||||
const news = createNewsPanel({
|
||||
container: document.getElementById('news-panel-body'),
|
||||
setLayerParams: (id, params, options) => calls.push([id, params, options]),
|
||||
});
|
||||
return { news, panel, calls, opened: () => opened };
|
||||
}
|
||||
|
||||
test('the panel shows the last 24 h as event cards and opens once', () => {
|
||||
const { news, panel, opened } = fixture();
|
||||
news.update(null);
|
||||
assert.equal(panel.hidden, true);
|
||||
news.update(view());
|
||||
assert.equal(panel.hidden, false);
|
||||
assert.equal(opened(), 1);
|
||||
assert.equal(document.getElementById('news-panel-count').textContent, '2');
|
||||
assert.equal(
|
||||
panel.querySelector('.news-readout__window').textContent,
|
||||
'Last 24 h',
|
||||
);
|
||||
assert.deepEqual(
|
||||
[...panel.querySelectorAll('.data-toggle-chip[data-chip-id]')].map(
|
||||
(chip) => chip.textContent,
|
||||
),
|
||||
['All 7', 'Ukraine–Russia 7'],
|
||||
);
|
||||
const [first, second] = panel.querySelectorAll(
|
||||
'.news-readout__feed .news-card',
|
||||
);
|
||||
assert.equal(
|
||||
first.querySelector('.news-card__title').textContent,
|
||||
'Strike on Kharkiv',
|
||||
);
|
||||
assert.equal(
|
||||
first.querySelector('.news-card__note').textContent,
|
||||
'English headline by the model',
|
||||
);
|
||||
assert.equal(
|
||||
first.querySelector('.news-card__meta').textContent,
|
||||
'Strike · Kharkiv · 4 sources · 10 min',
|
||||
);
|
||||
assert.equal(
|
||||
first.querySelector('.news-card__marker').getAttribute('aria-label'),
|
||||
'Major',
|
||||
);
|
||||
assert.equal(
|
||||
first.querySelector('.news-card__sides').textContent,
|
||||
'Reported by UA sources · RU sources',
|
||||
);
|
||||
assert.deepEqual(
|
||||
[...first.querySelectorAll('.news-chip')].map((c) => c.textContent),
|
||||
['Reported by both sides', 'Video'],
|
||||
);
|
||||
const img = first.querySelector('.news-card__thumb img');
|
||||
assert.equal(img.getAttribute('src'), 'https://a.test/p.jpg');
|
||||
assert.equal(img.getAttribute('referrerpolicy'), 'no-referrer');
|
||||
assert.equal(first.querySelector('.news-card__credit').textContent, 'A');
|
||||
// A lone report has no picture.
|
||||
assert.equal(second.querySelector('.news-card__thumb'), null);
|
||||
// A later update does not reopen a panel the reader collapsed.
|
||||
panel.classList.add('collapsed');
|
||||
news.update(view());
|
||||
assert.equal(opened(), 1);
|
||||
news.destroy();
|
||||
assert.equal(panel.hidden, true);
|
||||
});
|
||||
|
||||
test('a card click flies there; open, it links the source and closes', () => {
|
||||
const { news, panel, calls } = fixture();
|
||||
news.update(view());
|
||||
panel.querySelector('.news-card__main').click();
|
||||
assert.deepEqual(calls.at(-1), [
|
||||
'news',
|
||||
{ reportId: 'big', focus: true },
|
||||
{ origin: 'user' },
|
||||
]);
|
||||
news.update(view({ selected: feedCardView(big, NOW) }));
|
||||
const open = panel.querySelector('.news-card.is-open');
|
||||
const link = open.querySelector('.news-card__link');
|
||||
assert.equal(link.textContent, 'Source: example.com ↗');
|
||||
assert.equal(link.getAttribute('href'), 'https://www.example.com/big');
|
||||
assert.equal(link.getAttribute('rel'), 'noopener noreferrer');
|
||||
assert.equal(
|
||||
open.querySelector('.news-card__original').textContent,
|
||||
'Удар по Харкову',
|
||||
);
|
||||
open.querySelector('.news-card__main').click();
|
||||
assert.deepEqual(calls.at(-1)[1], { clear: true });
|
||||
news.destroy();
|
||||
});
|
||||
|
||||
test('filters, In view and empty or failed reads', () => {
|
||||
const { news, panel, calls } = fixture();
|
||||
news.update(view());
|
||||
assert.equal(panel.querySelector('[aria-label="In view"]'), null);
|
||||
const severity = panel.querySelector('select[aria-label="Severity"]');
|
||||
assert.equal(severity.value, '2');
|
||||
severity.value = '3';
|
||||
severity.dispatchEvent(new Event('change'));
|
||||
assert.deepEqual(calls.at(-1)[1], { filters: { minSeverity: 3 } });
|
||||
const [minor, cards] = panel.querySelectorAll('.news-toggle input');
|
||||
assert.equal(minor.checked, false);
|
||||
assert.equal(cards.checked, true);
|
||||
cards.checked = false;
|
||||
cards.dispatchEvent(new Event('change'));
|
||||
assert.deepEqual(calls.at(-1)[1], { filters: { cards: false } });
|
||||
panel.querySelector('[data-chip-id="ua-ru-war"]').click();
|
||||
assert.deepEqual(calls.at(-1)[1], { filters: { hotspot: 'ua-ru-war' } });
|
||||
|
||||
news.update(
|
||||
view({
|
||||
inView: { active: true, loading: false, error: null, items: [] },
|
||||
items: [],
|
||||
hasMore: false,
|
||||
}),
|
||||
);
|
||||
const section = panel.querySelector('[aria-label="In view"]');
|
||||
assert.match(
|
||||
section.textContent,
|
||||
/Nothing reported near here in the last 24 h/,
|
||||
);
|
||||
assert.match(
|
||||
panel.textContent,
|
||||
/No news matches these filters in the last 24 h/,
|
||||
);
|
||||
assert.equal(panel.querySelector('.news-readout__footer button'), null);
|
||||
|
||||
news.update(
|
||||
view({ items: [], error: 'News feed unavailable', hasMore: false }),
|
||||
);
|
||||
assert.equal(
|
||||
panel.querySelector('.news-readout__status').textContent,
|
||||
'News feed unavailable',
|
||||
);
|
||||
news.destroy();
|
||||
});
|
||||
Reference in new issue
Block a user