feat: add move-to-list functionality and stats dashboard cards to lists overview

This commit is contained in:
2026-02-12 21:26:45 +01:00
parent d988cb53cf
commit 5c589c4b93
5 changed files with 116 additions and 1 deletions

View File

@@ -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 })