소스 검색

refactor: add delete option to sidebar

Sam Jaffe 3 주 전
부모
커밋
ef99b6175b
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      Todos/View/ContentView.swift

+ 10 - 0
Todos/View/ContentView.swift

@@ -20,6 +20,10 @@ struct ContentView: View {
             CategoryPanelView(item: item)
           } label: {
             CategorySidebarView(name: Bindable(item).name)
+          } .contextMenu {
+            Button(action: { deleteItem(item: item) }) {
+              Label("Delete", systemImage: "trash")
+            }
           }
         }
         .onDelete(perform: deleteItems)
@@ -47,6 +51,12 @@ struct ContentView: View {
       modelContext.insert(newItem)
     }
   }
+  
+  private func deleteItem(item: Category) {
+    withAnimation {
+      modelContext.delete(item)
+    }
+  }
 
   private func deleteItems(offsets: IndexSet) {
     withAnimation {