-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathindex.jsx
More file actions
49 lines (42 loc) · 1.34 KB
/
index.jsx
File metadata and controls
49 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ArrowUpRightIcon } from '@heroicons/react/24/outline';
import Banner from '@node-core/ui-components/Common/Banner';
import { useEffect, useState } from 'preact/hooks';
import { fetchBanners } from './fetchBanners.mjs';
/** @import { BannerEntry } from './types.d.ts' */
/**
* Asynchronously fetches and displays announcement banners from the remote config.
* Global banners are rendered above version-specific ones.
* Non-blocking: silently ignores fetch/parse failures.
*
* @param {{ remoteConfig: string, versionMajor: number | null }} props
*/
export default ({ remoteConfig, versionMajor }) => {
const [banners, setBanners] = useState(/** @type {BannerEntry[]} */ ([]));
useEffect(() => {
if (!remoteConfig) {
return;
}
fetchBanners(remoteConfig, versionMajor)
.then(setBanners)
.catch(console.error);
}, []);
if (!banners.length) {
return null;
}
return (
<div role="region" aria-label="Announcements">
{banners.map(banner => (
<Banner key={banner.text ?? banner.text} type={banner.type}>
{banner.link ? (
<a href={banner.link} target="_blank" rel="noopener noreferrer">
{banner.text}
</a>
) : (
banner.text
)}
{banner.link && <ArrowUpRightIcon />}
</Banner>
))}
</div>
);
};