This commit is contained in:
Trey t
2022-01-22 13:57:25 -06:00
parent 4486ed1306
commit 01e54d9373
9 changed files with 106 additions and 37 deletions

View File

@@ -9,9 +9,12 @@ import Foundation
import UserNotifications
import UIKit
import WidgetKit
import SwiftUI
// AppDelegate.swift
class AppDelegate: NSObject, UIApplicationDelegate {
@AppStorage("savedOnboardingData") private var savedOnboardingData = OnboardingData()
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// PersistenceController.shared.clearDB()
application.registerForRemoteNotifications()
@@ -29,17 +32,27 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if let action = LocalNotification.ActionType(rawValue: response.actionIdentifier) {
var date: Date
switch savedOnboardingData.inputDay {
case .Today:
date = Date()
case .Previous:
date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
}
switch action {
case .horrible:
PersistenceController.shared.add(mood: .horrible, forDate: Date())
PersistenceController.shared.add(mood: .horrible, forDate: date)
case .bad:
PersistenceController.shared.add(mood: .bad, forDate: Date())
PersistenceController.shared.add(mood: .bad, forDate: date)
case .average:
PersistenceController.shared.add(mood: .average, forDate: Date())
PersistenceController.shared.add(mood: .average, forDate: date)
case .good:
PersistenceController.shared.add(mood: .good, forDate: Date())
PersistenceController.shared.add(mood: .good, forDate: date)
case .great:
PersistenceController.shared.add(mood: .great, forDate: Date())
PersistenceController.shared.add(mood: .great, forDate: date)
}
}
WidgetCenter.shared.reloadAllTimelines()