From 52c5862b54c6435382840d116feac3d0e5fa4f53 Mon Sep 17 00:00:00 2001 From: Blacky <106263486+Black-Fox-2022@users.noreply.github.com> Date: Wed, 29 May 2024 12:04:01 +0200 Subject: [PATCH] Allow Notification Removal Fix #181 --- .../Status Banners/StatusMessageBanner.swift | 6 ++++- .../Status Banners/StatusMessageDisplay.swift | 23 ++++++++++++++++++- iOS/InsightGroupsView.swift | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Shared/Status Banners/StatusMessageBanner.swift b/Shared/Status Banners/StatusMessageBanner.swift index ba10dea..37a9e65 100644 --- a/Shared/Status Banners/StatusMessageBanner.swift +++ b/Shared/Status Banners/StatusMessageBanner.swift @@ -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) } } } diff --git a/Shared/Status Banners/StatusMessageDisplay.swift b/Shared/Status Banners/StatusMessageDisplay.swift index aa06aa0..1570a2f 100644 --- a/Shared/Status Banners/StatusMessageDisplay.swift +++ b/Shared/Status Banners/StatusMessageDisplay.swift @@ -12,6 +12,13 @@ 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() @@ -19,7 +26,12 @@ struct StatusMessageDisplay: View { 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) @@ -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() diff --git a/iOS/InsightGroupsView.swift b/iOS/InsightGroupsView.swift index 668d87e..1c2d9be 100644 --- a/iOS/InsightGroupsView.swift +++ b/iOS/InsightGroupsView.swift @@ -40,7 +40,7 @@ struct InsightGroupsView: View { var body: some View { NavigationView { VStack(alignment: .leading, spacing: 0) { - //StatusMessageDisplay() + StatusMessageDisplay() TestModeIndicator()