-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoDetailView.swift
More file actions
173 lines (154 loc) · 5.02 KB
/
TodoDetailView.swift
File metadata and controls
173 lines (154 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
// TodoDetailView.swift
// DevLog
//
// Created by opfic on 6/12/25.
//
import SwiftUI
struct TodoDetailView: View {
@State var viewModel: TodoDetailViewModel
var body: some View {
ZStack {
Color(.secondarySystemBackground).ignoresSafeArea()
if let todo = viewModel.state.todo {
TodoDetailContentView(
title: todo.title,
content: todo.content
)
} else if viewModel.state.isLoading {
LoadingView()
}
}
.onAppear { viewModel.send(.onAppear) }
.navigationBarTitleDisplayMode(.inline)
.sheet(isPresented: Binding(
get: { viewModel.state.showInfo },
set: { viewModel.send(.setShowInfo($0)) }
)) {
sheetContent
}
.fullScreenCover(isPresented: Binding(
get: { viewModel.state.showEditor },
set: { viewModel.send(.setShowEditor($0)) }
)) {
if let todo = viewModel.state.todo {
TodoEditorView(
viewModel: TodoEditorViewModel(todo: todo),
onSubmit: { viewModel.send(.upsertTodo($0)) }
)
}
}
.toolbar { toolbarContent }
}
@ToolbarContentBuilder
private var toolbarContent: some ToolbarContent {
ToolbarItem(placement: .topBarTrailing) {
Button {
viewModel.send(.setShowInfo(true))
} label: {
Image(systemName: "info.circle")
}
}
if viewModel.showEditButton {
if #available(iOS 26.0, *) {
ToolbarSpacer(.fixed, placement: .topBarTrailing)
}
ToolbarItem(placement: .topBarTrailing) {
Button {
viewModel.send(.setShowEditor(true))
} label: {
Text("수정")
}
}
}
}
@ViewBuilder
private var sheetContent: some View {
if let todo = viewModel.state.todo {
TodoDetailInfoSheetView(todo: todo) {
viewModel.send(.setShowInfo(false))
}
}
}
}
private struct TodoDetailInfoSheetView: View {
let todo: Todo
let onClose: () -> Void
private let calendar = Calendar.current
var body: some View {
NavigationStack {
List {
Section("옵션") {
HStack {
Text("카테고리")
Spacer()
Text(todo.kind.localizedName)
.foregroundStyle(.secondary)
}
statusRow(
title: "완료",
systemImage: todo.isCompleted ? "checkmark.circle.fill" : "circle",
color: todo.isCompleted ? .green : .secondary
)
statusRow(
title: "중요 표시",
systemImage: todo.isPinned ? "star.fill" : "star",
color: todo.isPinned ? .orange : .secondary
)
HStack {
Text("마감일")
Spacer()
if let dueDate = todo.dueDate {
Tag(dueDateText(for: dueDate), isEditing: false)
.padding(.vertical, -4)
} else {
Text("없음")
.foregroundStyle(.secondary)
}
}
}
Section("태그") {
if todo.tags.isEmpty {
Text("태그 없음")
.foregroundStyle(.secondary)
.padding(.vertical, 4)
} else {
TagList(todo.tags)
}
}
}
.navigationTitle("세부 정보")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarLeadingButton {
onClose()
}
}
}
}
@ViewBuilder
private func statusRow(
title: String,
systemImage: String,
color: Color
) -> some View {
HStack {
Text(title)
Spacer()
Image(systemName: systemImage)
.foregroundStyle(color)
}
}
private func dueDateText(for dueDate: Date) -> String {
let currentYear = calendar.component(.year, from: Date())
let dueDateYear = calendar.component(.year, from: dueDate)
if currentYear == dueDateYear {
return dueDate.formatted(
.dateTime.month(.defaultDigits).day(.defaultDigits)
)
}
return dueDate.formatted(
.dateTime.year(.twoDigits).month(.defaultDigits).day(.defaultDigits)
)
}
}