UI update for advanced search options, search button

This commit is contained in:
maddiebaka 2023-11-17 11:46:10 -05:00
parent da83c34090
commit 5a5e56cb66
3 changed files with 82 additions and 31 deletions

View File

@ -150,6 +150,19 @@
}
}
}
},
"Search for:" : {
"localizations" : {
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Options de recherche"
}
}
}
},
"Words" : {
}
},
"version" : "1.0"

View File

@ -17,33 +17,59 @@ struct DictionaryView: View {
@State private var tokiInput: String = ""
@State private var selectedPartOfSpeech: String?
@State private var advancedSearchEnabled = false
@State var searchMode: SearchMode = .Dictionary
@FocusState private var searchInputIsForuced: Bool
var body: some View {
VStack {
TextField("Search", text: $tokiInput)
.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
HStack {
TextField("Search", text: $tokiInput)
//.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
filterByInput()
//tokiDictViewModel.filterDictionaryEnglishMode(tokiInput)
}
Button {
hideKeyboard()
filterByInput()
//tokiDictViewModel.filterDictionaryEnglishMode(tokiInput)
} label: {
Image(systemName: "magnifyingglass")
}
Picker("Language", selection: $searchMode) {
Text("Dictionary").tag(SearchMode.Dictionary)
Text("Definitions").tag(SearchMode.Definitions)
.buttonStyle(.borderedProminent)
Button(action: {
withAnimation {
advancedSearchEnabled.toggle()
}
}, label: {
Image(systemName: "slider.horizontal.2.square.on.square")
})
.buttonStyle(.bordered)
}
.pickerStyle(SegmentedPickerStyle())
.onTapGesture {
if self.searchMode == SearchMode.Dictionary {
self.searchMode = SearchMode.Definitions
} else {
self.searchMode = SearchMode.Dictionary
.padding([.top, .leading, .trailing], 8)
if advancedSearchEnabled == true {
VStack {
Text("Search for:")
Picker("Language", selection: $searchMode) {
Text("Words").tag(SearchMode.Dictionary)
Text("Definitions").tag(SearchMode.Definitions)
}
.pickerStyle(SegmentedPickerStyle())
.onTapGesture {
if self.searchMode == SearchMode.Dictionary {
self.searchMode = SearchMode.Definitions
} else {
self.searchMode = SearchMode.Dictionary
}
filterByInput()
}
}
filterByInput()
.padding([.leading, .trailing], 8)
}
List(tokiDictViewModel.dictionary, id: \.word) { entry in
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)
@ -70,6 +96,16 @@ struct DictionaryView: View {
}
}
extension View {
func searchOptionsButtonStyle(toggle: Binding<Bool>) -> any PrimitiveButtonStyle {
if toggle.wrappedValue == true {
BorderedButtonStyle()
} else {
BorderlessButtonStyle()
}
}
}
struct DictionaryView_Previews: PreviewProvider {

View File

@ -15,22 +15,24 @@ struct TranslatorView: View {
var body: some View {
VStack {
// Button(action: changeTranslationDirection) {
// #warning("This needs to actually switch how the lookup happens")
// if translateToTokiPona == true {
// LanguageDirectionView(from: "English", to: "Toki Pona", fromColor: .blue, toColor: .cyan)
// } else {
// LanguageDirectionView(from: "Toki Pona", to: "English", fromColor: .cyan, toColor: .blue)
// }
// }
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
HStack {
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
tokiDictViewModel.translatePhrase(tokiInput)
}
Button {
hideKeyboard()
tokiDictViewModel.translatePhrase(tokiInput)
} label: {
Image(systemName: "magnifyingglass")
}
.buttonStyle(.borderedProminent)
}
.padding([.top, .leading, .trailing], 8)
if tokiInput.count == 0 {
List(tokiDictViewModel.dictionary, id: \.word) { entry in
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)