@@ -35,20 +35,8 @@ struct HomeView: View {
3535 . listStyle ( . insetGrouped)
3636 . navigationTitle ( String ( localized: " nav_home " ) )
3737 . toolbar { toolbar }
38- . sheet ( item: $store. scope ( state: \. sheet, action: \. sheet) ) { sheetStore in
39- switch sheetStore. state {
40- case . reorderTodo:
41- CategoryManageView (
42- preferences: store. preferences,
43- onDismiss: { array in
44- store. send ( . sheet( . dismiss) )
45- store. send ( . orderTodoCategory( array) , animation: . default)
46- }
47- )
48- case . contentPicker:
49- contentPicker
50- }
51- }
38+ . alert ( $store. scope ( state: \. alert, action: \. alert) )
39+ . sheet ( item: $store. scope ( state: \. sheet, action: \. sheet) , content: sheetContent)
5240 . fullScreenCover ( isPresented: Binding (
5341 get: { store. showTodoEditor } ,
5442 set: { store. send ( . setPresentation( . todoEditor, $0) ) }
@@ -69,14 +57,112 @@ struct HomeView: View {
6957 ) ) {
7058 SearchView ( store: coordinator. makeSearchStore ( ) )
7159 }
72- . alert ( $store. scope ( state: \. alert, action: \. alert) )
7360 . overlay {
7461 if store. isAppending {
7562 LoadingView ( )
7663 }
7764 }
7865 }
7966
67+ @ViewBuilder
68+ private func sheetContent( _ sheetStore: Store < HomeFeature . SheetState , HomeFeature . Sheet > ) -> some View {
69+ if sheetStore. state == . contentPicker {
70+ NavigationStack {
71+ List {
72+ Section {
73+ if store. isPreferencesLoading {
74+ LoadingView ( )
75+ } else {
76+ let preferences = store. preferences. filter ( \. isVisible)
77+ ForEach ( preferences, id: \. id) { item in
78+ Button {
79+ DispatchQueue . main. async {
80+ openTodoEditor ( for: item. category)
81+ }
82+ } label: {
83+ labelImage (
84+ text: item. localizedName,
85+ systemName: item. symbolName,
86+ imageColor: item. color
87+ )
88+ }
89+ }
90+ }
91+ } header: {
92+ Text ( " TODO " )
93+ . foregroundStyle ( Color ( . label) )
94+ }
95+
96+ Section {
97+ Button {
98+ store. send ( . tapWebPageInput)
99+ } label: {
100+ labelImage (
101+ text: " URL " ,
102+ systemName: " globe " ,
103+ imageColor: . blue
104+ )
105+ }
106+ } header: {
107+ Text ( " Web Page " )
108+ . foregroundStyle ( Color ( . label) )
109+ }
110+ }
111+ . navigationDestination (
112+ item: $store. scope ( state: \. webPageInput, action: \. webPageInput)
113+ ) { _ in
114+ Form {
115+ Section {
116+ TextField (
117+ " https:// " ,
118+ text: Binding (
119+ get: { store. webPageURLInput } ,
120+ set: { store. send ( . updateWebPageURLInput( $0) ) }
121+ )
122+ )
123+ . textInputAutocapitalization ( . never)
124+ . keyboardType ( . URL)
125+ } footer: {
126+ Text ( String ( localized: " home_webpage_input_message " ) )
127+ }
128+ }
129+ . scrollDisabled ( true )
130+ . toolbar {
131+ ToolbarItem ( placement: . principal) {
132+ Text ( String ( localized: " home_webpage_input_title " ) )
133+ }
134+ ToolbarItem ( placement: . topBarTrailing) {
135+ Button ( String ( localized: " home_add " ) ) {
136+ store. send ( . addWebPage)
137+ }
138+ }
139+ }
140+ }
141+ . toolbar {
142+ ToolbarItem ( placement: . principal) {
143+ Text ( String ( localized: " nav_home_content " ) )
144+ }
145+ ToolbarItem ( placement: . topBarLeading) {
146+ Button {
147+ store. send ( . sheet( . presented( . tapCloseButton) ) )
148+ } label: {
149+ Image ( systemName: " xmark " )
150+ . bold ( )
151+ }
152+ }
153+ }
154+ }
155+ } else {
156+ CategoryManageView (
157+ preferences: store. preferences,
158+ onDismiss: { array in
159+ store. send ( . sheet( . dismiss) )
160+ store. send ( . orderTodoCategory( array) , animation: . default)
161+ }
162+ )
163+ }
164+ }
165+
80166 private var todoSection : some View {
81167 Section ( content: {
82168 if store. isPreferencesLoading {
@@ -269,101 +355,6 @@ struct HomeView: View {
269355 }
270356 }
271357
272- private var contentPicker : some View {
273- NavigationStack {
274- List {
275- Section {
276- if store. isPreferencesLoading {
277- LoadingView ( )
278- } else {
279- let preferences = store. preferences. filter ( \. isVisible)
280- ForEach ( preferences, id: \. id) { item in
281- Button {
282- DispatchQueue . main. async {
283- openTodoEditor ( for: item. category)
284- }
285- } label: {
286- labelImage (
287- text: item. localizedName,
288- systemName: item. symbolName,
289- imageColor: item. color
290- )
291- }
292- }
293- }
294- } header: {
295- Text ( " TODO " )
296- . foregroundStyle ( Color ( . label) )
297- }
298-
299- Section {
300- Button {
301- store. send ( . tapWebPageInput)
302- } label: {
303- labelImage (
304- text: " URL " ,
305- systemName: " globe " ,
306- imageColor: . blue
307- )
308- }
309- } header: {
310- Text ( " Web Page " )
311- . foregroundStyle ( Color ( . label) )
312- }
313- }
314- . navigationDestination (
315- isPresented: Binding (
316- get: { store. contentPickerDestination == . webPageInput } ,
317- set: { isPresented in
318- if !isPresented {
319- store. send ( . sheet( . presented( . setContentPickerDestination( nil ) ) ) )
320- }
321- }
322- )
323- ) {
324- Form {
325- Section {
326- TextField (
327- " https:// " ,
328- text: Binding (
329- get: { store. webPageURLInput } ,
330- set: { store. send ( . updateWebPageURLInput( $0) ) }
331- )
332- )
333- . textInputAutocapitalization ( . never)
334- . keyboardType ( . URL)
335- } footer: {
336- Text ( String ( localized: " home_webpage_input_message " ) )
337- }
338- }
339- . scrollDisabled ( true )
340- . toolbar {
341- ToolbarItem ( placement: . principal) {
342- Text ( String ( localized: " home_webpage_input_title " ) )
343- }
344- ToolbarItem ( placement: . topBarTrailing) {
345- Button ( String ( localized: " home_add " ) ) {
346- store. send ( . addWebPage)
347- }
348- }
349- }
350- }
351- . toolbar {
352- ToolbarItem ( placement: . principal) {
353- Text ( String ( localized: " nav_home_content " ) )
354- }
355- ToolbarItem ( placement: . topBarLeading) {
356- Button {
357- store. send ( . sheet( . presented( . tapCloseButton) ) )
358- } label: {
359- Image ( systemName: " xmark " )
360- . bold ( )
361- }
362- }
363- }
364- }
365- }
366-
367358 private func labelImage(
368359 text: String ,
369360 systemName: String ,
0 commit comments