Save which cards are favorite
This commit is contained in:
@@ -24,6 +24,7 @@ extension Flashcard {
|
||||
@NSManaged public var nextSpacedRepetitionMilestone: Int64
|
||||
@NSManaged public var shown: Bool
|
||||
@NSManaged public var shownCount: Int64
|
||||
@NSManaged public var favorite: Bool
|
||||
}
|
||||
|
||||
extension Flashcard : Identifiable {
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>_XCCurrentVersionName</key>
|
||||
<string>WordAX.xcdatamodel</string>
|
||||
<string>WordAX0.0.4.xcdatamodel</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="desc" optional="YES" attributeType="String"/>
|
||||
<attribute name="favorite" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="lastSeenOn" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="name" optional="YES" attributeType="String"/>
|
||||
<attribute name="nextSpacedRepetitionMilestone" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="shown" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="shownCount" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
</entity>
|
||||
</model>
|
||||
@@ -126,6 +126,5 @@ struct AnkiView: View {
|
||||
|
||||
#Preview {
|
||||
AnkiView()
|
||||
.environmentObject(WordAXModelView())
|
||||
.environment(\.managedObjectContext, DataController.preview.container.viewContext)
|
||||
}
|
||||
|
||||
@@ -8,26 +8,32 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FlashCardListRowView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
var flashcard: Flashcard
|
||||
@State var favorite = true
|
||||
@State var flashcard: Flashcard
|
||||
@State private var refresh: UUID = UUID()
|
||||
var body: some View {
|
||||
HStack {
|
||||
Group {
|
||||
if favorite {
|
||||
if !flashcard.favorite {
|
||||
Image(systemName: "star")
|
||||
} else {
|
||||
ZStack {
|
||||
Image(systemName: "star.fill")
|
||||
.foregroundStyle(.yellow)
|
||||
Image(systemName: "star")
|
||||
.opacity(0.4)
|
||||
.opacity(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
self.favorite = !self.favorite
|
||||
flashcard.favorite.toggle()
|
||||
do {
|
||||
try flashcard.managedObjectContext?.save()
|
||||
} catch {
|
||||
print("Something went wrong while saving favorite cards, please try again")
|
||||
}
|
||||
refresh = UUID()
|
||||
}
|
||||
.id(refresh)
|
||||
.padding(.trailing)
|
||||
VStack {
|
||||
Text(flashcard.name ?? "Unknown")
|
||||
@@ -41,7 +47,6 @@ struct FlashCardListRowView: View {
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FlashCardListView: View {
|
||||
@EnvironmentObject var model: WordAXModelView
|
||||
@State var showDescription = true
|
||||
@State var addFlashcard = false
|
||||
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "dateAdded", ascending: false)]) var flashcards: FetchedResults<Flashcard>
|
||||
@@ -34,8 +33,7 @@ struct FlashCardListView: View {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Text("You currently don't have any flashcards. To add flashcards, either click at the '+' button at the top or you can download them from the store (coming soon)")
|
||||
.padding()
|
||||
.background(.purple)
|
||||
|
||||
Reference in New Issue
Block a user