2021-11-03 18:21:22 +00:00
|
|
|
//
|
|
|
|
// ContentView.swift
|
|
|
|
// Toki Trainer
|
|
|
|
//
|
|
|
|
// Created by Avery Ada Pace on 11/2/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import CoreData
|
|
|
|
|
2021-11-04 18:10:22 +00:00
|
|
|
extension String: Identifiable {
|
|
|
|
public var id: String { self }
|
|
|
|
}
|
|
|
|
|
2021-11-03 18:21:22 +00:00
|
|
|
struct ContentView: View {
|
2021-11-04 18:10:22 +00:00
|
|
|
@Environment(\.managedObjectContext) private var viewContext
|
2021-11-03 18:21:22 +00:00
|
|
|
|
2021-11-07 06:25:18 +00:00
|
|
|
@State private var tokiInput: String = ""
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
TabView {
|
|
|
|
TranslatorView()
|
2021-11-07 18:03:41 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "pencil")
|
|
|
|
Text("Phrase Lookup")
|
|
|
|
}
|
2021-11-08 17:24:46 +00:00
|
|
|
FlashCardLessonsView()
|
2021-11-07 06:25:18 +00:00
|
|
|
.tabItem {
|
|
|
|
Image(systemName: "character.textbox")
|
|
|
|
Text("Flash Cards")
|
|
|
|
}
|
2021-11-07 22:15:11 +00:00
|
|
|
FlashCardResultsView()
|
2021-11-07 18:03:41 +00:00
|
|
|
.tabItem {
|
2021-11-07 23:15:00 +00:00
|
|
|
Image(systemName: "number.circle")
|
2021-11-07 18:03:41 +00:00
|
|
|
Text("Flash Card Results")
|
|
|
|
}
|
2021-11-07 06:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func openPartsOfSpeechView() {
|
|
|
|
print("Button pressed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TranslatorView: View {
|
2021-11-04 18:10:22 +00:00
|
|
|
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
|
2021-11-06 01:04:03 +00:00
|
|
|
@State private var selectedPartOfSpeech: String?
|
2021-11-05 20:21:46 +00:00
|
|
|
@State private var tokiInput: String = ""
|
2021-11-07 06:25:18 +00:00
|
|
|
|
2021-11-03 18:21:22 +00:00
|
|
|
var body: some View {
|
2021-11-03 23:38:53 +00:00
|
|
|
VStack {
|
2021-11-05 20:21:46 +00:00
|
|
|
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
|
2021-11-03 23:38:53 +00:00
|
|
|
.multilineTextAlignment(.center)
|
2021-11-05 20:21:46 +00:00
|
|
|
.textInputAutocapitalization(.never)
|
|
|
|
.disableAutocorrection(true)
|
2021-11-03 23:38:53 +00:00
|
|
|
.padding(8)
|
2021-11-05 20:21:46 +00:00
|
|
|
.onSubmit {
|
|
|
|
tokiDictViewModel.filterDictionary(tokiInput)
|
|
|
|
}
|
2021-11-04 18:10:22 +00:00
|
|
|
List(tokiDictViewModel.dictionary, id: \.word) { entry in
|
2021-11-03 23:38:53 +00:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(entry.word)
|
|
|
|
.font(.title)
|
|
|
|
ForEach(entry.definitions, id: \.pos) { definition in
|
|
|
|
HStack(alignment: .top) {
|
2021-11-04 18:10:22 +00:00
|
|
|
Button(action: {
|
|
|
|
self.selectedPartOfSpeech = String(definition.pos)
|
|
|
|
}) {
|
2021-11-03 23:38:53 +00:00
|
|
|
Text(definition.pos)
|
|
|
|
.frame(width: 45, height: 22, alignment: .center)
|
|
|
|
.foregroundColor(.black)
|
|
|
|
.background(Color(K.posColors[definition.pos]!))
|
|
|
|
.cornerRadius(5.0)
|
|
|
|
.padding(4)
|
|
|
|
}
|
2021-11-04 18:10:22 +00:00
|
|
|
.buttonStyle(BorderlessButtonStyle())
|
2021-11-03 23:38:53 +00:00
|
|
|
Text(definition.definition)
|
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
|
|
.padding(4)
|
|
|
|
}
|
2021-11-03 18:21:22 +00:00
|
|
|
}
|
2021-11-03 23:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-04 18:10:22 +00:00
|
|
|
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
|
2021-11-06 01:04:03 +00:00
|
|
|
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS, partsOfSpeech: tokiDictViewModel.partsOfSpeech)
|
2021-11-03 23:38:53 +00:00
|
|
|
}
|
2021-11-03 18:21:22 +00:00
|
|
|
}
|
2021-11-04 18:10:22 +00:00
|
|
|
}
|
2021-11-03 18:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-11-07 18:03:41 +00:00
|
|
|
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
2021-11-03 18:21:22 +00:00
|
|
|
}
|
|
|
|
}
|