@@ -12,70 +12,86 @@ struct TodoView: View {
1212 @EnvironmentObject var router : NavigationRouter
1313
1414 var body : some View {
15- VStack {
16- if viewModel. state. todos. isEmpty {
17- VStack {
18- Spacer ( )
19- Text ( " 작성된 내용이 없습니다. " )
20- . foregroundStyle ( Color . gray)
21- Spacer ( )
22- }
23- . frame ( maxWidth: . infinity, alignment: . center)
15+ ZStack {
16+ if viewModel. state. isLoading {
17+ LoadingView ( )
2418 } else {
25- List ( viewModel. state. todos) { todo in
26- Button {
27- router. push ( Path . detail ( todo) )
28- } label: {
29- VStack ( alignment: . leading, spacing: 5 ) {
30- HStack {
31- if todo. isPinned {
32- Image ( systemName: " star.fill " )
19+ if viewModel. state. todos. isEmpty {
20+ VStack {
21+ Spacer ( )
22+ Text ( " 작성된 내용이 없습니다. " )
23+ . foregroundStyle ( Color . gray)
24+ Spacer ( )
25+ }
26+ . frame ( maxWidth: . infinity, alignment: . center)
27+ } else {
28+ List ( viewModel. state. todos) { todo in
29+ Button {
30+ router. push ( Path . detail ( todo) )
31+ } label: {
32+ VStack ( alignment: . leading, spacing: 5 ) {
33+ HStack {
34+ if todo. isPinned {
35+ Image ( systemName: " star.fill " )
36+ . font ( . headline)
37+ . foregroundStyle ( Color . orange)
38+ }
39+ Text ( todo. title)
3340 . font ( . headline)
34- . foregroundStyle ( Color . orange )
41+ . lineLimit ( 1 )
3542 }
36- Text ( todo. title)
37- . font ( . headline)
43+ Text ( todo. content)
44+ . font ( . subheadline)
45+ . foregroundStyle ( Color . gray)
3846 . lineLimit ( 1 )
3947 }
40- Text ( todo. content)
41- . font ( . subheadline)
42- . foregroundStyle ( Color . gray)
43- . lineLimit ( 1 )
48+ . padding ( . vertical, 5 )
4449 }
45- . padding ( . vertical, 5 )
46- }
47- . swipeActions ( edge: . leading) {
48- Button ( action: {
49- viewModel. send ( . tapTogglePinned( todo) )
50- } ) {
51- Image ( systemName: " star \( todo. isPinned ? " .slash " : " .fill " ) " )
52- }
53- . tint ( Color . orange)
54- }
55- . swipeActions ( edge: . trailing, allowsFullSwipe: true ) {
56- Button ( role: . destructive, action: {
57- viewModel. send ( . swipeTodo( todo) )
58- } ) {
59- Image ( systemName: " trash " )
50+ . swipeActions ( edge: . leading) {
51+ Button ( action: {
52+ viewModel. send ( . tapTogglePinned( todo) )
53+ } ) {
54+ Image ( systemName: " star \( todo. isPinned ? " .slash " : " .fill " ) " )
55+ }
56+ . tint ( Color . orange)
6057 }
58+ . swipeActions ( edge: . trailing, allowsFullSwipe: true ) {
59+ Button ( role: . destructive, action: {
60+ viewModel. send ( . swipeTodo( todo) )
61+ } ) {
62+ Image ( systemName: " trash " )
63+ }
6164
65+ }
6266 }
63- }
64- . listStyle ( . plain )
65- . refreshable {
66- viewModel . send ( . refresh )
67- }
68- . navigationDestination ( for : Path . self ) { path in
69- switch path {
70- case . detail ( let todo ) :
71- TodoDetailView (
72- todo : todo ,
73- onSubmit : { viewModel . send ( . upsertTodo ( $0 ) ) }
74- )
67+ . listStyle ( . plain )
68+ . refreshable {
69+ viewModel . send ( . refresh )
70+ }
71+ . navigationDestination ( for : Path . self ) { path in
72+ switch path {
73+ case . detail ( let todo ) :
74+ TodoDetailView (
75+ todo : todo ,
76+ onSubmit : { viewModel . send ( . upsertTodo ( $0 ) ) }
77+ )
78+ }
7579 }
7680 }
7781 }
7882 }
83+ . alert ( " 불러오기 실패 " , isPresented: Binding (
84+ get: { viewModel. state. showAlert } ,
85+ set: { _, _ in }
86+ ) ) {
87+ Button ( role: . cancel, action: {
88+ viewModel. send ( . closeAlert)
89+ } ) {
90+ Text ( " 확인 " )
91+ }
92+ } message: {
93+ Text ( viewModel. state. alertMessage)
94+ }
7995 . navigationTitle ( viewModel. state. kind. localizedName)
8096 . navigationBarTitleDisplayMode ( . large)
8197 . fullScreenCover ( isPresented: Binding (
@@ -181,14 +197,7 @@ struct TodoView: View {
181197 Text ( scope. localizedName) . tag ( scope)
182198 }
183199 }
184- . task {
185- viewModel. send ( . onAppear)
186- }
187- . overlay {
188- if viewModel. state. isLoading {
189- LoadingView ( )
190- }
191- }
200+ . task { viewModel. send ( . onAppear) }
192201 }
193202
194203 private enum Path : Hashable {
0 commit comments