feat: add move-to-list functionality and stats dashboard cards to lists overview
This commit is contained in:
@@ -12,6 +12,26 @@ class ListStore {
|
||||
lists.first { $0.isInbox }!.id
|
||||
}
|
||||
|
||||
var allOpenItems: [TodoItem] {
|
||||
lists.flatMap { $0.items }.filter { !$0.isCompleted }
|
||||
}
|
||||
|
||||
var openCount: Int { allOpenItems.count }
|
||||
|
||||
var urgentCount: Int {
|
||||
let threeDaysFromNow = Calendar.current.date(byAdding: .day, value: 3, to: Date())!
|
||||
return allOpenItems.filter { item in
|
||||
item.priority == .high || (item.deadline != nil && item.deadline! <= threeDaysFromNow)
|
||||
}.count
|
||||
}
|
||||
|
||||
var dueCount: Int {
|
||||
let startOfTomorrow = Calendar.current.startOfDay(for: Calendar.current.date(byAdding: .day, value: 1, to: Date())!)
|
||||
return allOpenItems.filter { item in
|
||||
item.deadline != nil && item.deadline! < startOfTomorrow
|
||||
}.count
|
||||
}
|
||||
|
||||
init(modelContext: ModelContext) {
|
||||
self.modelContext = modelContext
|
||||
ensureInbox()
|
||||
@@ -86,7 +106,17 @@ class ListStore {
|
||||
fetchLists()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
func moveItem(_ itemID: UUID, from sourceListID: UUID, to targetListID: UUID) {
|
||||
guard sourceListID != targetListID,
|
||||
let sourceList = lists.first(where: { $0.id == sourceListID }),
|
||||
let targetList = lists.first(where: { $0.id == targetListID }),
|
||||
let item = sourceList.items.first(where: { $0.id == itemID }) else { return }
|
||||
sourceList.items.removeAll { $0.id == itemID }
|
||||
targetList.items.append(item)
|
||||
item.modifiedAt = Date()
|
||||
save()
|
||||
fetchLists()
|
||||
}
|
||||
|
||||
private func ensureInbox() {
|
||||
let descriptor = FetchDescriptor<TodoList>(predicate: #Predicate { $0.isInbox })
|
||||
|
||||
Reference in New Issue
Block a user