Skip to content

Commit

Permalink
Fix for survey modal (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi authored Aug 5, 2024
1 parent 35eeb56 commit 49150b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
6 changes: 3 additions & 3 deletions LifeSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 25 additions & 20 deletions LifeSpace/Map/OptionsPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -78,7 +89,7 @@ struct OptionsPanel: View {
.buttonStyle(.borderedProminent)

Button(action: {
self.showingStartSurveyModal = false
self.showingSurveyConfirmation.toggle()
}, label: {
Text("NO")
.padding()
Expand All @@ -88,12 +99,6 @@ struct OptionsPanel: View {
.buttonStyle(.bordered)
}
}

private func launchSurvey() {
if SurveyModule.shouldShowSurvey && !SurveyModule.surveyAlreadyTaken {
self.showingStartSurveyModal = true
}
}
}

#Preview {
Expand Down
5 changes: 3 additions & 2 deletions LifeSpace/Survey/DailySurveyTaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,7 +143,6 @@ struct DailySurveyTaskView: View {
}
}


private func saveResponse(taskResult: ORKTaskResult) async {
var response = DailySurveyResponse()

Expand Down

0 comments on commit 49150b3

Please sign in to comment.