-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9197c2
commit a6f96fa
Showing
6 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Basic-Car-Maintenance/Shared/Models/EditVehicleEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// EditVehicleEvent.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// Created by Traton Gossink on 11/18/23. | ||
// | ||
|
||
import FirebaseFirestoreSwift | ||
import Foundation | ||
|
||
struct EditVehicleEvent: Codable, Identifiable, Hashable { | ||
@DocumentID var id: String? | ||
var userID: String? | ||
let name: String | ||
let make: String | ||
let model: String | ||
let year: String | ||
let color: String | ||
let VIN: String | ||
let licenseplatenumber: String | ||
var vehicle: Vehicle? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
Basic-Car-Maintenance/Shared/Settings/Views/EditVehicleView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// EditVehicleView.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// Created by Traton Gossink on 11/6/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct EditVehicleView: View, Observable { | ||
@Binding var selectedEvent: EditVehicleEvent? | ||
var viewModel: SettingsViewModel | ||
@State private var selectedVehicle: Vehicle? | ||
@State private var name = "" | ||
@State private var make = "" | ||
@State private var model = "" | ||
@State private var year = "" | ||
@State private var color = "" | ||
@State private var VIN = "" | ||
@State private var licensePlateNumber = "" | ||
@Environment(\.dismiss) var dismiss | ||
|
||
var body: some View { | ||
NavigationStack { | ||
Form { | ||
Section { | ||
TextField("Name", text: $name) | ||
} header: { | ||
Text("Name") | ||
} | ||
Section { | ||
TextField("Make", text: $make) | ||
} header: { | ||
Text("Make") | ||
} | ||
|
||
Section { | ||
TextField("Model", text: $model) | ||
} header: { | ||
Text("Model") | ||
} | ||
|
||
Section { | ||
TextField("Year", text: $year) | ||
} header: { | ||
Text("Year") | ||
} | ||
|
||
Section { | ||
TextField("Color", text: $color) | ||
} header: { | ||
Text("Color") | ||
} | ||
Section { | ||
TextField("VIN", text: $VIN) | ||
} header: { | ||
Text("VIN") | ||
} | ||
Section { | ||
TextField("License Plate Number", text: $licensePlateNumber) | ||
} header: { | ||
Text("License Plate Number") | ||
} | ||
} | ||
.analyticsView("\(Self.self)") | ||
.onAppear { | ||
guard let selectedEvent = selectedEvent else { return } | ||
setEditVehicleEventValues(event: selectedEvent) | ||
} | ||
.navigationTitle(Text("Update Vehicle Info")) | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
Button { | ||
dismiss() | ||
} label: { | ||
Text("Cancel") | ||
} | ||
} | ||
|
||
ToolbarItem(placement: .topBarTrailing) { | ||
Button { | ||
if let selectedVehicle, let selectedEvent { | ||
var event = EditVehicleEvent(name: name, | ||
make: make, | ||
model: model, | ||
year: year, | ||
color: color, | ||
VIN: VIN, | ||
licenseplatenumber: licensePlateNumber, | ||
vehicle: selectedVehicle) | ||
event.id = selectedEvent.id | ||
Task { | ||
await viewModel.updateEvent(event) | ||
dismiss() | ||
} | ||
} | ||
} label: { | ||
Text("Update") | ||
} | ||
.disabled(name.isEmpty) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func setEditVehicleEventValues(event: EditVehicleEvent) { | ||
self.name = event.name | ||
self.make = event.make | ||
self.model = event.model | ||
self.year = event.year | ||
self.color = event.color | ||
self.VIN = event.VIN | ||
self.licensePlateNumber = event.licenseplatenumber | ||
self.selectedVehicle = event.vehicle | ||
} | ||
} | ||
|
||
#Preview { | ||
EditVehicleView(selectedEvent: | ||
.constant(EditVehicleEvent(name: "", make: "", model: "", year: "", color: "", VIN: "", licenseplatenumber: "")), | ||
viewModel: | ||
SettingsViewModel(authenticationViewModel: AuthenticationViewModel()) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters