mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 01:06:23 +02:00
feat: add unread count endpoint and update inbox logic
- Introduced a new API endpoint to fetch unread notification counts, providing both total and recent counts for better tracking. - Updated the useInbox hook to manage separate states for older and recent unread counts, enhancing user experience with real-time updates. - Implemented logic to handle marking notifications as read, ensuring accurate count adjustments for both recent and older items. - Enhanced type definitions in the inbox types to support the new unread count functionality.
This commit is contained in:
parent
3a1fa25a6f
commit
076de2f3d7
4 changed files with 268 additions and 38 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import {
|
||||
type GetNotificationsRequest,
|
||||
type GetNotificationsResponse,
|
||||
type GetUnreadCountResponse,
|
||||
type MarkAllNotificationsReadResponse,
|
||||
type MarkNotificationReadRequest,
|
||||
type MarkNotificationReadResponse,
|
||||
getNotificationsRequest,
|
||||
getNotificationsResponse,
|
||||
getUnreadCountResponse,
|
||||
markAllNotificationsReadResponse,
|
||||
markNotificationReadRequest,
|
||||
markNotificationReadResponse,
|
||||
|
|
@ -85,6 +87,24 @@ class NotificationsApiService {
|
|||
markAllAsRead = async (): Promise<MarkAllNotificationsReadResponse> => {
|
||||
return baseApiService.patch("/api/v1/notifications/read-all", markAllNotificationsReadResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get unread notification count with split between total and recent
|
||||
* - total_unread: All unread notifications
|
||||
* - recent_unread: Unread within sync window (last 14 days)
|
||||
*/
|
||||
getUnreadCount = async (searchSpaceId?: number): Promise<GetUnreadCountResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
if (searchSpaceId !== undefined) {
|
||||
params.append("search_space_id", String(searchSpaceId));
|
||||
}
|
||||
const queryString = params.toString();
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/notifications/unread-count${queryString ? `?${queryString}` : ""}`,
|
||||
getUnreadCountResponse
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const notificationsApiService = new NotificationsApiService();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue