Opening report from history
This commit is contained in:
parent
a7f4e6b3c5
commit
bc88a7bb0e
@ -11,7 +11,7 @@ import SwiftUI
|
|||||||
import AutoCatCore
|
import AutoCatCore
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
class HistoryCoordinator {
|
final class HistoryCoordinator {
|
||||||
|
|
||||||
var navController: UINavigationController?
|
var navController: UINavigationController?
|
||||||
|
|
||||||
@ -20,7 +20,8 @@ class HistoryCoordinator {
|
|||||||
let resolver = ServiceContainer.shared
|
let resolver = ServiceContainer.shared
|
||||||
let viewModel = HistoryViewModel(
|
let viewModel = HistoryViewModel(
|
||||||
apiService: resolver.resolve(ApiServiceProtocol.self),
|
apiService: resolver.resolve(ApiServiceProtocol.self),
|
||||||
storageService: resolver.resolve(StorageServiceProtocol.self)
|
storageService: resolver.resolve(StorageServiceProtocol.self),
|
||||||
|
coordinator: self
|
||||||
)
|
)
|
||||||
|
|
||||||
let view = HistoryScreen(viewModel: viewModel)
|
let view = HistoryScreen(viewModel: viewModel)
|
||||||
@ -31,4 +32,12 @@ class HistoryCoordinator {
|
|||||||
|
|
||||||
return navController
|
return navController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openReport(vehicle: VehicleDto) async {
|
||||||
|
|
||||||
|
let coordinator = ReportCoordinator(controller: navController,
|
||||||
|
vehicle: vehicle,
|
||||||
|
isPersistent: true)
|
||||||
|
_ = try? await coordinator.start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,9 @@ struct HistoryScreen: View {
|
|||||||
Section(header: Text(section.header)) {
|
Section(header: Text(section.header)) {
|
||||||
ForEach(section.elements) { vehicle in
|
ForEach(section.elements) { vehicle in
|
||||||
VehicleCellView(vehicle: vehicle)
|
VehicleCellView(vehicle: vehicle)
|
||||||
|
.onTapGesture {
|
||||||
|
Task { await viewModel.openReport(vehicle: vehicle) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ final class HistoryViewModel: ACHudContainer {
|
|||||||
|
|
||||||
let apiService: ApiServiceProtocol
|
let apiService: ApiServiceProtocol
|
||||||
let storageService: StorageServiceProtocol
|
let storageService: StorageServiceProtocol
|
||||||
|
let coordinator: HistoryCoordinator?
|
||||||
|
|
||||||
var hud: ACHud?
|
var hud: ACHud?
|
||||||
|
|
||||||
@ -43,10 +44,12 @@ final class HistoryViewModel: ACHudContainer {
|
|||||||
var dbFileURL: URL?
|
var dbFileURL: URL?
|
||||||
|
|
||||||
init(apiService: ApiServiceProtocol,
|
init(apiService: ApiServiceProtocol,
|
||||||
storageService: StorageServiceProtocol) {
|
storageService: StorageServiceProtocol,
|
||||||
|
coordinator: HistoryCoordinator) {
|
||||||
|
|
||||||
self.apiService = apiService
|
self.apiService = apiService
|
||||||
self.storageService = storageService
|
self.storageService = storageService
|
||||||
|
self.coordinator = coordinator
|
||||||
|
|
||||||
Task { await loadVehicles() }
|
Task { await loadVehicles() }
|
||||||
Task { dbFileURL = await storageService.dbFileURL }
|
Task { dbFileURL = await storageService.dbFileURL }
|
||||||
@ -55,8 +58,12 @@ final class HistoryViewModel: ACHudContainer {
|
|||||||
func loadVehicles() async {
|
func loadVehicles() async {
|
||||||
|
|
||||||
vehicles = await storageService.loadVehicles()
|
vehicles = await storageService.loadVehicles()
|
||||||
vehiclesFiltered = vehicles
|
applyFilters()
|
||||||
vehicleSections = vehiclesFiltered.groupedByDate(type: .updatedDate)
|
}
|
||||||
|
|
||||||
|
func openReport(vehicle: VehicleDto) async {
|
||||||
|
await coordinator?.openReport(vehicle: vehicle)
|
||||||
|
await loadVehicles()
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyFilters() {
|
func applyFilters() {
|
||||||
|
|||||||
@ -45,7 +45,7 @@ struct VehicleCellView: View {
|
|||||||
Spacer(minLength: 8)
|
Spacer(minLength: 8)
|
||||||
|
|
||||||
VStack(alignment: .trailing, spacing: 8) {
|
VStack(alignment: .trailing, spacing: 8) {
|
||||||
if vehicle.updatedDate != vehicle.addedDate {
|
if abs(vehicle.updatedDate - vehicle.addedDate) > 10 {
|
||||||
Text(Formatters.short.string(from: Date(timeIntervalSince1970: vehicle.updatedDate)))
|
Text(Formatters.short.string(from: Date(timeIntervalSince1970: vehicle.updatedDate)))
|
||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
@ -56,6 +56,7 @@ struct VehicleCellView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getForegroundColor() -> Color {
|
func getForegroundColor() -> Color {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user