Skip to content

Commit

Permalink
change to use array of hidden announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Sep 13, 2024
1 parent 985dc66 commit af9c2ec
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions frontend/src/components/AnnouncementsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const welcomeAnnouncement: Announcement = {
export function AnnouncementsDisplay() {
const [announcement, setAnnouncement] = useState<Announcement | null>(null);
// showWelcome will display a welcome motd, the welcome motd has an id of "welcome" and once that is saved to hiddenMotdId, it will not show again
const [hiddenAnnouncementId, setHiddenAnnouncementId] = useSetting('hiddenAnnouncementId', 'showWelcome');
const [hiddenAnnouncementIds, setHiddenAnnouncementIds] = useSetting<string[]>('hiddenAnnouncementIds', []);

async function fetchAnnouncement() {
const announcement = await getLatestAnnouncement();
Expand All @@ -41,23 +41,22 @@ export function AnnouncementsDisplay() {
useEffect(() => {
void fetchAnnouncement();
}, []);

useEffect(() => {
if (hiddenAnnouncementId === 'showWelcome') {
if (hiddenAnnouncementIds.length > 0) {
setAnnouncement(welcomeAnnouncement);
}
}, [hiddenAnnouncementId]);
}, [hiddenAnnouncementIds]);

function hideAnnouncement() {
if (announcement) {
setHiddenAnnouncementId(announcement.id);
setHiddenAnnouncementIds([...hiddenAnnouncementIds, announcement.id]);
void fetchAnnouncement();
}
}

const hidden = useMemo(() => {
return hiddenAnnouncementId === announcement?.id;
}, [hiddenAnnouncementId, announcement]);
return !announcement?.id || hiddenAnnouncementIds.includes(announcement.id);
}, [hiddenAnnouncementIds, announcement]);

if (!announcement || !announcement.title || hidden) {
return null;
Expand Down

0 comments on commit af9c2ec

Please sign in to comment.