mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-30 04:01:02 +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?,
|
case notifications(sinceId: String?,
|
||||||
maxId: String?,
|
maxId: String?,
|
||||||
types: [String]?)
|
types: [String]?)
|
||||||
|
case clear
|
||||||
|
|
||||||
public func path() -> String {
|
public func path() -> String {
|
||||||
switch self {
|
switch self {
|
||||||
case .notifications:
|
case .notifications:
|
||||||
return "notifications"
|
return "notifications"
|
||||||
|
case .clear:
|
||||||
|
return "notifications/clear"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +25,8 @@ public enum Notifications: Endpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params
|
return params
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public struct NotificationsListView: View {
|
||||||
.task {
|
.task {
|
||||||
viewModel.client = client
|
viewModel.client = client
|
||||||
await viewModel.fetchNotifications()
|
await viewModel.fetchNotifications()
|
||||||
|
await viewModel.clear()
|
||||||
}
|
}
|
||||||
.refreshable {
|
.refreshable {
|
||||||
await viewModel.fetchNotifications()
|
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) {
|
func handleEvent(event: any StreamEvent) {
|
||||||
if let event = event as? StreamEventNotification {
|
if let event = event as? StreamEventNotification {
|
||||||
notifications.insert(event.notification, at: 0)
|
notifications.insert(event.notification, at: 0)
|
||||||
|
|
Loading…
Reference in a new issue