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" "version" : "1.0"

View File

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

View File

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