Add option to add hint to a card

This commit is contained in:
2024-07-04 21:36:32 +02:00
parent f6c4e68698
commit 65d3974d6c
2 changed files with 19 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ struct AddFlashCardView: View {
@State var selectedDeck: Deck?
@State var createDisabled: Bool = true
@State var flashcard: Flashcard
@State var hint: String = ""
var edit: Bool = false
var body: some View {
NavigationStack {
@@ -25,6 +26,10 @@ struct AddFlashCardView: View {
TextField("Name", text: $text)
.focused($focus)
TextField("Description", text: $description, axis: .vertical)
TextField("Hint", text: $hint, axis: .vertical)
.lineLimit(3, reservesSpace: true)
}
Section(header: Text("Deck details")) {
Picker("Deck", selection: $selectedDeck) {
ForEach(decks) { deck in
Text(deck.name ?? "Unknown deck name")
@@ -70,6 +75,7 @@ struct AddFlashCardView: View {
flashcard.name = self.text
flashcard.desc = self.description
flashcard.deck = selectedDeck
flashcard.hint = self.hint
if !edit {
flashcard.nextSpacedRepetitionMilestone = 0
flashcard.lastSeenOn = nil

View File

@@ -42,20 +42,20 @@ struct FlashCardView: View {
} else {
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)
}
if !showDescription && flashcard.hint != nil {
if showHint {
Text((flashcard.hint != nil) ? "Hint: \(flashcard.hint ?? "")" : "")
.padding()
.font(.footnote)
} else {
}
Button {
showHint.toggle()
} label: {
Text(showHint ? "Hide Hint" : "Show Hint")
.padding()
}
// .disabled(flashcard.hint == nil)
}
}
.padding([.horizontal, .top])