@@ -12,74 +12,78 @@ struct TaskEditView: View {
1212 @Environment ( TaskManager . self) var taskManager
1313
1414 var task : TaskModel
15- var taskIndex : Int
1615
1716 @FocusState private var taskFocus : Bool
1817 @FocusState private var descFocus : Bool
1918
2019 var body : some View {
2120 @Bindable var taskManager = taskManager
2221
23- NavigationStack {
24- VStack {
25- HStack {
26- DoneButton ( isDone: $taskManager. tasks [ taskIndex] . isDone)
22+ let taskIndex = taskManager. getTaskIndexBy ( task: task)
23+
24+ if taskIndex == - 1 {
25+ } else {
26+ NavigationStack {
27+ VStack {
28+ HStack {
29+ DoneButton ( isDone: $taskManager. tasks [ taskIndex] . isDone)
30+
31+ Spacer ( )
32+
33+ Text ( task. dateStr)
34+
35+ Spacer ( )
36+
37+ Button {
38+ taskManager. delete ( task: task)
39+ dismiss ( )
40+ } label: {
41+ Text ( " 안할래 " )
42+ }
43+
44+ }
2745
28- Spacer ( )
46+ TextField ( " " , text: $taskManager. tasks [ taskIndex] . task)
47+ . frame ( height: 64 )
48+ . background ( Color . Todo. grayFry)
49+ . padding ( [ . bottom] , 16 )
50+ . focused ( $taskFocus)
51+ . onSubmit {
52+ taskFocus = false
53+ }
2954
30- Text ( task. dateStr)
55+ TextField ( " " , text: $taskManager. tasks [ taskIndex] . description, axis: . vertical)
56+ . frame ( height: 330 , alignment: . top)
57+ . lineLimit ( 2 ... )
58+ . foregroundColor ( Color . Todo. black)
59+ . background ( Color . Todo. grayFry)
60+ . focused ( $descFocus)
61+ . onSubmit {
62+ descFocus = false
63+ }
3164
3265 Spacer ( )
33-
34- Button {
35- taskManager. delete ( task: task)
36- dismiss ( )
37- } label: {
38- Text ( " 안할래 " )
39- }
40-
4166 }
42-
43- TextField ( " " , text: $taskManager. tasks [ taskIndex] . task)
44- . frame ( height: 64 )
45- . background ( Color . Todo. grayFry)
46- . padding ( [ . bottom] , 16 )
47- . focused ( $taskFocus)
48- . onSubmit {
49- taskFocus = false
67+ . toolbar {
68+ ToolbarItemGroup ( placement: . topBarLeading) {
69+ Text ( " Task " )
70+ . font ( . Todo. title)
71+ . foregroundStyle ( Color . Todo. black)
72+ FavoriteButton ( isFavorite: $taskManager. tasks [ taskIndex] . isFavorite)
5073 }
51-
52- TextField ( " " , text: $taskManager. tasks [ taskIndex] . description, axis: . vertical)
53- . frame ( height: 330 , alignment: . top)
54- . lineLimit ( 2 ... )
55- . foregroundColor ( Color . Todo. black)
56- . background ( Color . Todo. grayFry)
57- . focused ( $descFocus)
58- . onSubmit {
59- descFocus = false
74+ ToolbarItemGroup ( placement: . topBarTrailing) {
75+ Button ( " 닫기 " ) {
76+ dismiss ( )
77+ }
6078 }
61-
62- Spacer ( )
63- }
64- . toolbar {
65- ToolbarItemGroup ( placement: . topBarLeading) {
66- Text ( " Task " )
67- . font ( . Todo. title)
68- . foregroundStyle ( Color . Todo. black)
69- FavoriteButton ( isFavorite: $taskManager. tasks [ taskIndex] . isFavorite)
70- }
71- ToolbarItemGroup ( placement: . topBarTrailing) {
72- Button ( " 닫기 " ) {
73- dismiss ( )
74- }
7579 }
80+ . navigationBarBackButtonHidden ( )
81+ . padding ( EdgeInsets ( top: 32 , leading: 16 , bottom: 16 , trailing: 16 ) )
7682 }
77- . navigationBarBackButtonHidden ( )
78- . padding ( EdgeInsets ( top: 32 , leading: 16 , bottom: 16 , trailing: 16 ) )
7983 }
8084 }
8185}
8286
8387#Preview {
84- TaskEditView ( task: TaskModel ( task: " " , description: " " ) , taskIndex : 0 )
88+ TaskEditView ( task: TaskModel ( task: " " , description: " " ) )
8589}
0 commit comments