Skip to content

Commit

Permalink
Reformat odometer view (#346)
Browse files Browse the repository at this point in the history
* Reformat odometer view

* Small PR udpates

---------

Co-authored-by: Mikaela Caron <mikaelacaron@gmail.com>
  • Loading branch information
kondayutarou and mikaelacaron authored Oct 21, 2024
1 parent 7595807 commit 5e5ed93
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 99 deletions.
91 changes: 20 additions & 71 deletions Basic-Car-Maintenance/Shared/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
}
},
"%lld %@" : {
"extractionState" : "stale",
"localizations" : {
"de" : {
"stringUnit" : {
Expand Down Expand Up @@ -2678,77 +2679,6 @@
}
}
},
"For %@" : {
"comment" : "Maintenance list item description 'For which vehicle'",
"localizations" : {
"be" : {
"stringUnit" : {
"state" : "translated",
"value" : "Для %@"
}
},
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Für %@"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
"value" : "برای %@"
}
},
"hi" : {
"stringUnit" : {
"state" : "translated",
"value" : "%@ के लिए"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "대상 차량: %@"
}
},
"nl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Voor %@"
}
},
"pl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Dla %@"
}
},
"pt-BR" : {
"stringUnit" : {
"state" : "translated",
"value" : "Para %@"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Для %@"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "For %@"
}
},
"uk" : {
"stringUnit" : {
"state" : "translated",
"value" : "Для %@"
}
}
}
},
"GitHub Repo" : {
"comment" : "Link to the Basic Car Maintenance GitHub repo.",
"localizations" : {
Expand Down Expand Up @@ -2885,6 +2815,9 @@
}
}
},
"Key" : {
"extractionState" : "manual"
},
"Kilometers" : {
"localizations" : {
"de" : {
Expand Down Expand Up @@ -3217,6 +3150,16 @@
}
}
},
"Mileage: %lld %@" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Mileage: %1$lld %2$@"
}
}
}
},
"Miles" : {
"localizations" : {
"de" : {
Expand Down Expand Up @@ -3534,6 +3477,9 @@
}
}
},
"No Name" : {
"extractionState" : "manual"
},
"No results" : {
"localizations" : {
"be" : {
Expand Down Expand Up @@ -4153,6 +4099,9 @@
}
}
}
},
"Recorded On: %@" : {

},
"Report a Bug" : {
"comment" : "Link to report a bug",
Expand Down
34 changes: 34 additions & 0 deletions Basic-Car-Maintenance/Shared/Odometer/Views/OdometerRowView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// OdometerRowView.swift
// Basic-Car-Maintenance
//
// https://github.com/mikaelacaron/Basic-Car-Maintenance
// See LICENSE for license information.
//

import SwiftUI

struct OdometerRowView: View {
let reading: OdometerReading
let vehicleName: String?

var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("\(vehicleName ?? "No Name")")
.font(.title3)

VStack(alignment: .leading, spacing: 4) {
Text("Mileage: \(reading.distance) \(reading.isMetric ? "km" : "mi")")
.foregroundStyle(.gray)

Text("Recorded On: \(reading.date.formatted(date: .abbreviated, time: .omitted))")
.foregroundStyle(.gray)
}
}
}
}

#Preview {
OdometerRowView(reading: .init(date: .now, distance: 1000, isMetric: true, vehicleID: "1234"),
vehicleName: "Sample Vehicle Name")
}
47 changes: 19 additions & 28 deletions Basic-Car-Maintenance/Shared/Odometer/Views/OdometerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,28 @@ struct OdometerView: View {
NavigationStack {
List {
ForEach(viewModel.readings) { reading in
VStack(alignment: .leading, spacing: 8) {
Text("\(reading.distance) \(reading.isMetric ? "km" : "mi")")
.font(.title3)

let vehicleName = viewModel.vehicles.first { $0.id == reading.vehicleID }?.name
if let vehicleName {
Text("For \(vehicleName)")
}

Text("\(reading.date.formatted(date: .abbreviated, time: .omitted))")
}
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) {
Task {
await viewModel.deleteReading(reading)
let vehicleName = viewModel.vehicles.first { $0.id == reading.vehicleID }?.name
OdometerRowView(reading: reading, vehicleName: vehicleName)
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) {
Task {
await viewModel.deleteReading(reading)
}
} label: {
Image(systemName: SFSymbol.trash)
}
} label: {
Image(systemName: SFSymbol.trash)
}

Button {
viewModel.selectedReading = reading
viewModel.isShowingEditReadingView = true
} label: {
Label {
Text("Edit")
} icon: {
Image(systemName: SFSymbol.pencil)

Button {
viewModel.selectedReading = reading
viewModel.isShowingEditReadingView = true
} label: {
Label {
Text("Edit")
} icon: {
Image(systemName: SFSymbol.pencil)
}
}
}
}
}
.listStyle(.inset)
}
Expand Down

0 comments on commit 5e5ed93

Please sign in to comment.