Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for survey modal #34

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading