New: custom alert for merge/replace imported events

This commit is contained in:
neon443
2025-05-28 14:47:05 +01:00
parent 1902c5102c
commit 0f3b86fe8c
3 changed files with 92 additions and 40 deletions

View File

@@ -325,14 +325,18 @@ class EventViewModel: ObservableObject, @unchecked Sendable {
return ""
}
func importEvents(_ imported: String) throws {
func importEvents(_ imported: String, replace: Bool) throws {
guard let data = Data(base64Encoded: imported) else {
throw importError.invalidB64
}
let decoder = JSONDecoder()
do {
let decoded = try decoder.decode([Event].self, from: data)
self.events = decoded
if replace {
self.events = decoded
} else {
self.events = self.events + decoded
}
saveEvents()
} catch {
throw error