Clear profile selection if current profile removed

Do it before ForEach rearranges NavigationLink elements, because
it may trigger undesired navigation to a deleted profile.

Restore related assertion.
This commit is contained in:
Davide De Rosa 2022-04-19 18:34:02 +02:00
parent 7128352a9c
commit 18e9f7cbb5
2 changed files with 13 additions and 1 deletions

View File

@ -160,11 +160,23 @@ extension OrganizerView.ProfilesList {
}
private func removeProfiles(_ indexSet: IndexSet) {
withAnimation {
doRemoveProfiles(indexSet)
}
}
private func doRemoveProfiles(_ indexSet: IndexSet) {
let headers = profileManager.headers.sorted()
var toDelete: [UUID] = []
indexSet.forEach {
toDelete.append(headers[$0].id)
}
// clear selection before removal to avoid triggering a bogus navigation push
if let selectedProfileId = selectedProfileId, toDelete.contains(selectedProfileId) {
self.selectedProfileId = nil
}
profileManager.removeProfiles(withIds: toDelete)
}

View File

@ -162,7 +162,7 @@ extension ProfileManager {
}
guard let profile = strategy.profile(withId: id) else {
// assertionFailure("Profile in headers yet not found in persistent store")
assertionFailure("Profile in headers yet not found in persistent store")
return nil
}
guard availabilityFilter?(profile.header) ?? true else {