mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
refactor: enhance announcements functionality to include expired announcements in hooks and components
This commit is contained in:
parent
7bc02ce55b
commit
7af4bc0b49
5 changed files with 55 additions and 32 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue