Header Integration
This commit is contained in:
parent
59da4a7cc5
commit
a37d322994
13 changed files with 80 additions and 3 deletions
46
frontend/header/news-ticker.js
Normal file
46
frontend/header/news-ticker.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const response = await fetch('https://api.instantworkstation.com/workstations');
|
||||
const workstations = await response.json();
|
||||
|
||||
const now = new Date();
|
||||
const recent = new Date(now);
|
||||
|
||||
recent.setUTCDate(now.getUTCDate() - 30);
|
||||
recent.setUTCHours(0, 0, 0, 0);
|
||||
|
||||
const recentWorkstations = workstations.filter(isRecent);
|
||||
const news = recentWorkstations.flatMap(generateNews);
|
||||
const ticker = document.getElementById('news-ticker-content');
|
||||
|
||||
let index = 0;
|
||||
if (news.length > 0) {
|
||||
ticker.textContent = news[index];
|
||||
ticker.addEventListener('animationiteration', showNextAnnouncement);
|
||||
ticker.style.animationPlayState = 'running';
|
||||
}
|
||||
|
||||
function generateNews(workstation) {
|
||||
return workstation.architectures.map(architecture => {
|
||||
const workstationDetails = `${workstation.os} ${workstation.version}`;
|
||||
const architectureDetails = `${architecture.cpu} ${architecture.bitness} ${architecture.endianness}`;
|
||||
|
||||
return `${workstationDetails} ${architectureDetails} is now available`;
|
||||
});
|
||||
}
|
||||
|
||||
function isRecent(workstation) {
|
||||
const added = new Date(workstation.added);
|
||||
|
||||
return added >= recent;
|
||||
}
|
||||
|
||||
function showNextAnnouncement() {
|
||||
index++;
|
||||
|
||||
if (index < news.length) {
|
||||
ticker.textContent = news[index];
|
||||
} else {
|
||||
ticker.removeEventListener('animationiteration', showNextAnnouncement);
|
||||
ticker.style.animationPlayState = 'paused';
|
||||
ticker.textContent = '';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue