|
|
@@ -0,0 +1,34 @@
|
|
|
+//
|
|
|
+// NewProjectMenu.swift
|
|
|
+// Todos
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 3/2/26.
|
|
|
+//
|
|
|
+
|
|
|
+import SwiftUI
|
|
|
+import SwiftData
|
|
|
+
|
|
|
+struct NewProjectMenu: View {
|
|
|
+ @Environment(\.modelContext) private var modelContext
|
|
|
+ @Query private var items: [Project]
|
|
|
+
|
|
|
+ var body: some View {
|
|
|
+ Button("New Project", action: addItem)
|
|
|
+ .keyboardShortcut("N", modifiers: [.command])
|
|
|
+ }
|
|
|
+
|
|
|
+ private func addItem() {
|
|
|
+ withAnimation {
|
|
|
+ let newItem = Project(timestamp: Date())
|
|
|
+ let count = items.count(where: { $0.name.starts(with: "New Project") })
|
|
|
+ if (count > 0) {
|
|
|
+ newItem.name += " (\(count))"
|
|
|
+ }
|
|
|
+ modelContext.insert(newItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#Preview {
|
|
|
+ NewProjectMenu()
|
|
|
+}
|