Results screen written
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
//  FlashCardLessonsResultsView.swift
 | 
					//  FlashCardLessonResultsView.swift
 | 
				
			||||||
//  Toki Trainer
 | 
					//  Toki Trainer
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//  Created by Avery Ada Pace on 11/8/21.
 | 
					//  Created by Avery Ada Pace on 11/8/21.
 | 
				
			||||||
@@ -7,14 +7,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import SwiftUI
 | 
					import SwiftUI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct FlashCardLessonsResultsView: View {
 | 
					struct FlashCardLessonResultsView: View {
 | 
				
			||||||
    var body: some View {
 | 
					    var body: some View {
 | 
				
			||||||
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
 | 
					        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct FlashCardLessonsResultsView_Previews: PreviewProvider {
 | 
					struct FlashCardLessonResultsView_Previews: PreviewProvider {
 | 
				
			||||||
    static var previews: some View {
 | 
					    static var previews: some View {
 | 
				
			||||||
        FlashCardLessonsResultsView()
 | 
					        FlashCardLessonResultsView()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,10 @@ struct FlashCardLessonsView: View {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            Text("Please Select a Lesson")
 | 
				
			||||||
 | 
					                .font(.title)
 | 
				
			||||||
            .navigationBarTitle("Lessons")
 | 
					            .navigationBarTitle("Lessons")
 | 
				
			||||||
 | 
					            .navigationViewStyle(StackNavigationViewStyle())
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -88,5 +91,7 @@ struct FlashCardLessonsView: View {
 | 
				
			|||||||
struct FlashCardLessonsView_Previews: PreviewProvider {
 | 
					struct FlashCardLessonsView_Previews: PreviewProvider {
 | 
				
			||||||
    static var previews: some View {
 | 
					    static var previews: some View {
 | 
				
			||||||
        FlashCardLessonsView()
 | 
					        FlashCardLessonsView()
 | 
				
			||||||
 | 
					        FlashCardLessonsView()
 | 
				
			||||||
 | 
					            .previewDevice(/*@START_MENU_TOKEN@*/"iPad Pro (9.7-inch)"/*@END_MENU_TOKEN@*/)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ struct FlashCardView: View {
 | 
				
			|||||||
    @State var currentLesson: String
 | 
					    @State var currentLesson: String
 | 
				
			||||||
    @State var dictionary: [TokiDictEntry]
 | 
					    @State var dictionary: [TokiDictEntry]
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    @State private var resultsShown = false
 | 
				
			||||||
 | 
					    @State private var results: [String: Bool] = [:]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    init(lesson: String, passedDictionary: [TokiDictEntry]) {
 | 
					    init(lesson: String, passedDictionary: [TokiDictEntry]) {
 | 
				
			||||||
        self.dictionary = passedDictionary
 | 
					        self.dictionary = passedDictionary
 | 
				
			||||||
        currentLesson = lesson
 | 
					        currentLesson = lesson
 | 
				
			||||||
@@ -28,18 +31,13 @@ struct FlashCardView: View {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    var body: some View {
 | 
					    var body: some View {
 | 
				
			||||||
        VStack {
 | 
					        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 {
 | 
					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 {
 | 
					struct FlashCardStack: View {
 | 
				
			||||||
    @Environment(\.managedObjectContext) private var viewContext
 | 
					    @Environment(\.managedObjectContext) private var viewContext
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -68,15 +84,13 @@ struct FlashCardStack: View {
 | 
				
			|||||||
    @State private var flashCardsVertOffset: [CGFloat] = []
 | 
					    @State private var flashCardsVertOffset: [CGFloat] = []
 | 
				
			||||||
    @State private var flashCardsResults: [FlashCardResult] = []
 | 
					    @State private var flashCardsResults: [FlashCardResult] = []
 | 
				
			||||||
    @State private var helperFadeOutOverlay = false
 | 
					    @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
 | 
					    @State private var currentFlashCard = 0
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    init(currentLesson: String, dictionary: [TokiDictEntry]) {
 | 
					 | 
				
			||||||
        self.currentLesson = currentLesson
 | 
					 | 
				
			||||||
        self.dictionary = dictionary
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    var body: some View {
 | 
					    var body: some View {
 | 
				
			||||||
        VStack {
 | 
					        VStack {
 | 
				
			||||||
            ZStack {
 | 
					            ZStack {
 | 
				
			||||||
@@ -204,13 +218,16 @@ struct FlashCardStack: View {
 | 
				
			|||||||
    func nextFlashCard() {
 | 
					    func nextFlashCard() {
 | 
				
			||||||
        flashCardsVertOffset[currentFlashCard] = -1000
 | 
					        flashCardsVertOffset[currentFlashCard] = -1000
 | 
				
			||||||
        if currentFlashCard == (flashCards.count - 1) {
 | 
					        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
 | 
					            return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        currentFlashCard += 1
 | 
					        currentFlashCard += 1
 | 
				
			||||||
        flashCardsVertOffset[currentFlashCard] = 50
 | 
					        flashCardsVertOffset[currentFlashCard] = 50
 | 
				
			||||||
        flashCardsAreInteractive[currentFlashCard] = true
 | 
					        flashCardsAreInteractive[currentFlashCard] = true
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        self.helperFadeOutOverlay = true
 | 
					        self.helperFadeOutOverlay = true
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if ((flashCards.count - 1) - currentFlashCard) > 3 {
 | 
					        if ((flashCards.count - 1) - currentFlashCard) > 3 {
 | 
				
			||||||
@@ -276,7 +293,7 @@ struct FlashCard: View {
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        Text("")
 | 
					        Text("")
 | 
				
			||||||
            .modifier(CardFlipModifier(isFaceDown: isFaceDown, frontText: dictionaryEntry.word, backText: concatenateDefinitions()))
 | 
					            .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)
 | 
					            .offset(x: isFaceDown ? -dragAmount : dragAmount, y: abs(dragAmount) / 10)
 | 
				
			||||||
            .rotationEffect(.degrees(isFaceDown ? -(dragAmount / 50) : dragAmount / 50))
 | 
					            .rotationEffect(.degrees(isFaceDown ? -(dragAmount / 50) : dragAmount / 50))
 | 
				
			||||||
            .font(.title)
 | 
					            .font(.title)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user