Skip to content

Commit

Permalink
Merge pull request #194 from TelemetryDeck/RemovalOfNotifications
Browse files Browse the repository at this point in the history
Allow Notification Removal
  • Loading branch information
Black-Fox-2022 authored May 29, 2024
2 parents 8e185d5 + 52c5862 commit 9d8984f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Shared/Status Banners/StatusMessageBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ struct StatusMessageBanner: View {
#endif
}

Spacer()
Image(systemName: "xmark")
.font(.system(size: 18))
.padding(.horizontal, 4)
.padding(.vertical, 10)
.foregroundColor(Color.secondary)
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion Shared/Status Banners/StatusMessageDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ struct StatusMessageDisplay: View {
@EnvironmentObject var api: APIClient
@EnvironmentObject var errorService: ErrorService

@AppStorage("dismissedNotificationsIDs4") var _dismissedNotificationsIDs: String = ""

var dismissedNotificationsIDs: [String] {
let x = _dismissedNotificationsIDs.split(separator: ",")
return x.map { String($0) }
}

@State var statusMessages: [DTOv2.StatusMessage] = []

let timer = Timer.publish(every: 60, on: .main, in: .common).autoconnect()

var body: some View {
VStack(spacing: 0) {
ForEach(statusMessages) { message in
StatusMessageBanner(statusMessage: message)
if !dismissedNotificationsIDs.contains(message.id) {
StatusMessageBanner(statusMessage: message)
.onTapGesture {
dismissNotification(id: message.id)
}
}
}
}
.onAppear(perform: loadMessages)
Expand All @@ -28,6 +40,15 @@ struct StatusMessageDisplay: View {
}
}

func dismissNotification(id: String) {
if dismissedNotificationsIDs.count > 20 {
let dismissedNotificationsIDsCopy = dismissedNotificationsIDs.suffix(20)
_dismissedNotificationsIDs = dismissedNotificationsIDsCopy.joined(separator: ",")
_dismissedNotificationsIDs.append(",")
}
_dismissedNotificationsIDs.append(id + ",")
}

func loadMessages() {
statusMessages = []
loadOrganizationStatusMessages()
Expand Down
2 changes: 1 addition & 1 deletion iOS/InsightGroupsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct InsightGroupsView: View {
var body: some View {
NavigationView {
VStack(alignment: .leading, spacing: 0) {
//StatusMessageDisplay()
StatusMessageDisplay()

TestModeIndicator()

Expand Down

0 comments on commit 9d8984f

Please sign in to comment.