feat: add extended fields (notes, deadline, priority) to todo editor
This commit is contained in:
@@ -23,9 +23,15 @@ class ListStore {
|
||||
lists.removeAll { $0.id == list.id }
|
||||
}
|
||||
|
||||
func addItem(to listID: UUID, title: String) {
|
||||
func addItem(
|
||||
to listID: UUID,
|
||||
title: String,
|
||||
notes: String? = nil,
|
||||
deadline: Date? = nil,
|
||||
priority: Priority? = nil
|
||||
) {
|
||||
guard let index = lists.firstIndex(where: { $0.id == listID }) else { return }
|
||||
let item = TodoItem(title: title)
|
||||
let item = TodoItem(title: title, notes: notes, deadline: deadline, priority: priority)
|
||||
lists[index].items.append(item)
|
||||
}
|
||||
|
||||
@@ -34,15 +40,31 @@ class ListStore {
|
||||
lists[listIndex].items.removeAll { $0.id == itemID }
|
||||
}
|
||||
|
||||
func updateItem(_ itemID: UUID, in listID: UUID, title: String) {
|
||||
func updateItem(
|
||||
_ itemID: UUID,
|
||||
in listID: UUID,
|
||||
title: String,
|
||||
notes: String? = nil,
|
||||
deadline: Date? = nil,
|
||||
priority: Priority? = nil,
|
||||
isCompleted: Bool? = nil
|
||||
) {
|
||||
guard let listIndex = lists.firstIndex(where: { $0.id == listID }),
|
||||
let itemIndex = lists[listIndex].items.firstIndex(where: { $0.id == itemID }) else { return }
|
||||
lists[listIndex].items[itemIndex].title = title
|
||||
lists[listIndex].items[itemIndex].notes = notes
|
||||
lists[listIndex].items[itemIndex].deadline = deadline
|
||||
lists[listIndex].items[itemIndex].priority = priority
|
||||
if let isCompleted {
|
||||
lists[listIndex].items[itemIndex].isCompleted = isCompleted
|
||||
}
|
||||
lists[listIndex].items[itemIndex].modifiedAt = Date()
|
||||
}
|
||||
|
||||
func toggleItemCompleted(_ itemID: UUID, in listID: UUID) {
|
||||
guard let listIndex = lists.firstIndex(where: { $0.id == listID }),
|
||||
let itemIndex = lists[listIndex].items.firstIndex(where: { $0.id == itemID }) else { return }
|
||||
lists[listIndex].items[itemIndex].isCompleted.toggle()
|
||||
lists[listIndex].items[itemIndex].modifiedAt = Date()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user