Refactor, decompose and add previews. Fix part of speech sheet pop over
This commit is contained in:
44
Toki Trainer/Views/WordListViews/DictionaryView.swift
Normal file
44
Toki Trainer/Views/WordListViews/DictionaryView.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// DictionaryView.swift
|
||||
// Toki Trainer
|
||||
//
|
||||
// Created by maddiefuzz on 10/4/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct DictionaryView: View {
|
||||
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
|
||||
|
||||
@State var tokiInput: String = ""
|
||||
@State 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.filterDictionary(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DictionaryView_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
DictionaryView(selectedPartOfSpeech: "n").previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user