Skip to content

Commit 7a1855f

Browse files
committed
refactor: LoadingVIew를 띄울 시 UI 개선
1 parent 350a1c1 commit 7a1855f

1 file changed

Lines changed: 55 additions & 56 deletions

File tree

DevLog/UI/Home/TodoView.swift

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,70 @@ 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
}
@@ -194,11 +198,6 @@ struct TodoView: View {
194198
}
195199
}
196200
.task { viewModel.send(.onAppear) }
197-
.overlay {
198-
if viewModel.state.isLoading {
199-
LoadingView()
200-
}
201-
}
202201
}
203202

204203
private enum Path: Hashable {

0 commit comments

Comments
 (0)