refactor: enhance announcements functionality to include expired announcements in hooks and components

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-07-16 20:03:09 -07:00
parent 7bc02ce55b
commit 7af4bc0b49
5 changed files with 55 additions and 32 deletions

View file

@ -54,28 +54,17 @@ export const announcements: Announcement[] = [
url: "/changelog",
},
},
{
id: "announcement-1",
title: "Introducing What's New",
description: "All major product updates will be posted here.",
category: "feature",
date: "2026-02-17T00:00:00Z",
startTime: "2026-02-17T00:00:00Z",
endTime: "2026-02-20T00:00:00Z",
audience: "all",
isImportant: false,
},
{
id: "announcement-6",
title: "Past Test Announcement",
description: "This should be seen by nobody, because it's in the past.",
category: "maintenance",
date: "2026-02-17T00:00:00Z",
startTime: "2026-02-15T23:23:00Z",
endTime: "2026-02-16T00:00:00Z",
audience: "users",
isImportant: true,
},
// {
// id: "announcement-1",
// title: "Introducing What's New",
// description: "All major product updates will be posted here.",
// category: "feature",
// date: "2026-02-17T00:00:00Z",
// startTime: "2026-02-17T00:00:00Z",
// endTime: "2026-02-20T00:00:00Z",
// audience: "all",
// isImportant: false,
// },
// {
// id: "2026-02-10-podcast-improvements",
// title: "Podcast Generation Improvements",

View file

@ -37,6 +37,32 @@ export function announcementMatchesAudience(
}
}
/**
* Returns true when the announcement has been published (startTime has
* passed), regardless of whether its visibility window has expired.
* Used for archive views like the announcements page.
*/
export function isAnnouncementPublished(announcement: Announcement, now = new Date()): boolean {
const start = new Date(announcement.startTime).getTime();
if (Number.isNaN(start)) return false;
return now.getTime() >= start;
}
/**
* Filter announcements to all published ones (including expired) targeted
* at the given audience. Powers archive views; use getActiveAnnouncements
* for toasts, spotlights, and unread badges.
*/
export function getPublishedAnnouncements(
announcements: Announcement[],
isAuthenticated: boolean,
now = new Date()
): Announcement[] {
return announcements.filter(
(a) => isAnnouncementPublished(a, now) && announcementMatchesAudience(a, isAuthenticated)
);
}
/**
* Filter announcements to only those that are currently active and
* targeted at the given audience.