feat: separate open and completed todos into collapsible sections
This commit is contained in:
@@ -13,6 +13,14 @@ class TodoList: Identifiable {
|
||||
items.sorted { $0.createdAt < $1.createdAt }
|
||||
}
|
||||
|
||||
var openItems: [TodoItem] {
|
||||
items.filter { !$0.isCompleted }.sorted { $0.createdAt < $1.createdAt }
|
||||
}
|
||||
|
||||
var completedItems: [TodoItem] {
|
||||
items.filter { $0.isCompleted }.sorted { ($0.modifiedAt ?? $0.createdAt) > ($1.modifiedAt ?? $1.createdAt) }
|
||||
}
|
||||
|
||||
init(id: UUID = UUID(), name: String, items: [TodoItem] = [], isInbox: Bool = false) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
@@ -5,6 +5,7 @@ struct ListDetailView: View {
|
||||
let listID: UUID
|
||||
@State private var editorItem: TodoItem?
|
||||
@State private var moveItem: TodoItem?
|
||||
@State private var showCompleted = true
|
||||
|
||||
private var todoList: TodoList? {
|
||||
store.lists.first { $0.id == listID }
|
||||
@@ -13,12 +14,13 @@ struct ListDetailView: View {
|
||||
var body: some View {
|
||||
Group {
|
||||
if let todoList {
|
||||
if todoList.sortedItems.isEmpty {
|
||||
if todoList.items.isEmpty {
|
||||
ContentUnavailableView("Keine Einträge", systemImage: "tray")
|
||||
} else {
|
||||
List {
|
||||
Section {
|
||||
TodoListView(
|
||||
items: todoList.sortedItems,
|
||||
items: todoList.openItems,
|
||||
onToggle: { item in
|
||||
store.toggleItemCompleted(item.id, in: listID)
|
||||
},
|
||||
@@ -33,6 +35,41 @@ struct ListDetailView: View {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if !todoList.completedItems.isEmpty {
|
||||
Section {
|
||||
if showCompleted {
|
||||
TodoListView(
|
||||
items: todoList.completedItems,
|
||||
onToggle: { item in
|
||||
store.toggleItemCompleted(item.id, in: listID)
|
||||
},
|
||||
onTap: { item in
|
||||
editorItem = item
|
||||
},
|
||||
onDelete: { item in
|
||||
store.deleteItem(item.id, from: listID)
|
||||
},
|
||||
onMove: { item in
|
||||
moveItem = item
|
||||
}
|
||||
)
|
||||
}
|
||||
} header: {
|
||||
Button {
|
||||
withAnimation {
|
||||
showCompleted.toggle()
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Text("Erledigt (\(todoList.completedItems.count))")
|
||||
Spacer()
|
||||
Image(systemName: showCompleted ? "chevron.down" : "chevron.right")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user