Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Notification Removal #194

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
var body: some View {
NavigationView {
VStack(alignment: .leading, spacing: 0) {
//StatusMessageDisplay()
StatusMessageDisplay()

TestModeIndicator()

Expand Down Expand Up @@ -72,7 +72,7 @@
.task {
for groupID in groupService.groupsDictionary.keys {
for insightID in groupService.groupsDictionary[groupID]?.insightIDs ?? [] {
if !(insightService.insightDictionary.keys.contains(insightID)) {

Check warning on line 75 in iOS/InsightGroupsView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Prefer For-Where Violation: `where` clauses are preferred over a single `if` inside a `for` (for_where)
await insightService.retrieveInsight(with: insightID)
}
}
Expand Down
Loading