Add notification badge count and MainTabView with notification tab FRE-4740 FRE-4739
- Add getUnreadCount() endpoint to NotificationsServiceProtocol - Add NotificationUnreadCountResponse model - Add badgeCount and fetchUnreadCount() to NotificationsViewModel - Update markAsRead/markAllAsRead to decrement badge count - Create MainTabView with Home, Challenges, Clubs, Notifications tabs - Add unread badge on notification tab using .badge() modifier - Support injected ViewModel in NotificationsView for shared state - Add badge count tests to NotificationServiceTests - Fetch unread count on app launch and tab switch Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -6,6 +6,7 @@ protocol NotificationsServiceProtocol: Sendable {
|
||||
func list(params: NotificationListParams) async throws -> [NotificationItem]
|
||||
func markAsRead(id: String) async throws
|
||||
func markAllAsRead() async throws
|
||||
func getUnreadCount() async throws -> Int
|
||||
}
|
||||
|
||||
// MARK: - Default Service
|
||||
@@ -62,6 +63,17 @@ class NotificationsService: NotificationsServiceProtocol {
|
||||
_ = try JSONDecoder().decode(NotificationMarkAllReadResponse.self, from: data)
|
||||
}
|
||||
|
||||
func getUnreadCount() async throws -> Int {
|
||||
let url = baseURL.appendingPathComponent("/api/notifications/unread-count")
|
||||
let request = try buildRequest(url: url)
|
||||
|
||||
let (data, response) = try await session.data(for: request)
|
||||
try validateResponse(response)
|
||||
|
||||
let decoded = try JSONDecoder().decode(NotificationUnreadCountResponse.self, from: data)
|
||||
return decoded.count
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func buildRequest(url: URL, method: HTTPMethod = .get, body: Data? = nil) throws -> URLRequest {
|
||||
|
||||
Reference in New Issue
Block a user