diff --git a/NearFuture.xcodeproj/project.xcworkspace/xcuserdata/neon443.xcuserdatad/UserInterfaceState.xcuserstate b/NearFuture.xcodeproj/project.xcworkspace/xcuserdata/neon443.xcuserdatad/UserInterfaceState.xcuserstate index 404c36b..c3d9f55 100644 Binary files a/NearFuture.xcodeproj/project.xcworkspace/xcuserdata/neon443.xcuserdatad/UserInterfaceState.xcuserstate and b/NearFuture.xcodeproj/project.xcworkspace/xcuserdata/neon443.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/NearFuture.xcodeproj/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/NearFuture.xcodeproj/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index c3006bd..cba1885 100644 --- a/NearFuture.xcodeproj/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/NearFuture.xcodeproj/xcuserdata/neon443.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -14,8 +14,8 @@ filePath = "NearFuture/Item.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "245" - endingLineNumber = "245" + startingLineNumber = "248" + endingLineNumber = "248" landmarkName = "importEvents(_:)" landmarkType = "7"> diff --git a/NearFuture/AddEventView.swift b/NearFuture/AddEventView.swift index adce4ba..4fac805 100644 --- a/NearFuture/AddEventView.swift +++ b/NearFuture/AddEventView.swift @@ -16,6 +16,7 @@ struct AddEventView: View { @Binding var eventColor: Color @Binding var eventDescription: String @Binding var eventDate: Date + @Binding var eventTime: Bool @Binding var eventRecurrence: Event.RecurrenceType @State var adding : Bool @@ -93,6 +94,15 @@ struct AddEventView: View { DatePicker("", selection: $eventDate, displayedComponents: .date) .datePickerStyle(WheelDatePickerStyle()) + Toggle("Schedule a Time", isOn: $eventTime) + if eventTime { + DatePicker( + "", + selection: $eventDate, + displayedComponents: .hourAndMinute + ) + } + // re-ocurrence Picker Picker("Recurrence", selection: $eventRecurrence) { ForEach(Event.RecurrenceType.allCases, id: \.self) { recurrence in @@ -117,6 +127,7 @@ struct AddEventView: View { color: ColorCodable(eventColor), description: eventDescription, date: eventDate, + time: eventTime, recurrence: eventRecurrence ) resetAddEventView() @@ -125,14 +136,14 @@ struct AddEventView: View { .font(.headline) .cornerRadius(10) .buttonStyle(BorderedProminentButtonStyle()) - if eventName.isEmpty { - Text("Give your event a name.") - } } .disabled(eventName.isEmpty) if eventName.isEmpty { - Text("Give your event a name.") - + HStack { + Image(systemName: "exclamationmark.circle") + .foregroundStyle(.red) + Text("Give your event a name.") + } } } } @@ -192,22 +203,16 @@ struct MagicClearButton: View { } } -struct AddEvent_Preview: PreviewProvider { - @State static var symbol = "star" - @State static var date = Date() - @State static var color = Color(.red) - - static var previews: some View { - AddEventView( - viewModel: EventViewModel(), - eventName: .constant("Birthday"), - eventSymbol: $symbol, - eventColor: $color, - eventDescription: .constant("A very special day"), - eventDate: $date, - eventRecurrence: .constant(.monthly), - adding: true - ) - } +#Preview { + AddEventView( + viewModel: EventViewModel(), + eventName: .constant("Birthday"), + eventSymbol: .constant("star"), + eventColor: .constant(Color.red), + eventDescription: .constant("A very special day"), + eventDate: .constant(Date()), + eventTime: .constant(true), + eventRecurrence: .constant(.monthly), + adding: true + ) } - diff --git a/NearFuture/ContentView.swift b/NearFuture/ContentView.swift index cb1f97b..c6b8ef2 100644 --- a/NearFuture/ContentView.swift +++ b/NearFuture/ContentView.swift @@ -27,6 +27,7 @@ struct ContentView: View { ].randomElement() ?? Color.red @State private var eventDescription = "" @State private var eventDate = Date() + @State private var eventTime = false @State private var eventRecurrence: Event.RecurrenceType = .none @State private var showingAddEventView = false @State private var searchInput: String = "" @@ -122,6 +123,7 @@ struct ContentView: View { eventColor: $eventColor, eventDescription: $eventDescription, eventDate: $eventDate, + eventTime: $eventTime, eventRecurrence: $eventRecurrence, adding: true //adding event ) @@ -186,7 +188,12 @@ struct EventListView: View { .font(.subheadline) .foregroundColor(.gray) } - Text(event.date.formatted(date: .long, time: .omitted)) + Text( + event.date.formatted( + date: .long, + time: event.time ? .standard : .omitted + ) + ) .font(.subheadline) .foregroundColor(event.color.color) if event.recurrence != .none { diff --git a/NearFuture/EditEventView.swift b/NearFuture/EditEventView.swift index 6c7c882..0a2c89d 100644 --- a/NearFuture/EditEventView.swift +++ b/NearFuture/EditEventView.swift @@ -17,6 +17,7 @@ struct EditEventView: View { @State private var eventColor: Color @State private var eventDescription: String @State private var eventDate: Date + @State private var eventTime: Bool @State private var eventRecurrence: Event.RecurrenceType init(viewModel: EventViewModel, event: Binding) { @@ -27,6 +28,7 @@ struct EditEventView: View { _eventColor = State(initialValue: event.wrappedValue.color.color) _eventDescription = State(initialValue: event.wrappedValue.description) _eventDate = State(initialValue: event.wrappedValue.date) + _eventTime = State(initialValue: event.wrappedValue.time) _eventRecurrence = State(initialValue: event.wrappedValue.recurrence) } @@ -39,6 +41,7 @@ struct EditEventView: View { eventColor: $eventColor, eventDescription: $eventDescription, eventDate: $eventDate, + eventTime: $eventTime, eventRecurrence: $eventRecurrence, adding: false //bc we editing existing event ) @@ -82,6 +85,7 @@ struct EditEventView: View { color: ColorCodable(.red), description: "an event", date: Date(), + time: true, recurrence: .yearly ) ) diff --git a/NearFuture/Item.swift b/NearFuture/Item.swift index bdddc41..2771edf 100644 --- a/NearFuture/Item.swift +++ b/NearFuture/Item.swift @@ -26,6 +26,7 @@ struct Event: Identifiable, Codable { var color: ColorCodable var description: String var date: Date + var time: Bool var recurrence: RecurrenceType enum RecurrenceType: String, Codable, CaseIterable { @@ -159,6 +160,7 @@ class EventViewModel: ObservableObject { color: ColorCodable, description: String, date: Date, + time: Bool, recurrence: Event.RecurrenceType ) { let newEvent = Event( @@ -167,6 +169,7 @@ class EventViewModel: ObservableObject { color: color, description: description, date: date, + time: time, recurrence: recurrence ) events.append(newEvent) diff --git a/NearFutureWidgets/NearFutureWidgets.swift b/NearFutureWidgets/NearFutureWidgets.swift index cefacc8..13e77ab 100644 --- a/NearFutureWidgets/NearFutureWidgets.swift +++ b/NearFutureWidgets/NearFutureWidgets.swift @@ -142,6 +142,7 @@ struct Widget_Previews: PreviewProvider { color: ColorCodable(.blue), description: "Event description", date: Date.distantFuture, + time: false, recurrence: .yearly ), Event( @@ -150,6 +151,7 @@ struct Widget_Previews: PreviewProvider { color: ColorCodable(.orange), description: "description", date: Date(), + time: false, recurrence: .daily ), Event( @@ -158,6 +160,7 @@ struct Widget_Previews: PreviewProvider { color: ColorCodable(.orange), description: "description", date: Date(), + time: false, recurrence: .daily ), Event( @@ -166,6 +169,7 @@ struct Widget_Previews: PreviewProvider { color: ColorCodable(.orange), description: "description", date: Date(), + time: false, recurrence: .daily ), Event( @@ -174,7 +178,17 @@ struct Widget_Previews: PreviewProvider { color: ColorCodable(.orange), description: "description", date: Date(), + time: false, recurrence: .daily + ), + Event( + name: "time event", + symbol: "", + color: ColorCodable(.blue), + description: "an event with a time", + date: Date(), + time: true, + recurrence: .none ) ] static var previews: some View {