78 lines
1.9 KiB
Swift
78 lines
1.9 KiB
Swift
//
|
|
// EventsScreen.swift
|
|
// AutoCat
|
|
//
|
|
// Created by Selim Mustafaev on 10.12.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AutoCatCore
|
|
import MapKit
|
|
|
|
struct EventsScreen: View {
|
|
|
|
@State var viewModel: EventsViewModel
|
|
|
|
init(viewModel: EventsViewModel) {
|
|
self.viewModel = viewModel
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack{
|
|
map
|
|
.zIndex(viewModel.mode == .map ? 1 : 0)
|
|
list
|
|
.zIndex(viewModel.mode == .list ? 1 : 0)
|
|
}
|
|
.hud($viewModel.hud)
|
|
.navigationTitle(viewModel.vehicle.number)
|
|
.toolbar {
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Button("", systemImage: "plus") {
|
|
Task { await viewModel.addNewEvent() }
|
|
}
|
|
}
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Button("", systemImage: viewModel.mode.switchIcon) {
|
|
viewModel.mode.toggle()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var map: some View {
|
|
Map {
|
|
ForEach(viewModel.events.map(\.marker)) {
|
|
Marker($0.date, coordinate: $0.coordinate)
|
|
}
|
|
}
|
|
}
|
|
|
|
var list: some View {
|
|
List {
|
|
ForEach(viewModel.events) { event in
|
|
makeEventCell(for: event)
|
|
}
|
|
}
|
|
.listStyle(.inset)
|
|
}
|
|
|
|
func makeEventCell(for event: EventModel) -> some View {
|
|
HStack {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(event.address)
|
|
Text(event.marker.date)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Spacer()
|
|
Image(systemName: event.isMe ? "person.fill" : "person")
|
|
.foregroundStyle(event.isMe ? Color.accentColor : .secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
EventsScreen(viewModel: .init(vehicle: .preview))
|
|
}
|