diff --git a/LifeSpace.xcodeproj/project.pbxproj b/LifeSpace.xcodeproj/project.pbxproj index 3b88bc4..278c90c 100644 --- a/LifeSpace.xcodeproj/project.pbxproj +++ b/LifeSpace.xcodeproj/project.pbxproj @@ -804,7 +804,7 @@ CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 12; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -1008,7 +1008,7 @@ CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 12; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -1055,7 +1055,7 @@ CODE_SIGN_ENTITLEMENTS = "LifeSpace/Supporting Files/LifeSpace.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 12; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; diff --git a/LifeSpace/Map/OptionsPanel.swift b/LifeSpace/Map/OptionsPanel.swift index 7bc67cc..41935a6 100644 --- a/LifeSpace/Map/OptionsPanel.swift +++ b/LifeSpace/Map/OptionsPanel.swift @@ -27,9 +27,9 @@ struct OptionsPanel: View { @Environment(\.scenePhase) var scenePhase @Environment(LifeSpaceStandard.self) private var standard - @State private var showingSurveyAlert = false @State private var showingSurvey = false - @State private var showingStartSurveyModal = false + @State private var showingSurveyConfirmation = false + @State private var shouldShowSurvey = false var body: some View { GroupBox { @@ -42,33 +42,44 @@ struct OptionsPanel: View { .frame(maxWidth: .infinity) } .sheet(isPresented: $showingSurvey) { - DailySurveyTaskView(showingSurvey: $showingSurvey) - } - .sheet(isPresented: $showingStartSurveyModal) { - startSurveyModal - .presentationDetents([.medium, .large]) - .presentationDragIndicator(.hidden) + DailySurveyTaskView( + showingSurvey: $showingSurvey + ) } .onChange(of: scenePhase) { _, newPhase in if newPhase == .active { Task { _ = await standard.getLatestSurveyDate() - launchSurvey() + + if SurveyModule.shouldShowSurvey && !SurveyModule.surveyAlreadyTaken { + self.showingSurveyConfirmation = true + } } } } - }.groupBoxStyle(ButtonGroupBoxStyle()) + } + .groupBoxStyle(ButtonGroupBoxStyle()) + .sheet(isPresented: $showingSurveyConfirmation, onDismiss: { + if shouldShowSurvey { + self.showingSurvey.toggle() + self.shouldShowSurvey.toggle() + } + }) { + surveyConfirmationView + .presentationDetents([.medium, .large]) + .presentationDragIndicator(.hidden) + } } - private var startSurveyModal: some View { + private var surveyConfirmationView: some View { VStack { Text("SURVEY_READY_QUESTION") .font(.largeTitle) .multilineTextAlignment(.center) Button(action: { - self.showingSurvey = true - self.showingStartSurveyModal = false + self.showingSurveyConfirmation.toggle() + self.shouldShowSurvey.toggle() }, label: { Text("YES") .padding() @@ -78,7 +89,7 @@ struct OptionsPanel: View { .buttonStyle(.borderedProminent) Button(action: { - self.showingStartSurveyModal = false + self.showingSurveyConfirmation.toggle() }, label: { Text("NO") .padding() @@ -88,12 +99,6 @@ struct OptionsPanel: View { .buttonStyle(.bordered) } } - - private func launchSurvey() { - if SurveyModule.shouldShowSurvey && !SurveyModule.surveyAlreadyTaken { - self.showingStartSurveyModal = true - } - } } #Preview { diff --git a/LifeSpace/Survey/DailySurveyTaskView.swift b/LifeSpace/Survey/DailySurveyTaskView.swift index 6dacc6e..ffe950f 100644 --- a/LifeSpace/Survey/DailySurveyTaskView.swift +++ b/LifeSpace/Survey/DailySurveyTaskView.swift @@ -20,7 +20,9 @@ struct DailySurveyTaskView: View { var body: some View { - if SurveyModule.surveyAlreadyTaken { + if !showingSurvey { + EmptyView() + } else if SurveyModule.surveyAlreadyTaken { surveyTakenView } else if SurveyModule.isPreviousDaySurvey && !acknowledgedPreviousDaySurvey { previousDaySurveyView @@ -141,7 +143,6 @@ struct DailySurveyTaskView: View { } } - private func saveResponse(taskResult: ORKTaskResult) async { var response = DailySurveyResponse()