fix array length 0 check

This commit is contained in:
Beebles
2025-09-26 14:03:01 -06:00
parent 3b00e4a792
commit a5ce24405b
@@ -68,62 +68,66 @@ export function AnnouncementsDisplay() {
void fetchAnnouncement(); void fetchAnnouncement();
} }
if (!currentlyDisplayingAnnouncements) { if (currentlyDisplayingAnnouncements.length === 0) {
return null; return null;
} }
return ( return (
<PanelSection> <PanelSection>
{currentlyDisplayingAnnouncements.map((announcement) => ( {currentlyDisplayingAnnouncements.map((announcement) => (
<Announcement key={announcement.id} announcement={announcement} onHide={() => hideAnnouncement(announcement.id)} /> <Announcement
))} key={announcement.id}
announcement={announcement}
onHide={() => hideAnnouncement(announcement.id)}
/>
))}
</PanelSection> </PanelSection>
); );
} }
function Announcement({ announcement, onHide }: { announcement: Announcement, onHide: () => void }) { function Announcement({ announcement, onHide }: { announcement: Announcement; onHide: () => void }) {
// Severity is not implemented in the API currently // Severity is not implemented in the API currently
const severity = SEVERITIES['Low']; const severity = SEVERITIES['Low'];
return ( return (
<Focusable <Focusable
style={{ style={{
// Transparency is 20% of the color // Transparency is 20% of the color
backgroundColor: `${severity.color}33`, backgroundColor: `${severity.color}33`,
color: severity.text, color: severity.text,
borderColor: severity.color, borderColor: severity.color,
borderWidth: '2px', borderWidth: '2px',
borderStyle: 'solid', borderStyle: 'solid',
padding: '0.7rem', padding: '0.7rem',
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
position: 'relative', position: 'relative',
}} }}
> >
<div style={{ display: 'flex', justifyContent: 'space-between' }}> <div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span style={{ fontWeight: 'bold' }}>{announcement.title}</span> <span style={{ fontWeight: 'bold' }}>{announcement.title}</span>
<DialogButton <DialogButton
style={{
width: '1rem',
minWidth: '1rem',
height: '1rem',
padding: '0',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
top: '.75rem',
right: '.75rem',
}}
onClick={() => onHide()}
>
<FaTimes
style={{ style={{
width: '1rem', height: '.75rem',
minWidth: '1rem',
height: '1rem',
padding: '0',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
top: '.75rem',
right: '.75rem',
}} }}
onClick={() => onHide()} />
> </DialogButton>
<FaTimes </div>
style={{ <span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{announcement.text}</span>
height: '.75rem', </Focusable>
}}
/>
</DialogButton>
</div>
<span style={{ fontSize: '0.75rem', whiteSpace: 'pre-line' }}>{announcement.text}</span>
</Focusable>
); );
} }