Skip to content

Commit dde53d3

Browse files
committed
feat: 토글로 완료 여부를 선택할 수 있도록 추가
1 parent 389efce commit dde53d3

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

DevLog/Presentation/ViewModel/TodoEditorViewModel.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import OrderedCollections
1111
@Observable
1212
final class TodoEditorViewModel: Store {
1313
private struct Draft: Equatable {
14+
let isCompleted: Bool
1415
let isPinned: Bool
1516
let title: String
1617
let content: String
@@ -19,6 +20,7 @@ final class TodoEditorViewModel: Store {
1920
let kind: TodoKind
2021

2122
init(todo: Todo) {
23+
self.isCompleted = todo.isCompleted
2224
self.isPinned = todo.isPinned
2325
self.title = todo.title
2426
self.content = todo.content
@@ -28,6 +30,7 @@ final class TodoEditorViewModel: Store {
2830
}
2931

3032
init(state: State) {
33+
self.isCompleted = state.isCompleted
3134
self.isPinned = state.isPinned
3235
self.title = state.title
3336
self.content = state.content
@@ -38,6 +41,7 @@ final class TodoEditorViewModel: Store {
3841
}
3942

4043
struct State: Equatable {
44+
var isCompleted: Bool = false
4145
var isPinned: Bool = false
4246
var title: String = ""
4347
var content: String = ""
@@ -61,6 +65,7 @@ final class TodoEditorViewModel: Store {
6165
case addTag(String)
6266
case removeTag(String)
6367
case setContent(String)
68+
case setCompleted(Bool)
6469
case setDueDate(Date?)
6570
case setKind(TodoKind)
6671
case setPinned(Bool)
@@ -117,6 +122,7 @@ final class TodoEditorViewModel: Store {
117122
self.createdAt = todo.createdAt
118123
self.completedAt = todo.completedAt
119124
self.originalDraft = Draft(todo: todo)
125+
state.isCompleted = todo.isCompleted
120126
state.isPinned = todo.isPinned
121127
state.title = todo.title
122128
state.content = todo.content
@@ -145,6 +151,8 @@ final class TodoEditorViewModel: Store {
145151
} else {
146152
state.dueDate = nil
147153
}
154+
case .setCompleted(let isCompleted):
155+
state.isCompleted = isCompleted
148156
case .setKind(let todoKind):
149157
state.kind = todoKind
150158
case .setPinned(let isPinned):
@@ -183,13 +191,13 @@ extension TodoEditorViewModel {
183191
return Todo(
184192
id: self.id,
185193
isPinned: state.isPinned,
186-
isCompleted: self.isCompleted,
194+
isCompleted: state.isCompleted,
187195
isChecked: self.isChecked,
188196
title: state.title,
189197
content: state.content,
190198
createdAt: self.createdAt ?? date,
191199
updatedAt: date,
192-
completedAt: self.completedAt,
200+
completedAt: state.isCompleted ? (self.completedAt ?? date) : nil,
193201
dueDate: state.dueDate,
194202
tags: state.tags.map { $0 },
195203
kind: state.kind

DevLog/UI/Home/TodoEditorView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ private struct TodoEditorInfoSheetView: View {
192192
}
193193
}
194194

195+
Toggle(
196+
"완료",
197+
isOn: Binding(
198+
get: { viewModel.state.isCompleted },
199+
set: { viewModel.send(.setCompleted($0)) }
200+
)
201+
)
202+
.tint(.blue)
203+
195204
Toggle(
196205
"중요 표시",
197206
isOn: Binding(

0 commit comments

Comments
 (0)