implement lap edit
This commit is contained in:
@@ -17,6 +17,7 @@ struct StopwatchDetailView: View {
|
||||
@State private var draftName: String
|
||||
@State private var isShowingResetAlert = false
|
||||
@State private var isShowingDeleteAlert = false
|
||||
@State private var editingLap: Stopwatch.Lap?
|
||||
|
||||
private let dateFormatter: DateFormatter = {
|
||||
let formatter = DateFormatter()
|
||||
@@ -78,27 +79,32 @@ struct StopwatchDetailView: View {
|
||||
} else {
|
||||
List {
|
||||
ForEach(stopwatch.laps) { lap in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("Lap \(lap.number)")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text(Stopwatch.format(interval: lap.duration, format: AppSettings.shared.timeFormat))
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.bold()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .trailing) {
|
||||
Text(dateFormatter.string(from: lap.startTime))
|
||||
Text(dateFormatter.string(from: lap.endTime))
|
||||
Button {
|
||||
editingLap = lap
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("Lap \(lap.number)")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
Text(Stopwatch.format(interval: lap.duration, format: AppSettings.shared.timeFormat))
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.bold()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .trailing) {
|
||||
Text(dateFormatter.string(from: lap.startTime))
|
||||
Text(dateFormatter.string(from: lap.endTime))
|
||||
}
|
||||
}
|
||||
.font(.system(.caption, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.font(.system(.caption, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,26 +114,21 @@ struct StopwatchDetailView: View {
|
||||
Button(role: .destructive) {
|
||||
isShowingResetAlert = true
|
||||
} label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text("Reset Stopwatch")
|
||||
Spacer()
|
||||
}
|
||||
Text("Reset Stopwatch")
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
|
||||
Section {
|
||||
Button(role: .destructive) {
|
||||
isShowingDeleteAlert = true
|
||||
} label: {
|
||||
HStack {
|
||||
Spacer()
|
||||
Button(role: .destructive) {
|
||||
isShowingDeleteAlert = true
|
||||
} label: {
|
||||
Text("Delete Stopwatch")
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.navigationTitle("Edit Stopwatch")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.alert("Are you sure you want to reset the Stopwatch \(stopwatch.name)?", isPresented: $isShowingResetAlert) {
|
||||
@@ -155,6 +156,11 @@ struct StopwatchDetailView: View {
|
||||
.disabled(draftName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||
}
|
||||
}
|
||||
.sheet(item: $editingLap) { lap in
|
||||
EditLapView(lap: lap) { updatedLap in
|
||||
stopwatch.update(lap: updatedLap)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user