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

View File

@ -273,7 +273,7 @@ final class Database: ObservableObject {
continue continue
} }
if changedCaps.contains(oldCap.id) { if changedCaps.contains(oldCap.id) {
#warning("Merge changed caps with server updates") #warning("Merge changed caps with server updates")
} else { } else {
oldCap.update(with: cap) oldCap.update(with: cap)
let save = oldCap let save = oldCap