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"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "245"
endingLineNumber = "245"
startingLineNumber = "248"
endingLineNumber = "248"
landmarkName = "importEvents(_:)"
landmarkType = "7">
</BreakpointContent>

View File

@@ -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 {
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 {
#Preview {
AddEventView(
viewModel: EventViewModel(),
eventName: .constant("Birthday"),
eventSymbol: $symbol,
eventColor: $color,
eventSymbol: .constant("star"),
eventColor: .constant(Color.red),
eventDescription: .constant("A very special day"),
eventDate: $date,
eventDate: .constant(Date()),
eventTime: .constant(true),
eventRecurrence: .constant(.monthly),
adding: true
)
}
}

View File

@@ -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 {

View File

@@ -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<Event>) {
@@ -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
)
)

View File

@@ -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)

View File

@@ -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 {