Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions DevLog/Presentation/ViewModel/TodoEditorViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import OrderedCollections
@Observable
final class TodoEditorViewModel: Store {
private struct Draft: Equatable {
let isPinned: Bool
let title: String
let content: String
let dueDate: Date?
let tags: [String]

init(todo: Todo) {
self.isPinned = todo.isPinned
self.title = todo.title
self.content = todo.content
self.dueDate = todo.dueDate
self.tags = todo.tags
}

init(state: State) {
self.isPinned = state.isPinned
self.title = state.title
self.content = state.content
self.dueDate = state.dueDate
Expand All @@ -32,6 +35,7 @@ final class TodoEditorViewModel: Store {
}

struct State: Equatable {
var isPinned: Bool = false
var title: String = ""
var content: String = ""
var dueDate: Date?
Expand All @@ -58,6 +62,7 @@ final class TodoEditorViewModel: Store {
case setTabViewTag(Tag)
case setTagText(String)
case setTitle(String)
case togglePinned
case toggleDueDate
}

Expand All @@ -67,7 +72,6 @@ final class TodoEditorViewModel: Store {
private let calendar = Calendar.current
let navigationTitle: String
private let id: String
private let isPinned: Bool
private let isCompleted: Bool
private let isChecked: Bool
private let createdAt: Date?
Expand All @@ -88,7 +92,6 @@ final class TodoEditorViewModel: Store {
init(kind: TodoKind) {
self.navigationTitle = "새 \(kind.localizedName) 추가"
self.id = UUID().uuidString
self.isPinned = false
self.isCompleted = false
self.isChecked = false
self.createdAt = nil
Expand All @@ -101,13 +104,13 @@ final class TodoEditorViewModel: Store {
init(todo: Todo) {
self.navigationTitle = "편집"
self.id = todo.id
self.isPinned = todo.isPinned
self.isCompleted = todo.isCompleted
self.isChecked = todo.isChecked
self.createdAt = todo.createdAt
self.completedAt = todo.completedAt
self.kind = todo.kind
self.originalDraft = Draft(todo: todo)
state.isPinned = todo.isPinned
state.title = todo.title
state.content = todo.content
state.dueDate = todo.dueDate
Expand Down Expand Up @@ -136,6 +139,8 @@ final class TodoEditorViewModel: Store {
}
case .setTabViewTag(let tag):
state.tabViewTag = tag
case .togglePinned:
state.isPinned.toggle()
case .toggleDueDate:
if state.hasDueDate {
state.dueDate = nil
Expand Down Expand Up @@ -171,7 +176,7 @@ extension TodoEditorViewModel {
let date = Date()
return Todo(
id: self.id,
isPinned: self.isPinned,
isPinned: state.isPinned,
isCompleted: self.isCompleted,
isChecked: self.isChecked,
title: state.title,
Expand Down
3 changes: 3 additions & 0 deletions DevLog/Resource/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@
},
"제목" : {

},
"중요" : {

},
"중요 표시" : {

Expand Down
11 changes: 11 additions & 0 deletions DevLog/UI/Home/TodoEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ struct TodoEditorView: View {

private var accessoryBar: some View {
HStack {
Button {
viewModel.send(.togglePinned)
} label: {
Label {
Text("중요")
} icon: {
Image(systemName: viewModel.state.isPinned ? "star.fill" : "star")
.foregroundStyle(viewModel.state.isPinned ? .yellow : .gray)
}
.adaptiveButtonStyle()
}
TagEditor(
tags: viewModel.state.tags,
addAction: { viewModel.send(.addTag($0)) },
Expand Down