TokiTrainer/Toki Trainer/Views/WordListViews/DictionaryView.swift

45 lines
1.4 KiB
Swift

//
// DictionaryView.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/4/22.
//
import SwiftUI
struct DictionaryView: View {
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
@State private var tokiInput: String = ""
@State private var selectedPartOfSpeech: String?
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)
}
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
}
.onChange(of: tokiInput) { newValue in
tokiDictViewModel.filterDictionaryEnglishMode(newValue)
}
}
}
}
struct DictionaryView_Previews: PreviewProvider {
static var previews: some View {
DictionaryView().previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}