@@ -79,48 +79,8 @@ struct AccountSheet: View {
7979 }
8080 }
8181 if let enrollment = enrollments. first {
82- Section ( " Study Participation " ) { // swiftlint:disable:this closure_body_length
83- Button {
84- openUrl ( MyHeartCounts . website ( ) )
85- } label: {
86- HStack {
87- makeEnrolledStudyRow ( for: enrollment)
88- Spacer ( )
89- DisclosureIndicator ( )
90- }
91- . contentShape ( Rectangle ( ) )
92- . foregroundStyle ( colorScheme. textLabelForegroundStyle)
93- }
94- NavigationLink ( " Review Consent Forms " ) {
95- SignedConsentForms ( )
96- }
97- if let text = { ( ) -> LocalizedStringResource ? in
98- switch ( isProcessingHealthData, isProcessingSensorKitData) {
99- case ( true , true ) :
100- " Processing Health and SensorKit Data… "
101- case ( true , false ) :
102- " Processing Health Data… "
103- case ( false , true ) :
104- " Processing SensorKit Data… "
105- case ( false , false ) :
106- nil
107- }
108- } ( ) {
109- let label = HStack {
110- Text ( text)
111- Spacer ( )
112- ProgressView ( )
113- }
114- if debugModeEnabled {
115- NavigationLink {
116- DataProcessingDebugView ( )
117- } label: {
118- label
119- }
120- } else {
121- label
122- }
123- }
82+ Section ( " Study Participation " ) {
83+ studyParticipationSection ( enrollment)
12484 }
12585 }
12686 Section {
@@ -170,6 +130,52 @@ struct AccountSheet: View {
170130 }
171131
172132
133+ @ViewBuilder
134+ private func studyParticipationSection( _ enrollment: StudyEnrollment ) -> some View {
135+ Button {
136+ openUrl ( MyHeartCounts . website ( ) )
137+ } label: {
138+ HStack {
139+ makeEnrolledStudyRow ( for: enrollment)
140+ Spacer ( )
141+ DisclosureIndicator ( )
142+ }
143+ . contentShape ( Rectangle ( ) )
144+ . foregroundStyle ( colorScheme. textLabelForegroundStyle)
145+ }
146+ PostTrialNudgesToggle ( )
147+ NavigationLink ( " Review Consent Forms " ) {
148+ SignedConsentForms ( )
149+ }
150+ if let text = { ( ) -> LocalizedStringResource ? in
151+ switch ( isProcessingHealthData, isProcessingSensorKitData) {
152+ case ( true , true ) :
153+ " Processing Health and SensorKit Data… "
154+ case ( true , false ) :
155+ " Processing Health Data… "
156+ case ( false , true ) :
157+ " Processing SensorKit Data… "
158+ case ( false , false ) :
159+ nil
160+ }
161+ } ( ) {
162+ let label = HStack {
163+ Text ( text)
164+ Spacer ( )
165+ ProgressView ( )
166+ }
167+ if debugModeEnabled {
168+ NavigationLink {
169+ DataProcessingDebugView ( )
170+ } label: {
171+ label
172+ }
173+ } else {
174+ label
175+ }
176+ }
177+ }
178+
173179 @ViewBuilder
174180 private func makeEnrolledStudyRow( for enrollment: StudyEnrollment ) -> some View {
175181 if let studyInfo = enrollment. studyBundle? . studyDefinition. metadata {
@@ -198,6 +204,49 @@ struct AccountSheet: View {
198204}
199205
200206
207+ extension AccountSheet {
208+ private struct PostTrialNudgesToggle : View {
209+ @Environment ( Account . self)
210+ private var account
211+
212+ @State private var value = false
213+ @State private var updateTask : Task < Void , Never > ?
214+ @State private var shouldHandleUpdates = true
215+
216+ var body : some View {
217+ Toggle ( isOn: $value) {
218+ VStack ( alignment: . leading) {
219+ Text ( " POST_TRIAL_ACTIVITY_NUDGES_TOGGLE_TITLE " )
220+ Text ( " POST_TRIAL_ACTIVITY_NUDGES_TOGGLE_SUBTITLE " )
221+ . font ( . footnote)
222+ . foregroundStyle ( . secondary)
223+ }
224+ }
225+ . onChange ( of: account. details? . postTrialNudgesOptIn ?? false , initial: true ) { _, newValue in
226+ shouldHandleUpdates = false
227+ value = newValue
228+ shouldHandleUpdates = true
229+ }
230+ . onChange ( of: value) { _, newValue in
231+ updateTask? . cancel ( )
232+ guard shouldHandleUpdates else {
233+ return
234+ }
235+ updateTask = Task {
236+ do {
237+ try await Task . sleep ( for: . seconds( 0.25 ) )
238+ var details = AccountDetails ( )
239+ details. postTrialNudgesOptIn = newValue
240+ try await account. accountService. updateAccountDetails ( AccountModifications ( modifiedDetails: details) )
241+ } catch {
242+ // we silently ignore the error here
243+ }
244+ }
245+ }
246+ }
247+ }
248+ }
249+
201250extension AccountSheet {
202251 private struct AboutRow : View {
203252 // swiftlint:disable attributes
0 commit comments