Skip to content

Commit

Permalink
[#35] Add survey quit dialog and navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Feb 6, 2023
1 parent 63a1d8c commit a52c982
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extension RouteCoordinator: SurveySelectionCoordinator {
extension RouteCoordinator: SurveyDetailCoordinator {

func backToHome() {
guard routes.count > 1 else { return }
withoutAnimation {
self.routes.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct SurveyDetailView: View {
@State var questionIndex = 0
// TODO: Replace with real answer object
@State var currentAnswers = [String]()
@State var isShowingQuitPrompt = false

var body: some View {
ZStack {
Expand All @@ -48,9 +49,12 @@ struct SurveyDetailView: View {
}
}
.loadingDialog(loading: $dataSource.isLoading)
.alert(isPresented: $dataSource.isShowingErrorAlert, content: {
.alert(isPresented: $dataSource.isShowingErrorAlert) {
Alert(title: Text(dataSource.viewState.error))
})
}
.alert(isPresented: $isShowingQuitPrompt) {
quitAlert
}
}

var surveyView: some View {
Expand Down Expand Up @@ -134,15 +138,33 @@ struct SurveyDetailView: View {

var closeButton: some View {
Button {
// TODO: Implement close button
didPressBack()
isShowingQuitPrompt = true
} label: {
Assets.closeButton
.image
.resizable()
.frame(width: 28.0, height: 28.0)
.accessibility(.surveyQuestion(.closeButton))
}
.disabled(isAnimating)
}

var quitAlert: Alert {
Alert(
title: Text(String.localizeId.survey_quit_title()),
message: Text(String.localizeId.survey_quit_message()),
primaryButton: .default(
Text(String.localizeId.survey_quit_confirm())
) {
didPressBack()
},
secondaryButton: .cancel(
Text(String.localizeId.survey_quit_cancel())
.bold()
) {
isShowingQuitPrompt = false
}
)
}

init(survey: SurveyUiModel, coordinator: SurveyDetailCoordinator) {
Expand Down
4 changes: 4 additions & 0 deletions shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<string name="reset_password_success_notification_message">We’ve email you instructions to reset your password.</string>
<string name="account_logout_button">Logout</string>
<string name="survey_detail_start_button">Start Survey</string>
<string name="survey_quit_title">Warning!</string>
<string name="survey_quit_message">Are you sure you want to quit the survey?</string>
<string name="survey_quit_confirm">Yes</string>
<string name="survey_quit_cancel">Cancel</string>
</resources>

0 comments on commit a52c982

Please sign in to comment.