Added support for event times

notifications nex?
This commit is contained in:
neon443
2025-03-25 20:40:51 +00:00
parent d85ea08ba3
commit 4f36b52548
7 changed files with 59 additions and 26 deletions

View File

@@ -14,8 +14,8 @@
filePath = "NearFuture/Item.swift" filePath = "NearFuture/Item.swift"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "245" startingLineNumber = "248"
endingLineNumber = "245" endingLineNumber = "248"
landmarkName = "importEvents(_:)" landmarkName = "importEvents(_:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>

View File

@@ -16,6 +16,7 @@ struct AddEventView: View {
@Binding var eventColor: Color @Binding var eventColor: Color
@Binding var eventDescription: String @Binding var eventDescription: String
@Binding var eventDate: Date @Binding var eventDate: Date
@Binding var eventTime: Bool
@Binding var eventRecurrence: Event.RecurrenceType @Binding var eventRecurrence: Event.RecurrenceType
@State var adding : Bool @State var adding : Bool
@@ -93,6 +94,15 @@ struct AddEventView: View {
DatePicker("", selection: $eventDate, displayedComponents: .date) DatePicker("", selection: $eventDate, displayedComponents: .date)
.datePickerStyle(WheelDatePickerStyle()) .datePickerStyle(WheelDatePickerStyle())
Toggle("Schedule a Time", isOn: $eventTime)
if eventTime {
DatePicker(
"",
selection: $eventDate,
displayedComponents: .hourAndMinute
)
}
// re-ocurrence Picker // re-ocurrence Picker
Picker("Recurrence", selection: $eventRecurrence) { Picker("Recurrence", selection: $eventRecurrence) {
ForEach(Event.RecurrenceType.allCases, id: \.self) { recurrence in ForEach(Event.RecurrenceType.allCases, id: \.self) { recurrence in
@@ -117,6 +127,7 @@ struct AddEventView: View {
color: ColorCodable(eventColor), color: ColorCodable(eventColor),
description: eventDescription, description: eventDescription,
date: eventDate, date: eventDate,
time: eventTime,
recurrence: eventRecurrence recurrence: eventRecurrence
) )
resetAddEventView() resetAddEventView()
@@ -125,14 +136,14 @@ struct AddEventView: View {
.font(.headline) .font(.headline)
.cornerRadius(10) .cornerRadius(10)
.buttonStyle(BorderedProminentButtonStyle()) .buttonStyle(BorderedProminentButtonStyle())
if eventName.isEmpty {
Text("Give your event a name.")
}
} }
.disabled(eventName.isEmpty) .disabled(eventName.isEmpty)
if eventName.isEmpty { if eventName.isEmpty {
HStack {
Image(systemName: "exclamationmark.circle")
.foregroundStyle(.red)
Text("Give your event a name.") Text("Give your event a name.")
}
} }
} }
} }
@@ -192,22 +203,16 @@ struct MagicClearButton: View {
} }
} }
struct AddEvent_Preview: PreviewProvider { #Preview {
@State static var symbol = "star"
@State static var date = Date()
@State static var color = Color(.red)
static var previews: some View {
AddEventView( AddEventView(
viewModel: EventViewModel(), viewModel: EventViewModel(),
eventName: .constant("Birthday"), eventName: .constant("Birthday"),
eventSymbol: $symbol, eventSymbol: .constant("star"),
eventColor: $color, eventColor: .constant(Color.red),
eventDescription: .constant("A very special day"), eventDescription: .constant("A very special day"),
eventDate: $date, eventDate: .constant(Date()),
eventTime: .constant(true),
eventRecurrence: .constant(.monthly), eventRecurrence: .constant(.monthly),
adding: true adding: true
) )
} }
}

View File

