Onboarding screens

OnboardingData object that will hold onboarding answers
This commit is contained in:
Trey t
2022-01-22 12:55:12 -06:00
parent 55bcb460ba
commit 1b82f1d05e
9 changed files with 527 additions and 45 deletions

View File

@@ -11,15 +11,9 @@ struct SettingsView: View {
@Environment(\.dismiss) var dismiss
let editedDataClosure: (() -> Void)
@State private var showOnboarding = false
@AppStorage("notificationDate") private var notificationDate = Date() {
didSet {
if self.showReminder {
LocalNotification.scheduleReminder(atTime: self.notificationDate)
}
}
}
@AppStorage("savedOnboardingData") private var savedOnboardingData = OnboardingData()
@AppStorage("showReminder") private var showReminder: Bool = false
var body: some View {
@@ -29,15 +23,21 @@ struct SettingsView: View {
VStack {
closeButtonView
.padding()
notificationCell
randomShitCell
addTestDataCell
clearDB
whyBackgroundMode
changeIcon
showOnboardingButton
Spacer()
}
.padding()
}.sheet(isPresented: $showOnboarding) {
OnboardingMain(onboardingData: savedOnboardingData,
completionClosure: { onboardingData in
showOnboarding = false
savedOnboardingData = onboardingData
})
}
}
@@ -54,27 +54,6 @@ struct SettingsView: View {
}
}
private var notificationCell: some View {
ZStack {
Color(UIColor.systemBackground)
VStack {
Toggle("Would you like to be reminded?", isOn: $showReminder)
.onChange(of: showReminder, perform: { value in
self.maybeNotificaiotns(areEnabled: value)
})
.padding()
DatePicker("", selection: $notificationDate, displayedComponents: .hourAndMinute)
.onChange(of: notificationDate, perform: { value in
self.updateNotificationTimes(toDate: value)
})
.disabled(showReminder == false)
.padding()
}
}
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
private var randomShitCell: some View {
ZStack {
Color(UIColor.systemBackground)
@@ -179,21 +158,18 @@ struct SettingsView: View {
LocalNotification.scheduleReminder(atTime: date)
}
private func maybeNotificaiotns(areEnabled: Bool) {
if areEnabled {
LocalNotification.testIfEnabled(completion: { result in
switch result{
case .success(_):
LocalNotification.scheduleReminder(atTime: self.notificationDate)
case .failure(let error):
print(error)
// show error
break
}
private var showOnboardingButton: some View {
ZStack {
Color(UIColor.systemBackground)
Button(action: {
showOnboarding.toggle()
}, label: {
Text("Show Onboarding")
})
} else {
LocalNotification.removeNotificaiton()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
}