Rename cap variable to make it multi-purpose

This commit is contained in:
Christoph Hagen 2022-12-16 22:43:20 +01:00
parent 25aadffa51
commit fb90a4847e
2 changed files with 8 additions and 8 deletions

View File

@ -53,7 +53,7 @@ struct ContentView: View {
var isEnteringNewCapName = false
@State
private var capIdOfNextPhoto: Int?
private var selectedCapId: Int?
var filteredCaps: [Cap] {
let text = searchString
@ -253,7 +253,7 @@ struct ContentView: View {
.sheet(isPresented: $showCameraSheet) {
CameraView(isPresented: $showCameraSheet,
image: $database.image,
capId: $capIdOfNextPhoto)
capId: $selectedCapId)
}
.sheet(isPresented: $showSettingsSheet) {
SettingsView(isPresented: $showSettingsSheet)
@ -334,13 +334,13 @@ struct ContentView: View {
private func didTap(cap: Cap) {
guard let image = database.image else {
capIdOfNextPhoto = cap.id
selectedCapId = cap.id
openCamera()
return
}
database.save(image, for: cap.id)
database.image = nil
capIdOfNextPhoto = nil
selectedCapId = nil
}
private func saveNewCap() {
@ -356,16 +356,16 @@ struct ContentView: View {
private func showRenameWindow(for cap: Cap) {
updatedCapName = cap.name
capIdOfNextPhoto = cap.id
selectedCapId = cap.id
showUpdateCapNameAlert = true
}
private func saveNewCapName() {
defer {
capIdOfNextPhoto = nil
selectedCapId = nil
updatedCapName = ""
}
guard let capId = capIdOfNextPhoto else {
guard let capId = selectedCapId else {
return
}
let name = updatedCapName.trimmingCharacters(in: .whitespacesAndNewlines)