Got rid of TODOs
This commit is contained in:
		| @@ -2,7 +2,7 @@ | |||||||
| //  Flashcard+CoreDataProperties.swift | //  Flashcard+CoreDataProperties.swift | ||||||
| //  WordAX | //  WordAX | ||||||
| // | // | ||||||
| //  Created by Oliver Hnát on 09.04.2024. | //  Created by Oliver Hnát on 10.04.2024. | ||||||
| // | // | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| @@ -11,19 +11,17 @@ import CoreData | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| extension Flashcard { | extension Flashcard { | ||||||
|     // TODO: Get rid of shown and instead just use lastSeenOn == nil |  | ||||||
| 
 | 
 | ||||||
|     @nonobjc public class func fetchRequest() -> NSFetchRequest<Flashcard> { |     @nonobjc public class func fetchRequest() -> NSFetchRequest<Flashcard> { | ||||||
|         return NSFetchRequest<Flashcard>(entityName: "Flashcard") |         return NSFetchRequest<Flashcard>(entityName: "Flashcard") | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @NSManaged public var name: String? |     @NSManaged public var dateAdded: Date? | ||||||
|     @NSManaged public var desc: String? |     @NSManaged public var desc: String? | ||||||
|     @NSManaged public var id: UUID? |     @NSManaged public var id: UUID? | ||||||
|     @NSManaged public var shown: Bool |  | ||||||
|     @NSManaged public var nextSpacedRepetitionMilestone: Int64 |  | ||||||
|     @NSManaged public var lastSeenOn: Date? |     @NSManaged public var lastSeenOn: Date? | ||||||
|     @NSManaged public var dateAdded: Date? |     @NSManaged public var name: String? | ||||||
|  |     @NSManaged public var nextSpacedRepetitionMilestone: Int64 | ||||||
|     @NSManaged public var shownCount: Int64 |     @NSManaged public var shownCount: Int64 | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @@ -19,7 +19,7 @@ | |||||||
| 		6CEF7F7D2BC457E600E205F6 /* DataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F7C2BC457E600E205F6 /* DataController.swift */; }; | 		6CEF7F7D2BC457E600E205F6 /* DataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F7C2BC457E600E205F6 /* DataController.swift */; }; | ||||||
| 		6CEF7F812BC4694900E205F6 /* WordAXCD.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */; }; | 		6CEF7F812BC4694900E205F6 /* WordAXCD.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */; }; | ||||||
| 		6CEF7F842BC46B5900E205F6 /* Flashcard+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */; }; | 		6CEF7F842BC46B5900E205F6 /* Flashcard+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */; }; | ||||||
| 		6CEF7F8D2BC5613F00E205F6 /* Flashcard+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F8B2BC5613F00E205F6 /* Flashcard+CoreDataProperties.swift */; }; | 		6CEF7F9E2BC6B4F100E205F6 /* Flashcard+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEF7F9C2BC6B4F100E205F6 /* Flashcard+CoreDataProperties.swift */; }; | ||||||
| 		6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; }; | 		6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; }; | ||||||
| 		6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; }; | 		6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; }; | ||||||
| 		6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; }; | 		6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; }; | ||||||
| @@ -36,10 +36,11 @@ | |||||||
| 		6C8185092B8BA5740033CF46 /* FlashCardListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListView.swift; sourceTree = "<group>"; }; | 		6C8185092B8BA5740033CF46 /* FlashCardListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListView.swift; sourceTree = "<group>"; }; | ||||||
| 		6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListRowView.swift; sourceTree = "<group>"; }; | 		6C81850B2B8BA6BC0033CF46 /* FlashCardListRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardListRowView.swift; sourceTree = "<group>"; }; | ||||||
| 		6CEF7F512BC2DBF800E205F6 /* AddFlashCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFlashCard.swift; sourceTree = "<group>"; }; | 		6CEF7F512BC2DBF800E205F6 /* AddFlashCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFlashCard.swift; sourceTree = "<group>"; }; | ||||||
| 		6CEF7F7C2BC457E600E205F6 /* DataController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DataController.swift; path = WordAX/Model/DataController.swift; sourceTree = "<group>"; }; | 		6CEF7F7C2BC457E600E205F6 /* DataController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataController.swift; sourceTree = "<group>"; }; | ||||||
| 		6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = WordAX.xcdatamodel; sourceTree = "<group>"; }; | 		6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = WordAX.xcdatamodel; sourceTree = "<group>"; }; | ||||||
| 		6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Flashcard+CoreDataClass.swift"; sourceTree = "<group>"; }; | 		6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Flashcard+CoreDataClass.swift"; sourceTree = "<group>"; }; | ||||||
| 		6CEF7F8B2BC5613F00E205F6 /* Flashcard+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Flashcard+CoreDataProperties.swift"; sourceTree = "<group>"; }; | 		6CEF7F962BC6B45F00E205F6 /* WordAX0.0.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = WordAX0.0.1.xcdatamodel; sourceTree = "<group>"; }; | ||||||
|  | 		6CEF7F9C2BC6B4F100E205F6 /* Flashcard+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Flashcard+CoreDataProperties.swift"; path = "../../Flashcard+CoreDataProperties.swift"; sourceTree = "<group>"; }; | ||||||
| 		6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; }; | 		6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; }; | ||||||
| 		6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; }; | 		6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; }; | ||||||
| 		6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; }; | 		6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; }; | ||||||
| @@ -76,8 +77,10 @@ | |||||||
| 		6CEF7F7B2BC456A100E205F6 /* Model */ = { | 		6CEF7F7B2BC456A100E205F6 /* Model */ = { | ||||||
| 			isa = PBXGroup; | 			isa = PBXGroup; | ||||||
| 			children = ( | 			children = ( | ||||||
| 				6CEF7F8B2BC5613F00E205F6 /* Flashcard+CoreDataProperties.swift */, | 				6CEF7F7C2BC457E600E205F6 /* DataController.swift */, | ||||||
|  | 				6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */, | ||||||
| 				6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */, | 				6CEF7F822BC46B5900E205F6 /* Flashcard+CoreDataClass.swift */, | ||||||
|  | 				6CEF7F9C2BC6B4F100E205F6 /* Flashcard+CoreDataProperties.swift */, | ||||||
| 			); | 			); | ||||||
| 			path = Model; | 			path = Model; | ||||||
| 			sourceTree = "<group>"; | 			sourceTree = "<group>"; | ||||||
| @@ -85,8 +88,6 @@ | |||||||
| 		6CF439452B83541D004C3543 = { | 		6CF439452B83541D004C3543 = { | ||||||
| 			isa = PBXGroup; | 			isa = PBXGroup; | ||||||
| 			children = ( | 			children = ( | ||||||
| 				6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */, |  | ||||||
| 				6CEF7F7C2BC457E600E205F6 /* DataController.swift */, |  | ||||||
| 				6CF439502B83541D004C3543 /* WordAX */, | 				6CF439502B83541D004C3543 /* WordAX */, | ||||||
| 				6CF4394F2B83541D004C3543 /* Products */, | 				6CF4394F2B83541D004C3543 /* Products */, | ||||||
| 			); | 			); | ||||||
| @@ -196,6 +197,7 @@ | |||||||
| 				6CF439542B83541D004C3543 /* MainView.swift in Sources */, | 				6CF439542B83541D004C3543 /* MainView.swift in Sources */, | ||||||
| 				6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */, | 				6C8185082B8B523E0033CF46 /* NextRepetitionButtonView.swift in Sources */, | ||||||
| 				6C8185062B8A537F0033CF46 /* FlashCardView.swift in Sources */, | 				6C8185062B8A537F0033CF46 /* FlashCardView.swift in Sources */, | ||||||
|  | 				6CEF7F9E2BC6B4F100E205F6 /* Flashcard+CoreDataProperties.swift in Sources */, | ||||||
| 				6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */, | 				6C81850A2B8BA5740033CF46 /* FlashCardListView.swift in Sources */, | ||||||
| 				6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */, | 				6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */, | ||||||
| 				6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */, | 				6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */, | ||||||
| @@ -206,7 +208,6 @@ | |||||||
| 				6CEF7F812BC4694900E205F6 /* WordAXCD.xcdatamodeld in Sources */, | 				6CEF7F812BC4694900E205F6 /* WordAXCD.xcdatamodeld in Sources */, | ||||||
| 				6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */, | 				6C81850C2B8BA6BC0033CF46 /* FlashCardListRowView.swift in Sources */, | ||||||
| 				6CEF7F842BC46B5900E205F6 /* Flashcard+CoreDataClass.swift in Sources */, | 				6CEF7F842BC46B5900E205F6 /* Flashcard+CoreDataClass.swift in Sources */, | ||||||
| 				6CEF7F8D2BC5613F00E205F6 /* Flashcard+CoreDataProperties.swift in Sources */, |  | ||||||
| 			); | 			); | ||||||
| 			runOnlyForDeploymentPostprocessing = 0; | 			runOnlyForDeploymentPostprocessing = 0; | ||||||
| 		}; | 		}; | ||||||
| @@ -417,11 +418,11 @@ | |||||||
| 		6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */ = { | 		6CEF7F7F2BC4694900E205F6 /* WordAXCD.xcdatamodeld */ = { | ||||||
| 			isa = XCVersionGroup; | 			isa = XCVersionGroup; | ||||||
| 			children = ( | 			children = ( | ||||||
|  | 				6CEF7F962BC6B45F00E205F6 /* WordAX0.0.1.xcdatamodel */, | ||||||
| 				6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */, | 				6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */, | ||||||
| 			); | 			); | ||||||
| 			currentVersion = 6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */; | 			currentVersion = 6CEF7F802BC4694900E205F6 /* WordAX.xcdatamodel */; | ||||||
| 			name = WordAXCD.xcdatamodeld; | 			path = WordAXCD.xcdatamodeld; | ||||||
| 			path = WordAX/Model/WordAXCD.xcdatamodeld; |  | ||||||
| 			sourceTree = "<group>"; | 			sourceTree = "<group>"; | ||||||
| 			versionGroupType = wrapper.xcdatamodel; | 			versionGroupType = wrapper.xcdatamodel; | ||||||
| 		}; | 		}; | ||||||
|   | |||||||
| @@ -26,56 +26,6 @@ class DataController: ObservableObject { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     //    public func addFlashcard(name: String, description: String) { |  | ||||||
|     public func addFlashcard(name: String, description: String) { |  | ||||||
|         let flashcard = Flashcard(context: viewContext) |  | ||||||
|         flashcard.id = UUID() |  | ||||||
|         flashcard.name = name |  | ||||||
|         flashcard.desc = description |  | ||||||
|         flashcard.shown = false |  | ||||||
|         flashcard.nextSpacedRepetitionMilestone = 0 |  | ||||||
|         flashcard.lastSeenOn = nil |  | ||||||
|         flashcard.shownCount = 0 |  | ||||||
|         flashcard.dateAdded = Date() |  | ||||||
|         try? viewContext.save() |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     // TODO: Figure out if this does anything? |  | ||||||
|     public func setNextSpacedRepetitionMilestone(flashcard: Flashcard) { |  | ||||||
|         let current = SpacedRepetitionMilestoneEnum.allCasesSorted.firstIndex(of: flashcard.getSpacedRepetitionMilestone()) ?? SpacedRepetitionMilestoneEnum.allCases.count |  | ||||||
|         let predicate = NSPredicate(format: "id == %@", flashcard.id! as CVarArg) |  | ||||||
|         let flashcards = self.getAllFlashcards(predicate: predicate) |  | ||||||
|         if !flashcards.isEmpty { |  | ||||||
|             if current + 1 < SpacedRepetitionMilestoneEnum.allCases.count { |  | ||||||
|                 flashcards[0].nextSpacedRepetitionMilestone = SpacedRepetitionMilestoneEnum.allCasesSorted[current + 1].rawValue |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     public func setSpacedRepetitionMilestone(flashcardId: UUID, milestone: SpacedRepetitionMilestoneEnum?) { |  | ||||||
|         let predicate = NSPredicate(format: "id == %@", flashcardId as CVarArg) |  | ||||||
|         let flashcards = self.getAllFlashcards(predicate: predicate) |  | ||||||
|         if !flashcards.isEmpty { |  | ||||||
|             if milestone != nil { |  | ||||||
|                 flashcards[0].nextSpacedRepetitionMilestone = milestone!.rawValue |  | ||||||
|             } else { |  | ||||||
|                 flashcards[0].nextSpacedRepetitionMilestone = 0 |  | ||||||
|             } |  | ||||||
|             if !flashcards[0].shown { |  | ||||||
|                 flashcards[0].shown = true |  | ||||||
|             } |  | ||||||
|             flashcards[0].lastSeenOn = Date() |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     public func flashcardShown(flashcardId: UUID) { |  | ||||||
|         let predicate = NSPredicate(format: "id == %@", flashcardId as CVarArg) |  | ||||||
|         let flashcards = self.getAllFlashcards(predicate: predicate) |  | ||||||
|         if !flashcards.isEmpty { |  | ||||||
|             flashcards[0].shownCount += 1 |  | ||||||
|             try? viewContext.save() |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|      |      | ||||||
|     public func getAllFlashcards(predicate: NSPredicate? = nil) -> [Flashcard]{ |     public func getAllFlashcards(predicate: NSPredicate? = nil) -> [Flashcard]{ | ||||||
|         let request = NSFetchRequest<Flashcard>(entityName: "Flashcard") |         let request = NSFetchRequest<Flashcard>(entityName: "Flashcard") | ||||||
|   | |||||||
| @@ -0,0 +1,12 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||||||
|  | <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22757" systemVersion="23D60" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier=""> | ||||||
|  |     <entity name="Flashcard" representedClassName="Flashcard" syncable="YES"> | ||||||
|  |         <attribute name="dateAdded" attributeType="Date" usesScalarValueType="NO"/> | ||||||
|  |         <attribute name="desc" optional="YES" attributeType="String"/> | ||||||
|  |         <attribute name="id" attributeType="UUID" usesScalarValueType="NO"/> | ||||||
|  |         <attribute name="lastSeenOn" optional="YES" attributeType="Date" usesScalarValueType="NO"/> | ||||||
|  |         <attribute name="name" attributeType="String"/> | ||||||
|  |         <attribute name="nextSpacedRepetitionMilestone" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> | ||||||
|  |         <attribute name="shownCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> | ||||||
|  |     </entity> | ||||||
|  | </model> | ||||||
| @@ -35,7 +35,6 @@ struct AddFlashCard: View { | |||||||
|                         flashcard.id = UUID() |                         flashcard.id = UUID() | ||||||
|                         flashcard.name = self.text |                         flashcard.name = self.text | ||||||
|                         flashcard.desc = self.description |                         flashcard.desc = self.description | ||||||
|                         flashcard.shown = false |  | ||||||
|                         flashcard.nextSpacedRepetitionMilestone = 0 |                         flashcard.nextSpacedRepetitionMilestone = 0 | ||||||
|                         flashcard.lastSeenOn = nil |                         flashcard.lastSeenOn = nil | ||||||
|                         flashcard.shownCount = 0 |                         flashcard.shownCount = 0 | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ struct FlashCardView: View { | |||||||
|             .font(.title) |             .font(.title) | ||||||
|             .bold() |             .bold() | ||||||
|         VStack { |         VStack { | ||||||
|             if flashcard.shown && flashcard.lastSeenOn != nil { |             if flashcard.lastSeenOn != nil { | ||||||
|                 Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!)) |                 Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!)) | ||||||
|                     .font(.subheadline) |                     .font(.subheadline) | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -30,12 +30,6 @@ class WordAXModelView: ObservableObject { | |||||||
|     public func getDateFormatter() -> DateFormatter { |     public func getDateFormatter() -> DateFormatter { | ||||||
|         self.settings.dateFormatter |         self.settings.dateFormatter | ||||||
|     } |     } | ||||||
|      |  | ||||||
|      |  | ||||||
|     public func ankiButtonClicked(flashcardId: UUID, milestone: Flashcard.SpacedRepetitionMilestoneEnum?, moc: DataController) { |  | ||||||
|         moc.setSpacedRepetitionMilestone(flashcardId: flashcardId, milestone: milestone) |  | ||||||
|         moc.flashcardShown(flashcardId: flashcardId) |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user