Flash Cards now calculate percentage from last attempt
This commit is contained in:
parent
1c928fa876
commit
64a9849517
@ -74,7 +74,7 @@ struct FlashCardLessonsView: View {
|
|||||||
calculateStatistics(lesson)
|
calculateStatistics(lesson)
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
if statisticsCalculated && lessonStatistics[lesson.lesson] != 0.0 && lessonStatistics[lesson.lesson] != nil {
|
if statisticsCalculated && lessonStatistics[lesson.lesson] != nil {
|
||||||
Text("\(String(format: "%.0f", lessonStatistics[lesson.lesson]!)) %")
|
Text("\(String(format: "%.0f", lessonStatistics[lesson.lesson]!)) %")
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ struct FlashCardStack: View {
|
|||||||
@State private var flashCardsAreInteractive: [Bool] = []
|
@State private var flashCardsAreInteractive: [Bool] = []
|
||||||
@State private var flashCardsVertOffset: [CGFloat] = []
|
@State private var flashCardsVertOffset: [CGFloat] = []
|
||||||
@State private var flashCardsResults: [FlashCardResult] = []
|
@State private var flashCardsResults: [FlashCardResult] = []
|
||||||
@State private var fadeOutOverlay = false
|
@State private var helperFadeOutOverlay = false
|
||||||
|
@State private var deckCompleteFadeInOverlay = false
|
||||||
|
|
||||||
@State private var currentFlashCard = 0
|
@State private var currentFlashCard = 0
|
||||||
|
|
||||||
@ -82,18 +83,18 @@ struct FlashCardStack: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.overlay(HStack {
|
}
|
||||||
Image(systemName: "arrow.backward")
|
.overlay(HStack {
|
||||||
Text("Incorrect")
|
Image(systemName: "arrow.backward")
|
||||||
Spacer()
|
Text("Incorrect")
|
||||||
Text("Correct")
|
Spacer()
|
||||||
Image(systemName: "arrow.right")
|
Text("Correct")
|
||||||
}.opacity(fadeOutOverlay ? 0.0 : 1.0), alignment: .top)
|
Image(systemName: "arrow.right")
|
||||||
|
}.opacity(helperFadeOutOverlay ? 0.0 : 1.0), alignment: .top)
|
||||||
|
.onAppear {
|
||||||
|
initFlashCards()
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
.onAppear {
|
|
||||||
initFlashCards()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initFlashCards() {
|
func initFlashCards() {
|
||||||
@ -117,6 +118,17 @@ struct FlashCardStack: View {
|
|||||||
|
|
||||||
flashCardsVertOffset[currentFlashCard] = 50
|
flashCardsVertOffset[currentFlashCard] = 50
|
||||||
flashCardsAreInteractive[currentFlashCard] = true
|
flashCardsAreInteractive[currentFlashCard] = true
|
||||||
|
|
||||||
|
resetLessonAnswersCoreData()
|
||||||
|
}
|
||||||
|
|
||||||
|
func resetLessonAnswersCoreData() {
|
||||||
|
for lessonAnswer in lessonAnswers {
|
||||||
|
if lessonAnswer.lesson == currentLesson {
|
||||||
|
viewContext.delete(lessonAnswer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try? viewContext.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setFlashCardAnswersCoreData(_ correct: Bool) {
|
func setFlashCardAnswersCoreData(_ correct: Bool) {
|
||||||
@ -191,7 +203,7 @@ struct FlashCardStack: View {
|
|||||||
flashCardsAreInteractive[currentFlashCard] = true
|
flashCardsAreInteractive[currentFlashCard] = true
|
||||||
|
|
||||||
|
|
||||||
self.fadeOutOverlay = true
|
self.helperFadeOutOverlay = true
|
||||||
|
|
||||||
if ((flashCards.count - 1) - currentFlashCard) > 3 {
|
if ((flashCards.count - 1) - currentFlashCard) > 3 {
|
||||||
print("flashCards: \(flashCards.count)")
|
print("flashCards: \(flashCards.count)")
|
||||||
@ -334,9 +346,9 @@ struct CardFlipModifier: AnimatableModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct FlashCardView_Previews: PreviewProvider {
|
struct FlashCardView_Previews: PreviewProvider {
|
||||||
static var viewModel = TokiDictionaryViewModel()
|
static var lessonVM = FlashCardLessonsViewModel()
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
FlashCardView(lesson: "Preview", passedDictionary: viewModel.dictionary).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
FlashCardView(lesson: lessonVM.lessons[0].lesson, passedDictionary: lessonVM.lessons[0].words).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user