Преглед изворни кода

refactor: rename Category => Project

Sam Jaffe пре 2 недеља
родитељ
комит
fdea6a09c6

+ 1 - 1
Todos/Controller/SaveController.swift

@@ -12,7 +12,7 @@ final class SaveController {
     URL.documentsDirectory.appending(path: "Weekly Tracker \(date).yml")
   }
   
-  static func save(_ items: [Category], to: URL) {
+  static func save(_ items: [Project], to: URL) {
     let data = Data(items.map({ $0.yaml() }).joined().utf8)
     do {
       try data.write(to: to, options: [.atomic, .completeFileProtection])

+ 1 - 1
Todos/Model/Group.swift

@@ -101,7 +101,7 @@ extension Color: @retroactive Codable {
 
 final class Group : Identifiable, Codable {
   var name: String = ""
-  var color: Color = Color(.blue)
+  var color: Color = Color(.gray)
   
   var id: String { name }
   

+ 3 - 3
Todos/Model/Category.swift

@@ -1,5 +1,5 @@
 //
-//  Category.swift
+//  Project.swift
 //  Todos
 //
 //  Created by Sam Jaffe on 2/28/26.
@@ -9,9 +9,9 @@ import Foundation
 import SwiftData
 
 @Model
-final class Category {
+final class Project {
   var timestamp: Date
-  var name: String = "New Category"
+  var name: String = "New Project"
   var tasks: [Task] = []
   
   init(timestamp: Date) {

+ 1 - 1
Todos/TodosApp.swift

@@ -18,7 +18,7 @@ struct UserDefaultsKeys {
 struct TodosApp: App {
   var sharedModelContainer: ModelContainer = {
     let schema = Schema([
-      Category.self,
+      Project.self,
     ])
     let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
 

+ 0 - 22
Todos/View/CategorySidebarView.swift

@@ -1,22 +0,0 @@
-//
-//  CategorySidebarView.swift
-//  Todos
-//
-//  Created by Sam Jaffe on 2/28/26.
-//
-
-import SwiftUI
-import SwiftData
-
-struct CategorySidebarView: View {
-  @Binding var name: String
-
-  var body: some View {
-    TextField("Category", text: $name)
-  }
-}
-
-#Preview {
-  @Previewable @State var name = "New Category"
-  CategorySidebarView(name: $name)
-}

+ 8 - 8
Todos/View/ContentView.swift

@@ -13,7 +13,7 @@ struct ContentView: View {
   @AppStorage(UserDefaultsKeys.WeekStart) private var weekStart = Date()
   let inPreview = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
   
-  @Query private var items: [Category]
+  @Query private var items: [Project]
   
   @State private var showingPopup = false
   @State private var currentHint: URLHint = URLHint()
@@ -23,9 +23,9 @@ struct ContentView: View {
       List {
         ForEach(items) { item in
           NavigationLink {
-            CategoryPanelView(item: item)
+            ProjectPanelView(item: item)
           } label: {
-            CategorySidebarView(name: Bindable(item).name)
+            ProjectSidebarView(name: Bindable(item).name)
           } .contextMenu {
             Button(action: { deleteItem(item: item) }) {
               Label("Delete", systemImage: "trash")
@@ -38,7 +38,7 @@ struct ContentView: View {
       .toolbar {
         ToolbarItem {
           Button(action: addItem) {
-            Label("New Category", systemImage: "plus")
+            Label("New Project", systemImage: "plus")
           }
         }
       }
@@ -50,8 +50,8 @@ struct ContentView: View {
 
   private func addItem() {
     withAnimation {
-      let newItem = Category(timestamp: Date())
-      let count = items.count(where: { $0.name.starts(with: "New Category") })
+      let newItem = Project(timestamp: Date())
+      let count = items.count(where: { $0.name.starts(with: "New Project") })
       if (count > 0) {
         newItem.name += " (\(count))"
       }
@@ -99,7 +99,7 @@ struct ContentView: View {
     }
   }
   
-  private func deleteItem(item: Category) {
+  private func deleteItem(item: Project) {
     withAnimation {
       modelContext.delete(item)
     }
@@ -116,5 +116,5 @@ struct ContentView: View {
 
 #Preview {
   ContentView()
-      .modelContainer(for: Category.self, inMemory: true)
+      .modelContainer(for: Project.self, inMemory: true)
 }

+ 1 - 1
Todos/View/ExportMenu.swift

@@ -12,7 +12,7 @@ import UniformTypeIdentifiers
 struct ExportMenu: View {
   @Environment(\.modelContext) private var modelContext
   
-  @Query private var items: [Category]
+  @Query private var items: [Project]
   @State private var showingExporter = false
 
   var body: some View {

+ 5 - 5
Todos/View/CategoryPanelView.swift

@@ -1,5 +1,5 @@
 //
-//  CategoryPanelView.swift
+//  ProjectPanelView.swift
 //  Todos
 //
 //  Created by Sam Jaffe on 2/28/26.
@@ -8,8 +8,8 @@
 import SwiftUI
 import SwiftData
 
-struct CategoryPanelView: View {
-  @Bindable var item: Category
+struct ProjectPanelView: View {
+  @Bindable var item: Project
 
   var body: some View {
     let style = Date.FormatStyle(date: .numeric, time: .standard)
@@ -41,6 +41,6 @@ struct CategoryPanelView: View {
 }
 
 #Preview {
-  @Previewable @State var item = Category(timestamp: Date())
-  CategoryPanelView(item: item)
+  @Previewable @State var item = Project(timestamp: Date())
+  ProjectPanelView(item: item)
 }

+ 22 - 0
Todos/View/ProjectSidebarView.swift

@@ -0,0 +1,22 @@
+//
+//  ProjectSidebarView.swift
+//  Todos
+//
+//  Created by Sam Jaffe on 2/28/26.
+//
+
+import SwiftUI
+import SwiftData
+
+struct ProjectSidebarView: View {
+  @Binding var name: String
+
+  var body: some View {
+    TextField("Project", text: $name)
+  }
+}
+
+#Preview {
+  @Previewable @State var name = "New Project"
+  ProjectSidebarView(name: $name)
+}

+ 1 - 1
Todos/View/SaveSnapshotMenu.swift

@@ -11,7 +11,7 @@ import SwiftData
 struct SaveSnapshotMenu: View {
   @Environment(\.modelContext) private var modelContext
   
-  @Query private var items: [Category]
+  @Query private var items: [Project]
   
   var body: some View {
     Button("Save Snapshot") {