feat: added list overview and detail view

This commit is contained in:
2026-02-11 22:54:51 +01:00
parent 5a10e30319
commit 0754a7ff13
9 changed files with 264 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
import Foundation
import Observation
@Observable
class ListStore {
var lists: [TodoList]
init() {
self.lists = [TodoList(name: "Inbox", isInbox: true)]
}
func addList(name: String) {
let list = TodoList(name: name)
lists.append(list)
}
func deleteList(_ list: TodoList) {
guard !list.isInbox else { return }
lists.removeAll { $0.id == list.id }
}
func addItem(to listID: UUID, title: String) {
guard let index = lists.firstIndex(where: { $0.id == listID }) else { return }
let item = TodoItem(title: title)
lists[index].items.append(item)
}
func deleteItem(_ itemID: UUID, from listID: UUID) {
guard let listIndex = lists.firstIndex(where: { $0.id == listID }) else { return }
lists[listIndex].items.removeAll { $0.id == itemID }
}
func updateItem(_ itemID: UUID, in listID: UUID, title: String) {
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
}
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()
}
}