-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditEventSheet.swift
97 lines (71 loc) · 3.17 KB
/
EditEventSheet.swift
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
//
// EditEventSheet.swift
// Frat Maps
//
// Created by Spencer Byrne on 9/26/22.
//
import SwiftUI
struct EditEventSheet: View {
@Environment (\.dismiss) private var dismiss
@StateObject var event = CreateEventModel()
@StateObject var profanity = NoNaughtyBoys()
@State var title = ""
@State var ratio = ""
@State var date = Date()
@State var duration = ""
@State var endDate = Date()
@State var didChange = false
@State var didDelete = false
var fratID: String
var eventID: String
var body: some View {
let dateString = Date.getStringFromDate(date: date)
NavigationView{
ScrollView(showsIndicators: false){
VStack{
EditEventPreview(fratID: fratID, title: $title, ratio: $ratio, date: $date)
CreateEventOptions(title: $title, ratio: $ratio, date: $date, duration: $duration)
Spacer()
}
Button(action: {
didDelete = event.deleteEvent(fratID: fratID, eventID: eventID)
dismiss()
},label: {
Text("Delete Event")
.bold()
.foregroundColor(.red)
.frame(height: 50)
.frame(maxWidth: .infinity)
.background(.thinMaterial)
.cornerRadius(10)
.padding()
}).alert(isPresented: $didDelete){
Alert(title: Text("Error deleting event"), dismissButton: .default(Text("Try again?")))
}
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button("Save Changes"){
let endDateString = Date.getStringFromDate(date: event.getDuration(timeSelected: duration, startTime: date))
didChange = event.changeEvent(eventID: eventID, title: title, ratio: ratio, fratID: fratID, date: dateString, endDate: endDateString)
dismiss()
}.alert(isPresented: $didChange){
Alert(title: Text("Error uploading event"), dismissButton: .default(Text("Try again?")))
}
.disabled(title.containsBadWord() == true || title == "" || duration == "")
}
ToolbarItem(placement: .cancellationAction){
Button("Cancel"){
dismiss()
}
}
}
}.navigationBarHidden(true)
}
}
struct EditEventSheet_Previews: PreviewProvider {
static var previews: some View {
EditEventSheet(fratID: "Delta Kappa Epsilon", eventID: "4A2D0F04-37D3-45F1-B866-557998D0695B")
}
}