From 48e3ca9045c4d134530adb203cf0b3cbd94edf69 Mon Sep 17 00:00:00 2001 From: Evelyn <122575337+evelyn-hur@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:18:22 -0800 Subject: [PATCH] Fixed addDeleteFlag in DeleteDataView Fixed adding delete flag in DeleteDataView by modifying .healthKitDescription to return self by default (temporary fix). Also fixed bug where deleting last timestamp in array returns "index out of range." --- Prisma/PrivacyControls/DeleteDataView.swift | 18 ++++++++---------- Prisma/Standard/PrismaStandard+Extension.swift | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Prisma/PrivacyControls/DeleteDataView.swift b/Prisma/PrivacyControls/DeleteDataView.swift index 5641f85..8980434 100644 --- a/Prisma/PrivacyControls/DeleteDataView.swift +++ b/Prisma/PrivacyControls/DeleteDataView.swift @@ -49,8 +49,9 @@ struct DeleteDataView: View { } // on delete, remove it on the UI and set flag in firebase .onDelete { indices in + let timestampsToDelete = indices.map { timeArrayStatic[$0] } + deleteInBackend(identifier: categoryIdentifier, timestamps: timestampsToDelete) timeArrayStatic.remove(atOffsets: indices) - deleteInBackend(identifier: categoryIdentifier, timestampIndices: indices) } } } @@ -59,19 +60,16 @@ struct DeleteDataView: View { } } .navigationTitle(privacyModule.identifierUIString[categoryIdentifier] ?? "Identifier Title Not Found") - } - func deleteInBackend(identifier: String, timestampIndices: IndexSet) { - // loop through all the indices of items deleted - // get correspoding timestamp from timestamp array with index - // set the flag at that corresponding timestamp - for index in timestampIndices where timeArrayStatic.indices.contains(index) { - Task { - await standard.addDeleteFlag(selectedTypeIdentifier: identifier, timestamp: timeArrayStatic[index]) - } + + func deleteInBackend(identifier: String, timestamps: [String]) { + for timestamp in timestamps { + Task { + await standard.addDeleteFlag(selectedTypeIdentifier: identifier, timestamp: timestamp) } } } +} #Preview { diff --git a/Prisma/Standard/PrismaStandard+Extension.swift b/Prisma/Standard/PrismaStandard+Extension.swift index 358ec4d..29a5a73 100644 --- a/Prisma/Standard/PrismaStandard+Extension.swift +++ b/Prisma/Standard/PrismaStandard+Extension.swift @@ -21,7 +21,8 @@ extension String { for prefix in prefixes where self.hasPrefix(prefix) { return self.dropFirst(prefix.count).lowercased() } - return "unknown" + // return "unknown" + return self } }