|
|
|
|
@ -69,7 +69,9 @@ struct CountdownEditView : View { |
|
|
|
|
@State var nameString: String = "" |
|
|
|
|
|
|
|
|
|
@State var deleteConfirmationShown: Bool = false |
|
|
|
|
|
|
|
|
|
@State var activityNameConfirmationShown: Bool = false |
|
|
|
|
@State fileprivate var _rename: Bool? = nil |
|
|
|
|
|
|
|
|
|
@State var errorShown: Bool = false |
|
|
|
|
@State var error: Error? = nil |
|
|
|
|
|
|
|
|
|
@ -100,6 +102,19 @@ struct CountdownEditView : View { |
|
|
|
|
}, message: { |
|
|
|
|
Text("Do you really want to delete?") |
|
|
|
|
}) |
|
|
|
|
.confirmationDialog("", isPresented: $activityNameConfirmationShown, actions: { |
|
|
|
|
Button("Rename") { |
|
|
|
|
self._rename = true |
|
|
|
|
self._save() |
|
|
|
|
} |
|
|
|
|
Button("New activity") { |
|
|
|
|
self._rename = false |
|
|
|
|
self._save() |
|
|
|
|
} |
|
|
|
|
}, message: { |
|
|
|
|
Text("Do you wish to rename or create a new activity") |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
.alert("", isPresented: $errorShown, actions: { }, message: { |
|
|
|
|
Text(error?.localizedDescription ?? "error") |
|
|
|
|
}) |
|
|
|
|
@ -192,8 +207,24 @@ struct CountdownEditView : View { |
|
|
|
|
cd.order = max + 1 |
|
|
|
|
} |
|
|
|
|
if !self.nameString.isEmpty { |
|
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: self.nameString) |
|
|
|
|
// TODO: would you like to rename or create a new activity? |
|
|
|
|
|
|
|
|
|
if let activity = cd.activity, let currentActivityName = activity.name, self.nameString != currentActivityName { |
|
|
|
|
|
|
|
|
|
switch self._rename { |
|
|
|
|
case .none: |
|
|
|
|
self.activityNameConfirmationShown = true |
|
|
|
|
return |
|
|
|
|
case .some(let rename): |
|
|
|
|
if rename { |
|
|
|
|
activity.name = self.nameString |
|
|
|
|
} else { |
|
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: self.nameString) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
cd.activity = CoreDataRequests.getOrCreateActivity(name: self.nameString) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self._saveContext() |
|
|
|
|
|