2022-10-08 10:36:19 +00:00
|
|
|
//
|
|
|
|
// DictionaryView.swift
|
|
|
|
// Toki Trainer
|
|
|
|
//
|
|
|
|
// Created by maddiefuzz on 10/4/22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct DictionaryView: View {
|
|
|
|
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
|
|
|
|
|
2022-10-26 19:46:50 +00:00
|
|
|
@State private var tokiInput: String = ""
|
|
|
|
@State private var selectedPartOfSpeech: String?
|
2022-10-08 10:36:19 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
|
|
TextField("Search", text: $tokiInput)
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.textInputAutocapitalization(.never)
|
|
|
|
.disableAutocorrection(true)
|
|
|
|
.padding(8)
|
|
|
|
.onSubmit {
|
|
|
|
tokiDictViewModel.filterDictionary(tokiInput)
|
|
|
|
}
|
|
|
|
List(tokiDictViewModel.dictionary, id: \.word) { entry in
|
|
|
|
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)
|
|
|
|
}
|
2022-10-08 12:35:14 +00:00
|
|
|
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
|
|
|
|
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
|
|
|
|
}
|
2022-10-08 10:36:19 +00:00
|
|
|
.onChange(of: tokiInput) { newValue in
|
2022-10-26 19:46:50 +00:00
|
|
|
tokiDictViewModel.filterDictionaryEnglishMode(newValue)
|
2022-10-08 10:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-08 12:35:14 +00:00
|
|
|
|
|
|
|
struct DictionaryView_Previews: PreviewProvider {
|
|
|
|
|
|
|
|
static var previews: some View {
|
2022-10-26 19:46:50 +00:00
|
|
|
DictionaryView().previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
2022-10-08 12:35:14 +00:00
|
|
|
}
|
|
|
|
}
|