Skip to content

Commit

Permalink
style: prepare for public release
Browse files Browse the repository at this point in the history
  • Loading branch information
Parcley27 committed Jun 3, 2024
1 parent bf22f92 commit 24bd225
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 95 deletions.
4 changes: 0 additions & 4 deletions Timely.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
6EAEA0262B0196E50029A8D4 /* EventListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EAEA0252B0196E50029A8D4 /* EventListView.swift */; };
6EAEA0282B0196FC0029A8D4 /* NewEventSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EAEA0272B0196FC0029A8D4 /* NewEventSheetView.swift */; };
6EAEA02C2B0197270029A8D4 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EAEA02B2B0197270029A8D4 /* SettingsView.swift */; };
6ED5B6682BD3853200B0A728 /* DayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ED5B6672BD3853200B0A728 /* DayView.swift */; };
6EE9B5182B64E8C4005895DC /* EditEventSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE9B5172B64E8C4005895DC /* EditEventSheetView.swift */; };
6EF4F6CD2BB292C000288AE3 /* CalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EF4F6CC2BB292C000288AE3 /* CalendarView.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -63,7 +62,6 @@
6EAEA0252B0196E50029A8D4 /* EventListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventListView.swift; sourceTree = "<group>"; };
6EAEA0272B0196FC0029A8D4 /* NewEventSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventSheetView.swift; sourceTree = "<group>"; };
6EAEA02B2B0197270029A8D4 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
6ED5B6672BD3853200B0A728 /* DayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayView.swift; sourceTree = "<group>"; };
6EE9B5172B64E8C4005895DC /* EditEventSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditEventSheetView.swift; sourceTree = "<group>"; };
6EF4F6CC2BB292C000288AE3 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -174,7 +172,6 @@
isa = PBXGroup;
children = (
6EF4F6CC2BB292C000288AE3 /* CalendarView.swift */,
6ED5B6672BD3853200B0A728 /* DayView.swift */,
6EE9B5172B64E8C4005895DC /* EditEventSheetView.swift */,
6EAEA0232B0196C30029A8D4 /* EventDetailView.swift */,
6EAEA0252B0196E50029A8D4 /* EventListView.swift */,
Expand Down Expand Up @@ -316,7 +313,6 @@
buildActionMask = 2147483647;
files = (
6EF4F6CD2BB292C000288AE3 /* CalendarView.swift in Sources */,
6ED5B6682BD3853200B0A728 /* DayView.swift in Sources */,
6EAEA0282B0196FC0029A8D4 /* NewEventSheetView.swift in Sources */,
6EA0FCA42BFB0EA000981724 /* SettingsStore.swift in Sources */,
6EAEA0222B0196A90029A8D4 /* EventData.swift in Sources */,
Expand Down
40 changes: 25 additions & 15 deletions Timely/Data/EventData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Event : Identifiable, Codable {
let currentDate = Date()
let oneDayInSeconds: TimeInterval = 24 * 60 * 60
return currentDate.addingTimeInterval(oneDayInSeconds)

}()

var dateString: String? {
Expand All @@ -34,10 +35,11 @@ struct Event : Identifiable, Codable {
dateFormatter.timeStyle = .short

dateFormatter.dateFormat = "h:mm a 'on' EEEE, MMMM d, yyyy"

let formattedDate = dateFormatter.string(from: dateAndTime)

return formattedDate

}

var timeUntil: String {
Expand All @@ -61,8 +63,10 @@ struct Event : Identifiable, Codable {

if let formattedString = formatter.string(from: timeInterval) {
return formattedString

} else {
return "Time Until Date"

}
}

Expand All @@ -71,8 +75,10 @@ struct Event : Identifiable, Codable {

if timeInterval <= 0.0 {
return true

} else {
return false

}
}

Expand All @@ -94,28 +100,29 @@ struct Event : Identifiable, Codable {
var id = UUID()
}


// Should be hidden probably
// ^^^ Where did this come from????
extension EventData {
func removeEvent(event: Event) {
if let index = events.firstIndex(where: {$0.id == event.id}) {
events.remove(at: index)

}
}

func updateEventName(event: Event, newName: String) {
if let index = events.firstIndex(where: {$0.id == event.id}) {
events[index].name = newName

}
}

func toggleFavouriteEvent(event: Event) {
if let index = events.firstIndex(where: {$0.id == event.id}) {
if events[index].isFavourite == true {
events[index].isFavourite = false

} else {
events[index].isFavourite = true

}
}
}
Expand All @@ -124,8 +131,10 @@ extension EventData {
if let index = events.firstIndex(where: {$0.id == event.id}) {
if events[index].isMuted == true {
events[index].isMuted = false

} else {
events[index].isMuted = true

}
}
}
Expand All @@ -138,18 +147,22 @@ extension EventData {
if format == "Full Date" {
formatter.unitsStyle = .abbreviated
formatter.allowedUnits = [.year, .day, .hour, .minute, .second]

}

if format == "Seconds" {
formatter.unitsStyle = .positional
formatter.allowedUnits = [.second]

}

if var formattedString = formatter.string(from: timeInterval) {
formattedString = formattedString.replacingOccurrences(of: ",", with: "")
return formattedString

} else {
return "Time unknown"

}
}

Expand All @@ -163,8 +176,10 @@ extension EventData {

if dateString != "" {
return dateString

} else {
return "Date unknown"

}
}

Expand All @@ -174,26 +189,21 @@ extension EventData {
for event in events {
if event.timeUntil.prefix(1) == "-" {
count += 1

}
}

return count

}

/*
func sortEvents(filter: String? = "Date Ascending") {
if filter == "Date Ascending" {
for event in events {
// Sort by lowest date -> highest date
}
}
}
*/

func indexFor(_ event: Event) -> Double {
if let index = events.firstIndex(where: { $0.id == event.id }) {
return Double(index)

}

return 0.0

}
}
2 changes: 2 additions & 0 deletions Timely/Data/EventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EventStore: ObservableObject {
let fileURL = try Self.fileURL()
guard let data = try? Data(contentsOf: fileURL) else {
return []

}

let loadedEvents = try JSONDecoder().decode([Event].self, from: data)
Expand All @@ -40,6 +41,7 @@ class EventStore: ObservableObject {
let data = try JSONEncoder().encode(events)
let outfile = try Self.fileURL()
try data.write(to: outfile)

}
_ = try await task.value
}
Expand Down
7 changes: 5 additions & 2 deletions Timely/Data/SettingsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ class SettingsStore: ObservableObject {
}

/*
@Published var userName: String {
@Published var stringData: String {
didSet {
UserDefaults.standard.set(userName, forKey: "userName")
UserDefaults.standard.set(stringData, forKey: "stringData")

}
}
*/

init() {
self.showBadge = UserDefaults.standard.object(forKey: "showBadge") as? Bool ?? true
self.deletePassedEvents = UserDefaults.standard.object(forKey: "deletePassedEvents") as? Bool ?? true
//self.stringData = UserDefaults.standard.object(forKey: "stringData") as? String ?? ""

}
}
29 changes: 24 additions & 5 deletions Timely/TimelyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ struct TimelyApp: App {
Circle()
.stroke(.gray, lineWidth: 5.0)
.frame(width: 100)
.background(
.bar,
in: Circle()
)

.background(.bar, in: Circle())

Image(systemName: "plus")
.resizable()
.frame(width: 50.0, height: 50.0)
Expand All @@ -62,22 +59,27 @@ struct TimelyApp: App {
Task {
do {
try await eventList.save(events: eventList.events)

} catch {
fatalError(error.localizedDescription)

}
}
}
.task {
do {
try await eventList.load()
print("Loading events: \(eventList.events)")

} catch {
fatalError(error.localizedDescription)

}
}
.badge(filterPassedEvents(events: eventList.events) != nil ? filterPassedEvents(events: eventList.events)!.count : 0)
.tabItem {
Label("Events", systemImage: "list.bullet")

}
.tag(0)

Expand All @@ -86,17 +88,21 @@ struct TimelyApp: App {
Task {
do {
try await eventList.save(events: eventList.events)

} catch {
fatalError(error.localizedDescription)

}
}
}
.task {
do {
try await eventList.load()
print("Loading events: \(eventList.events)")

} catch {
fatalError(error.localizedDescription)

}
}
.tag(1)
Expand All @@ -105,17 +111,21 @@ struct TimelyApp: App {
Task {
do {
try await eventList.save(events: eventList.events)

} catch {
fatalError(error.localizedDescription)

}
}
}
.task {
do {
try await eventList.load()
print("Loading events: \(eventList.events)")

} catch {
fatalError(error.localizedDescription)

}
}
.tag(1)
Expand All @@ -125,35 +135,42 @@ struct TimelyApp: App {
Task {
do {
try await eventList.save(events: eventList.events)

} catch {
fatalError(error.localizedDescription)

}
}
}
.task {
do {
try await eventList.load()
print("Loading events: \(eventList.events)")

} catch {
fatalError(error.localizedDescription)

}
}
.tabItem {
Label("Calendar", systemImage: "calendar")

}
.tag(2)
}
.onChange(of: selectedTab) { newTab in
if newTab == 0 || newTab == 2 {
lastTab = selectedTab
print(selectedTab)

}

if newTab == 1 {
print(lastTab)
selectedTab = lastTab
print("Switching tab")
print(selectedTab)

}
}

Expand All @@ -163,11 +180,13 @@ struct TimelyApp: App {
.onTapGesture {
print("plus")
showNewSheet = true

}
.position(x: metrics.size.width * 0.5, y: metrics.size.height - 48)
}
.sheet(isPresented: $showNewSheet) {
NewEventSheetView(data: $eventList.events)

}
}
}
Expand Down
Loading

0 comments on commit 24bd225

Please sign in to comment.