Got rid of TODOs
This commit is contained in:
		| @@ -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]{ | ||||
|         let request = NSFetchRequest<Flashcard>(entityName: "Flashcard") | ||||
|   | ||||
| @@ -1,33 +0,0 @@ | ||||
| // | ||||
| //  Flashcard+CoreDataProperties.swift | ||||
| //  WordAX | ||||
| // | ||||
| //  Created by Oliver Hnát on 09.04.2024. | ||||
| // | ||||
| // | ||||
|  | ||||
| import Foundation | ||||
| import CoreData | ||||
|  | ||||
|  | ||||
| extension Flashcard { | ||||
|     // TODO: Get rid of shown and instead just use lastSeenOn == nil | ||||
|  | ||||
|     @nonobjc public class func fetchRequest() -> NSFetchRequest<Flashcard> { | ||||
|         return NSFetchRequest<Flashcard>(entityName: "Flashcard") | ||||
|     } | ||||
|  | ||||
|     @NSManaged public var name: String? | ||||
|     @NSManaged public var desc: String? | ||||
|     @NSManaged public var id: UUID? | ||||
|     @NSManaged public var shown: Bool | ||||
|     @NSManaged public var nextSpacedRepetitionMilestone: Int64 | ||||
|     @NSManaged public var lastSeenOn: Date? | ||||
|     @NSManaged public var dateAdded: Date? | ||||
|     @NSManaged public var shownCount: Int64 | ||||
|  | ||||
| } | ||||
|  | ||||
| extension Flashcard : Identifiable { | ||||
|  | ||||
| } | ||||
| @@ -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.name = self.text | ||||
|                         flashcard.desc = self.description | ||||
|                         flashcard.shown = false | ||||
|                         flashcard.nextSpacedRepetitionMilestone = 0 | ||||
|                         flashcard.lastSeenOn = nil | ||||
|                         flashcard.shownCount = 0 | ||||
|   | ||||
| @@ -20,7 +20,7 @@ struct FlashCardView: View { | ||||
|             .font(.title) | ||||
|             .bold() | ||||
|         VStack { | ||||
|             if flashcard.shown && flashcard.lastSeenOn != nil { | ||||
|             if flashcard.lastSeenOn != nil { | ||||
|                 Text("Last seen: " + model.getDateFormatter().string(from: flashcard.lastSeenOn!)) | ||||
|                     .font(.subheadline) | ||||
|             } | ||||
|   | ||||
| @@ -30,12 +30,6 @@ class WordAXModelView: ObservableObject { | ||||
|     public func getDateFormatter() -> 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