11import SwiftUI
22
3+ private struct PreviousReportSharePayload : Identifiable {
4+ let id = UUID ( )
5+ let text : String
6+ }
7+
38struct QuickEntryView : View {
49 @ EnvironmentObject private var model : AppModel
510 @ Environment ( \. dynamicTypeSize ) private var dynamicTypeSize
@@ -13,6 +18,8 @@ struct QuickEntryView: View {
1318 @ State private var isSaving = false
1419 @ State private var didInitializeDate = false
1520 @ State private var bibleStudyFeedback = SelectionHapticFeedback ( )
21+ @ State private var previousReportSharePayload : PreviousReportSharePayload ?
22+ @ State private var isSendingPreviousReport = false
1623 @ FocusState private var noteFocused : Bool
1724
1825 private var previousMonth : MonthKey {
@@ -54,6 +61,11 @@ struct QuickEntryView: View {
5461 . navigationBarTitleDisplayMode ( . inline )
5562 . scrollBounceBehavior ( . basedOnSize )
5663 . scrollDismissesKeyboard ( . interactively )
64+ . sheet ( item : $previousReportSharePayload ) { payload in
65+ ActivityView ( text : payload . text ) { _ in
66+ previousReportSharePayload = nil
67+ }
68+ }
5769 . onChange ( of : model . quickEntryResetGeneration ) { _ , _ in
5870 resetDraft ( )
5971 }
@@ -99,9 +111,7 @@ struct QuickEntryView: View {
99111 monthLabel
100112 )
101113
102- return Button {
103- model . openReport ( previousMonth )
104- } label : {
114+ return VStack ( alignment : . leading , spacing : 10 ) {
105115 HStack ( spacing : 12 ) {
106116 Image ( systemName : state . symbolName )
107117 . foregroundStyle ( Color . accentColor )
@@ -114,16 +124,69 @@ struct QuickEntryView: View {
114124 . foregroundStyle ( . secondary )
115125 }
116126 Spacer ( )
117- Image ( systemName : " chevron.right " ) . foregroundStyle ( . tertiary )
118127 }
119128 . frame ( maxWidth : . infinity , minHeight : 44 , alignment : . leading )
120- . padding ( )
121- . background ( Color . accentColor . opacity ( 0.09 ) , in : RoundedRectangle ( cornerRadius : 18 , style : . continuous ) )
129+
130+ Group {
131+ if dynamicTypeSize . isAccessibilitySize {
132+ VStack ( spacing : 8 ) { previousReportActions ( state , title : title ) }
133+ } else {
134+ HStack ( spacing : 8 ) { previousReportActions ( state , title : title ) }
135+ }
136+ }
137+
138+ Text ( " report.action.send_now_note " )
139+ . font ( . caption )
140+ . foregroundStyle ( . secondary )
141+ }
142+ . padding ( )
143+ . background (
144+ Color . accentColor . opacity ( 0.09 ) ,
145+ in : RoundedRectangle ( cornerRadius : 18 , style : . continuous )
146+ )
147+ }
148+
149+ @ ViewBuilder
150+ private func previousReportActions ( _ state : PreviousReportBannerState , title : String ) -> some View {
151+ Button {
152+ model . openReport ( previousMonth )
153+ } label : {
154+ Text ( state . reviewActionKey )
155+ . frame ( maxWidth : . infinity , minHeight : 44 )
122156 }
123- . buttonStyle ( . plain )
157+ . buttonStyle ( . bordered )
124158 . accessibilityLabel ( Text ( verbatim : title ) )
125159 . accessibilityValue ( Text ( state . statusKey ) )
126160 . accessibilityIdentifier ( " previousReportBanner " )
161+
162+ Button {
163+ sendPreviousReportNow ( )
164+ } label : {
165+ Group {
166+ if isSendingPreviousReport {
167+ ProgressView ( )
168+ } else {
169+ Label ( " report.action.send_now " , systemImage : " paperplane.fill " )
170+ }
171+ }
172+ . frame ( maxWidth : . infinity , minHeight : 44 )
173+ }
174+ . buttonStyle ( . borderedProminent )
175+ . tint ( Color . accentColor )
176+ . disabled ( isSendingPreviousReport )
177+ . accessibilityIdentifier ( " sendPreviousReportNowButton " )
178+ }
179+
180+ private func sendPreviousReportNow ( ) {
181+ guard ! isSendingPreviousReport else { return }
182+ let displayedDraft = model . reportDraft ( for : previousMonth )
183+ isSendingPreviousReport = true
184+
185+ Task { @MainActor in
186+ defer { isSendingPreviousReport = false }
187+ guard let snapshot = await model . sendReportImmediately ( displayedDraft ) else { return }
188+ previousReportSharePayload = PreviousReportSharePayload ( text : snapshot . receipt . text )
189+ }
127190 }
128191
129192 private var entryCard : some View {
@@ -387,6 +450,17 @@ private enum PreviousReportBannerState {
387450 }
388451 }
389452
453+ var reviewActionKey : LocalizedStringKey {
454+ switch self {
455+ case . ready :
456+ " report.action.review "
457+ case . changed :
458+ " report.action.review_correction "
459+ case . reviewed , . prepared :
460+ " report.action.open "
461+ }
462+ }
463+
390464 var symbolName : String {
391465 switch self {
392466 case . ready :
0 commit comments