Opening report from history
This commit is contained in:
parent
a7f4e6b3c5
commit
bc88a7bb0e
@ -11,7 +11,7 @@ import SwiftUI
|
||||
import AutoCatCore
|
||||
|
||||
@MainActor
|
||||
class HistoryCoordinator {
|
||||
final class HistoryCoordinator {
|
||||
|
||||
var navController: UINavigationController?
|
||||
|
||||
@ -20,7 +20,8 @@ class HistoryCoordinator {
|
||||
let resolver = ServiceContainer.shared
|
||||
let viewModel = HistoryViewModel(
|
||||
apiService: resolver.resolve(ApiServiceProtocol.self),
|
||||
storageService: resolver.resolve(StorageServiceProtocol.self)
|
||||
storageService: resolver.resolve(StorageServiceProtocol.self),
|
||||
coordinator: self
|
||||
)
|
||||
|
||||
let view = HistoryScreen(viewModel: viewModel)
|
||||
@ -31,4 +32,12 @@ class HistoryCoordinator {
|
||||
|
||||
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)) {
|
||||
ForEach(section.elements) { vehicle in
|
||||
VehicleCellView(vehicle: vehicle)
|
||||
.onTapGesture {
|
||||
Task { await viewModel.openReport(vehicle: vehicle) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ final class HistoryViewModel: ACHudContainer {
|
||||
|
||||
let apiService: ApiServiceProtocol
|
||||
let storageService: StorageServiceProtocol
|
||||
let coordinator: HistoryCoordinator?
|
||||
|
||||
var hud: ACHud?
|
||||
|
||||
@ -43,10 +44,12 @@ final class HistoryViewModel: ACHudContainer {
|
||||
var dbFileURL: URL?
|
||||
|
||||
init(apiService: ApiServiceProtocol,
|
||||
storageService: StorageServiceProtocol) {
|
||||
storageService: StorageServiceProtocol,
|
||||
coordinator: HistoryCoordinator) {
|
||||
|
||||
self.apiService = apiService
|
||||
self.storageService = storageService
|
||||
self.coordinator = coordinator
|
||||
|
||||
Task { await loadVehicles() }
|
||||
Task { dbFileURL = await storageService.dbFileURL }
|
||||
@ -55,8 +58,12 @@ final class HistoryViewModel: ACHudContainer {
|
||||
func loadVehicles() async {
|
||||
|
||||
vehicles = await storageService.loadVehicles()
|
||||
vehiclesFiltered = vehicles
|
||||
vehicleSections = vehiclesFiltered.groupedByDate(type: .updatedDate)
|
||||
applyFilters()
|
||||
}
|
||||
|
||||
func openReport(vehicle: VehicleDto) async {
|
||||
await coordinator?.openReport(vehicle: vehicle)
|
||||
await loadVehicles()
|
||||
}
|
||||
|
||||
func applyFilters() {
|
||||
|
||||
@ -45,7 +45,7 @@ struct VehicleCellView: View {
|
||||
Spacer(minLength: 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)))
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
@ -56,6 +56,7 @@ struct VehicleCellView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
|
||||
func getForegroundColor() -> Color {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user