@@ -27,6 +27,7 @@ struct ContentView: View {
].randomElement() ?? Color.red ].randomElement() ?? Color.red
@State private var eventDescription = "" @State private var eventDescription = ""
@State private var eventDate = Date() @State private var eventDate = Date()
@State private var eventTime = false
@State private var eventRecurrence: Event.RecurrenceType = .none @State private var eventRecurrence: Event.RecurrenceType = .none
@State private var showingAddEventView = false @State private var showingAddEventView = false
@State private var searchInput: String = "" @State private var searchInput: String = ""
@@ -122,6 +123,7 @@ struct ContentView: View {
eventColor: $eventColor, eventColor: $eventColor,
eventDescription: $eventDescription, eventDescription: $eventDescription,
eventDate: $eventDate, eventDate: $eventDate,
eventTime: $eventTime,
eventRecurrence: $eventRecurrence, eventRecurrence: $eventRecurrence,
adding: true //adding event adding: true //adding event
) )
@@ -186,7 +188,12 @@ struct EventListView: View {
.font(.subheadline) .font(.subheadline)
.foregroundColor(.gray) .foregroundColor(.gray)
} }
Text(event.date.formatted(date: .long, time: .omitted)) Text(
event.date.formatted(
date: .long,
time: event.time ? .standard : .omitted
)
)
.font(.subheadline) .font(.subheadline)
.foregroundColor(event.color.color) .foregroundColor(event.color.color)
if event.recurrence != .none { if event.recurrence != .none {

View File

@@ -17,6 +17,7 @@ struct EditEventView: View {
@State private var eventColor: Color @State private var eventColor: Color
@State private var eventDescription: String @State private var eventDescription: String
@State private var eventDate: Date @State private var eventDate: Date
@State private var eventTime: Bool
@State private var eventRecurrence: Event.RecurrenceType @State private var eventRecurrence: Event.RecurrenceType
init(viewModel: EventViewModel, event: Binding<Event>) { init(viewModel: EventViewModel, event: Binding<Event>) {
@@ -27,6 +28,7 @@ struct EditEventView: View {
_eventColor = State(initialValue: event.wrappedValue.color.color) _eventColor = State(initialValue: event.wrappedValue.color.color)
_eventDescription = State(initialValue: event.wrappedValue.description) _eventDescription = State(initialValue: event.wrappedValue.description)
_eventDate = State(initialValue: event.wrappedValue.date) _eventDate = State(initialValue: event.wrappedValue.date)
_eventTime = State(initialValue: event.wrappedValue.time)
_eventRecurrence = State(initialValue: event.wrappedValue.recurrence) _eventRecurrence = State(initialValue: event.wrappedValue.recurrence)
} }
@@ -39,6 +41,7 @@ struct EditEventView: View {
eventColor: $eventColor, eventColor: $eventColor,
eventDescription: $eventDescription, eventDescription: $eventDescription,
eventDate: $eventDate, eventDate: $eventDate,
eventTime: $eventTime,
eventRecurrence: $eventRecurrence, eventRecurrence: $eventRecurrence,
adding: false //bc we editing existing event adding: false //bc we editing existing event
) )
@@ -82,6 +85,7 @@ struct EditEventView: View {
color: ColorCodable(.red), color: ColorCodable(.red),
description: "an event", description: "an event",
date: Date(), date: Date(),
time: true,
recurrence: .yearly recurrence: .yearly
) )
) )

View File

@@ -26,6 +26,7 @@ struct Event: Identifiable, Codable {
var color: ColorCodable var color: ColorCodable
var description: String var description: String
var date: Date var date: Date
var time: Bool
var recurrence: RecurrenceType var recurrence: RecurrenceType
enum RecurrenceType: String, Codable, CaseIterable { enum RecurrenceType: String, Codable, CaseIterable {
@@ -159,6 +160,7 @@ class EventViewModel: ObservableObject {
color: ColorCodable, color: ColorCodable,
description: String, description: String,
date: Date, date: Date,
time: Bool,
recurrence: Event.RecurrenceType recurrence: Event.RecurrenceType
) { ) {
let newEvent = Event( let newEvent = Event(
@@ -167,6 +169,7 @@ class EventViewModel: ObservableObject {
color: color, color: color,
description: description, description: description,
date: date, date: date,
time: time,
recurrence: recurrence recurrence: recurrence
) )
events.append(newEvent) events.append(newEvent)

View File

@@ -142,6 +142,7 @@ struct Widget_Previews: PreviewProvider {
color: ColorCodable(.blue), color: ColorCodable(.blue),
description: "Event description", description: "Event description",
date: Date.distantFuture, date: Date.distantFuture,
time: false,
recurrence: .yearly recurrence: .yearly
), ),
Event( Event(
@@ -150,6 +151,7 @@ struct Widget_Previews: PreviewProvider {
color: ColorCodable(.orange), color: ColorCodable(.orange),
description: "description", description: "description",
date: Date(), date: Date(),
time: false,
recurrence: .daily recurrence: .daily
), ),
Event( Event(
@@ -158,6 +160,7 @@ struct Widget_Previews: PreviewProvider {
color: ColorCodable(.orange), color: ColorCodable(.orange),
description: "description", description: "description",
date: Date(), date: Date(),
time: false,
recurrence: .daily recurrence: .daily
), ),
Event( Event(
@@ -166,6 +169,7 @@ struct Widget_Previews: PreviewProvider {
color: ColorCodable(.orange), color: ColorCodable(.orange),
description: "description", description: "description",
date: Date(), date: Date(),
time: false,
recurrence: .daily recurrence: .daily
), ),
Event( Event(
@@ -174,7 +178,17 @@ struct Widget_Previews: PreviewProvider {
color: ColorCodable(.orange), color: ColorCodable(.orange),
description: "description", description: "description",
date: Date(), date: Date(),
time: false,
recurrence: .daily 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 { static var previews: some View {