mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Clear notifications on list view appear
This commit is contained in:
parent
346345e0c9
commit
5bc262da33
4 changed files with 18 additions and 0 deletions
5
Packages/Models/Sources/Models/ServerError.swift
Normal file
5
Packages/Models/Sources/Models/ServerError.swift
Normal file
|
@ -0,0 +1,5 @@
|
|||
import Foundation
|
||||
|
||||
public struct ServerError: Decodable {
|
||||
public let error: String?
|
||||
}
|
|
@ -4,11 +4,14 @@ public enum Notifications: Endpoint {
|
|||
case notifications(sinceId: String?,
|
||||
maxId: String?,
|
||||
types: [String]?)
|
||||
case clear
|
||||
|
||||
public func path() -> String {
|
||||
switch self {
|
||||
case .notifications:
|
||||
return "notifications"
|
||||
case .clear:
|
||||
return "notifications/clear"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +25,8 @@ public enum Notifications: Endpoint {
|
|||
}
|
||||
}
|
||||
return params
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public struct NotificationsListView: View {
|
|||
.task {
|
||||
viewModel.client = client
|
||||
await viewModel.fetchNotifications()
|
||||
await viewModel.clear()
|
||||
}
|
||||
.refreshable {
|
||||
await viewModel.fetchNotifications()
|
||||
|
|
|
@ -72,6 +72,13 @@ class NotificationsViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
func clear() async {
|
||||
guard let client else { return }
|
||||
do {
|
||||
let _: ServerError = try await client.post(endpoint: Notifications.clear)
|
||||
} catch { }
|
||||
}
|
||||
|
||||
func handleEvent(event: any StreamEvent) {
|
||||
if let event = event as? StreamEventNotification {
|
||||
notifications.insert(event.notification, at: 0)
|
||||
|
|
Loading…
Reference in a new issue