diff --git a/Toki Trainer/Views/FlashCardLessonResultsView.swift b/Toki Trainer/Views/FlashCardLessonResultsView.swift index 41943d2..73fa494 100644 --- a/Toki Trainer/Views/FlashCardLessonResultsView.swift +++ b/Toki Trainer/Views/FlashCardLessonResultsView.swift @@ -1,5 +1,5 @@ // -// FlashCardLessonsResultsView.swift +// FlashCardLessonResultsView.swift // Toki Trainer // // Created by Avery Ada Pace on 11/8/21. @@ -7,14 +7,14 @@ import SwiftUI -struct FlashCardLessonsResultsView: View { +struct FlashCardLessonResultsView: View { var body: some View { Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) } } -struct FlashCardLessonsResultsView_Previews: PreviewProvider { +struct FlashCardLessonResultsView_Previews: PreviewProvider { static var previews: some View { - FlashCardLessonsResultsView() + FlashCardLessonResultsView() } } diff --git a/Toki Trainer/Views/FlashCardLessonsView.swift b/Toki Trainer/Views/FlashCardLessonsView.swift index 41ed323..e342d3a 100644 --- a/Toki Trainer/Views/FlashCardLessonsView.swift +++ b/Toki Trainer/Views/FlashCardLessonsView.swift @@ -80,7 +80,10 @@ struct FlashCardLessonsView: View { } } } + Text("Please Select a Lesson") + .font(.title) .navigationBarTitle("Lessons") + .navigationViewStyle(StackNavigationViewStyle()) } } } @@ -88,5 +91,7 @@ struct FlashCardLessonsView: View { struct FlashCardLessonsView_Previews: PreviewProvider { static var previews: some View { FlashCardLessonsView() + FlashCardLessonsView() + .previewDevice(/*@START_MENU_TOKEN@*/"iPad Pro (9.7-inch)"/*@END_MENU_TOKEN@*/) } } diff --git a/Toki Trainer/Views/FlashCardView.swift b/Toki Trainer/Views/FlashCardView.swift index 25184de..355f69e 100644 --- a/Toki Trainer/Views/FlashCardView.swift +++ b/Toki Trainer/Views/FlashCardView.swift @@ -21,6 +21,9 @@ struct FlashCardView: View { @State var currentLesson: String @State var dictionary: [TokiDictEntry] + @State private var resultsShown = false + @State private var results: [String: Bool] = [:] + init(lesson: String, passedDictionary: [TokiDictEntry]) { self.dictionary = passedDictionary currentLesson = lesson @@ -28,18 +31,13 @@ struct FlashCardView: View { var body: some View { VStack { - FlashCardStack(currentLesson: currentLesson, dictionary: dictionary) + if !resultsShown { + FlashCardStack(currentLesson: currentLesson, dictionary: dictionary, resultsShown: $resultsShown, results: $results) + } else { + ResultsView(results: $results) + } } } - -// func getDictionary() -> [TokiDictEntry] { -// if dictionary != nil { -// dictionary?.shuffle() -// return dictionary ?? [] -// } else { -// return flashCardsViewModel.randomDictionary -// } -// } } extension Binding { @@ -53,6 +51,24 @@ extension Binding { } } +struct ResultsView: View { + + @Binding var results: [String: Bool] + + var body: some View { + VStack { + Text("Results") + .font(.title) + //ForEach(results.sorted(by: >), id: \.key) { key, value in + //ForEach(results.keys, id: \.self) { word in + List(Array(results.keys).sorted(by: <), id: \.self) { result in + Text(result) + .listRowBackground(results[result]! ? Color.green : Color.red) + } + } + } +} + struct FlashCardStack: View { @Environment(\.managedObjectContext) private var viewContext @@ -68,15 +84,13 @@ struct FlashCardStack: View { @State private var flashCardsVertOffset: [CGFloat] = [] @State private var flashCardsResults: [FlashCardResult] = [] @State private var helperFadeOutOverlay = false - @State private var deckCompleteFadeInOverlay = false + @State private var deckComplete = false + + @Binding var resultsShown: Bool + @Binding var results: [String: Bool] @State private var currentFlashCard = 0 - init(currentLesson: String, dictionary: [TokiDictEntry]) { - self.currentLesson = currentLesson - self.dictionary = dictionary - } - var body: some View { VStack { ZStack { @@ -204,13 +218,16 @@ struct FlashCardStack: View { func nextFlashCard() { flashCardsVertOffset[currentFlashCard] = -1000 if currentFlashCard == (flashCards.count - 1) { + for (index, card) in flashCards.enumerated() { + self.results[card.dictionaryEntry.word] = (flashCardsResults[index] == FlashCardResult.Correct) ? true : false + } + self.resultsShown = true return } currentFlashCard += 1 flashCardsVertOffset[currentFlashCard] = 50 flashCardsAreInteractive[currentFlashCard] = true - self.helperFadeOutOverlay = true if ((flashCards.count - 1) - currentFlashCard) > 3 { @@ -276,7 +293,7 @@ struct FlashCard: View { Text("") .modifier(CardFlipModifier(isFaceDown: isFaceDown, frontText: dictionaryEntry.word, backText: concatenateDefinitions())) - .frame(width: 0.8 * screen.width, height: 200) + .frame(width: 300, height: 200) .offset(x: isFaceDown ? -dragAmount : dragAmount, y: abs(dragAmount) / 10) .rotationEffect(.degrees(isFaceDown ? -(dragAmount / 50) : dragAmount / 50)) .font(.title)