-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSafetyLogDetailView.swift
More file actions
154 lines (131 loc) · 4.64 KB
/
SafetyLogDetailView.swift
File metadata and controls
154 lines (131 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// SafetyLogDetailView.swift
// berkeley-mobile
//
// Created by Justin Wong on 11/18/24.
// Copyright © 2024 ASUC OCTO. All rights reserved.
//
import MapKit
import SwiftUI
struct SafetyLogDetailView: View {
@EnvironmentObject var safetyViewModel: SafetyViewModel
@Binding var selectedSafetyLog: BMSafetyLog?
@Binding var drawerViewState: BMDrawerViewState
var body: some View {
VStack {
if #unavailable(iOS 26.0) {
HStack {
closeButton
Spacer()
}
.padding(.bottom, 10)
}
ScrollView(.vertical) {
if let selectedSafetyLog = selectedSafetyLog {
let mapRegion = MKCoordinateRegion(center: selectedSafetyLog.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
Group {
Map(coordinateRegion: .constant(mapRegion), annotationItems: [selectedSafetyLog]) { safetyLog in
MapPin(coordinate: safetyLog.coordinate)
}
}
.allowsHitTesting(false)
.frame(height: 250)
.frame(minWidth: 300, maxWidth: 500)
.clipShape(RoundedRectangle(cornerRadius: 10))
.shadow(color: .gray.opacity(0.5), radius: 7)
.padding()
SafetyLogView(safetyLog: selectedSafetyLog, isPresentingFullScreen: true)
}
}
}
}
private var closeButton: some View {
Button(action: {
withAnimation {
drawerViewState = .small
selectedSafetyLog = nil
}
}) {
// TODO: Make into own custom view if future calls
Image(systemName: "xmark.circle.fill")
.font(.system(size: 35))
.foregroundStyle(.gray)
}
}
}
// MARK: - SafetyLogView
struct SafetyLogView: View {
@EnvironmentObject private var viewModel: SafetyViewModel
var safetyLog: BMSafetyLog
var isPresentingFullScreen: Bool
var body: some View {
if isPresentingFullScreen {
mainBody
} else {
RoundedRectangle(cornerRadius: 10)
.stroke(viewModel.crimeInfos[safetyLog.getSafetyLogState]?.color ?? .gray.opacity(0.6), lineWidth: 1)
.frame(minWidth: 300, maxWidth: 500, minHeight: 200)
.overlay(
mainBody
)
.padding()
}
}
private var mainBody: some View {
VStack(alignment: .leading, spacing: 10) {
Group {
logTitle
logDateAndTime
logLocationView
}
Text(safetyLog.detail)
.font(Font(BMFont.regular(12)))
.font(.caption)
.foregroundStyle(.secondary)
}
.padding()
}
private var logTitle: some View {
HStack {
Text(safetyLog.crime.capitalized)
.font(Font(BMFont.regular(23)))
.bold()
.font(.title2)
Spacer()
}
}
@ViewBuilder
private var logDateAndTime: some View {
Text(getSafetyLogDateString())
.font(Font(BMFont.regular(17)))
.font(.subheadline)
}
private var logLocationView: some View {
HStack {
Image(systemName: "mappin.and.ellipse")
Text(safetyLog.location.capitalized)
.font(Font(BMFont.regular(14)))
.font(.caption)
.bold()
}
.foregroundStyle(.green)
}
private func getSafetyLogDateString() -> String {
let date = safetyLog.date
let dayOfTheWeek = DayOfWeek.weekday(date)
if date.isWithinPastWeek() {
return "\(dayOfTheWeek.stringRepresentation(includesYesterdayTodayVerbage: true)) at \(date.formatted(date: .omitted, time: .shortened))"
}
return date.formatted(date: .abbreviated, time: .shortened)
}
}
#Preview("SafetyLogDetailView") {
SafetyLogDetailView(selectedSafetyLog: .constant(SafetyViewModel.getSampleSafetyLog()), drawerViewState: .constant(.small))
.padding()
.environmentObject(SafetyViewModel())
}
#Preview("SafetyLogView") {
SafetyLogView(safetyLog: SafetyViewModel.getSampleSafetyLog(), isPresentingFullScreen: false)
.padding()
.environmentObject(SafetyViewModel())
}