Add show hint option, if hint is on the card
This commit is contained in:
@@ -53,6 +53,7 @@ class DataController: ObservableObject {
|
|||||||
flashcard.dateAdded = [Date(), Date().addingTimeInterval(-86400), Date().addingTimeInterval(-172800)].randomElement()!
|
flashcard.dateAdded = [Date(), Date().addingTimeInterval(-86400), Date().addingTimeInterval(-172800)].randomElement()!
|
||||||
flashcard.favorite = [true, false].randomElement()!
|
flashcard.favorite = [true, false].randomElement()!
|
||||||
flashcard.deck = decks.randomElement()
|
flashcard.deck = decks.randomElement()
|
||||||
|
flashcard.hint = ["This is a small hint", "Hint", "This is a very long hint that maybe should be even longer olorem ipsum to cover everything but I don't know what else to write Lorem Ipsum", "This is something in between hint that doesn'coveres the mid cases Lorem Ipsujm Lor"].randomElement()
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
try viewContext.save()
|
try viewContext.save()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ extension Flashcard {
|
|||||||
@NSManaged public var shown: Bool
|
@NSManaged public var shown: Bool
|
||||||
@NSManaged public var shownCount: Int64
|
@NSManaged public var shownCount: Int64
|
||||||
@NSManaged public var deck: Deck?
|
@NSManaged public var deck: Deck?
|
||||||
|
@NSManaged public var hint: String?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?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="">
|
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22757" systemVersion="23E224" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
|
||||||
<entity name="Deck" representedClassName="Deck" syncable="YES" coreSpotlightDisplayNameExpression="Deck">
|
<entity name="Deck" representedClassName="Deck" syncable="YES" coreSpotlightDisplayNameExpression="Deck">
|
||||||
<attribute name="dateAdded" attributeType="Date" defaultDateTimeInterval="736207200" usesScalarValueType="NO"/>
|
<attribute name="dateAdded" attributeType="Date" defaultDateTimeInterval="736207200" usesScalarValueType="NO"/>
|
||||||
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
|
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
<attribute name="dateAdded" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
<attribute name="dateAdded" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||||
<attribute name="desc" optional="YES" attributeType="String" spotlightIndexingEnabled="YES"/>
|
<attribute name="desc" optional="YES" attributeType="String" spotlightIndexingEnabled="YES"/>
|
||||||
<attribute name="favorite" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
<attribute name="favorite" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||||
|
<attribute name="hint" optional="YES" attributeType="String"/>
|
||||||
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||||
<attribute name="lastSeenOn" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
<attribute name="lastSeenOn" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||||
<attribute name="name" optional="YES" attributeType="String" spotlightIndexingEnabled="YES"/>
|
<attribute name="name" optional="YES" attributeType="String" spotlightIndexingEnabled="YES"/>
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ struct AnkiView: View {
|
|||||||
.sheet(isPresented: self.$deckViewVisible) {
|
.sheet(isPresented: self.$deckViewVisible) {
|
||||||
DeckSelectView(selection: $decksToDisplay, active: $deckViewVisible)
|
DeckSelectView(selection: $decksToDisplay, active: $deckViewVisible)
|
||||||
}
|
}
|
||||||
.onChange(of: deckViewVisible) { _ in
|
.onChange(of: deckViewVisible) {
|
||||||
refreshFlashcards()
|
refreshFlashcards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ struct FlashCardView: View {
|
|||||||
@Binding var showDescription: Bool
|
@Binding var showDescription: Bool
|
||||||
@Environment(\.colorScheme) var colorScheme
|
@Environment(\.colorScheme) var colorScheme
|
||||||
@State var editFlashcard: Bool = false
|
@State var editFlashcard: Bool = false
|
||||||
|
@State var showHint: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let flashcardText = Text(flashcard.name ?? "Unknown")
|
let flashcardText = Text(flashcard.name ?? "Unknown")
|
||||||
.font(.title)
|
.font(.title)
|
||||||
|
.textSelection(.enabled)
|
||||||
.bold()
|
.bold()
|
||||||
VStack {
|
VStack {
|
||||||
// TODO: Figure out if this and create/edit menu could be more similar?
|
// TODO: Figure out if this and create/edit menu could be more similar?
|
||||||
@@ -33,7 +34,6 @@ struct FlashCardView: View {
|
|||||||
.padding(.bottom)
|
.padding(.bottom)
|
||||||
}
|
}
|
||||||
flashcardText
|
flashcardText
|
||||||
.textSelection(.enabled)
|
|
||||||
Divider()
|
Divider()
|
||||||
.background(colorScheme == .light ? Color.black : Color.white)
|
.background(colorScheme == .light ? Color.black : Color.white)
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
@@ -42,6 +42,21 @@ struct FlashCardView: View {
|
|||||||
} else {
|
} else {
|
||||||
flashcardText
|
flashcardText
|
||||||
}
|
}
|
||||||
|
if flashcard.hint != nil {
|
||||||
|
if !showDescription {
|
||||||
|
Button {
|
||||||
|
showHint.toggle()
|
||||||
|
} label: {
|
||||||
|
Text(showHint ? "Hide Hint" : "Show Hint")
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
if showHint {
|
||||||
|
Text((flashcard.hint != nil) ? "Hint: \(flashcard.hint ?? "")" : "")
|
||||||
|
.padding()
|
||||||
|
.font(.footnote)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding([.horizontal, .top])
|
.padding([.horizontal, .top])
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
@@ -63,7 +78,7 @@ struct FlashCardView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
@State var showDescription = true
|
@State var showDescription = false
|
||||||
let flashcard = try? DataController.preview.viewContext.fetch(Flashcard.fetchRequest()).first
|
let flashcard = try? DataController.preview.viewContext.fetch(Flashcard.fetchRequest()).first
|
||||||
return FlashCardView(flashcard: flashcard!, showDescription: $showDescription)
|
return FlashCardView(flashcard: flashcard!, showDescription: $showDescription)
|
||||||
.environment(\.managedObjectContext, DataController.preview.container.viewContext)
|
.environment(\.managedObjectContext, DataController.preview.container.viewContext)
|
||||||
|
|||||||
Reference in New Issue
Block a user