Search: Add random text to the searchbar
It's redundant to have the navgiation title of the Search view as "Search" and the searchbar to have the same title. Make the searchbar have randomized quotes (from a fixed set) that doesn't repeat cases. Maybe make this customizable in the future? Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
cbe3d17be1
commit
f8b6ea6ba7
2 changed files with 45 additions and 1 deletions
|
|
@ -15,10 +15,23 @@ struct ContentView: View {
|
|||
@EnvironmentObject var pluginManager: PluginManager
|
||||
@EnvironmentObject var toastModel: ToastViewModel
|
||||
|
||||
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText: Bool = false
|
||||
|
||||
@State private var isEditingSearch = false
|
||||
@State private var isSearching = false
|
||||
@State private var searchText: String = ""
|
||||
|
||||
@State private var lastSearchTextIndex: Int = -1
|
||||
@State private var searchBarText: String = "Search"
|
||||
let searchBarTextArray: [String] = [
|
||||
"What's on your mind?",
|
||||
"Discover something interesting",
|
||||
"Find an engaging show",
|
||||
"Feeling adventurous?",
|
||||
"Look for something new",
|
||||
"The classics are a good idea"
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
NavView {
|
||||
List {
|
||||
|
|
@ -35,6 +48,11 @@ struct ContentView: View {
|
|||
Text("No results found")
|
||||
}
|
||||
}
|
||||
.onChange(of: searchText) { newText in
|
||||
if newText.isEmpty && isSearching {
|
||||
searchBarText = getSearchBarText()
|
||||
}
|
||||
}
|
||||
.onChange(of: scrapingModel.searchResults) { _ in
|
||||
// Cleans up any leftover search results in the event of an abrupt cancellation
|
||||
if !isSearching {
|
||||
|
|
@ -54,7 +72,7 @@ struct ContentView: View {
|
|||
.navigationTitle("Search")
|
||||
.navigationSearchBar {
|
||||
SearchBar(
|
||||
"Search",
|
||||
searchBarText,
|
||||
text: $searchText,
|
||||
isEditing: $isEditingSearch,
|
||||
onCommit: {
|
||||
|
|
@ -88,6 +106,7 @@ struct ContentView: View {
|
|||
scrapingModel.runningSearchTask = nil
|
||||
isSearching = false
|
||||
searchText = ""
|
||||
searchBarText = getSearchBarText()
|
||||
}
|
||||
}
|
||||
.navigationSearchBarHiddenWhenScrolling(false)
|
||||
|
|
@ -97,6 +116,26 @@ struct ContentView: View {
|
|||
.environmentObject(scrapingModel)
|
||||
.environmentObject(debridManager)
|
||||
}
|
||||
.backport.onAppear {
|
||||
searchBarText = getSearchBarText()
|
||||
}
|
||||
}
|
||||
|
||||
// Fetches random searchbar text if enabled, otherwise deinit the last case value
|
||||
func getSearchBarText() -> String {
|
||||
if usesRandomSearchText {
|
||||
let num = Int.random(in: 0..<searchBarTextArray.count - 1)
|
||||
if num == lastSearchTextIndex {
|
||||
lastSearchTextIndex = num + 1
|
||||
return searchBarTextArray[safe: num + 1] ?? "Search"
|
||||
} else {
|
||||
lastSearchTextIndex = num
|
||||
return searchBarTextArray[safe: num] ?? "Search"
|
||||
}
|
||||
} else {
|
||||
lastSearchTextIndex = -1
|
||||
return "Search"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ struct SettingsView: View {
|
|||
let backgroundContext = PersistenceController.shared.backgroundContext
|
||||
|
||||
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
|
||||
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText = false
|
||||
|
||||
@AppStorage("Updates.AutomaticNotifs") var autoUpdateNotifs = true
|
||||
|
||||
|
|
@ -82,6 +83,10 @@ struct SettingsView: View {
|
|||
Toggle(isOn: $autocorrectSearch) {
|
||||
Text("Autocorrect search")
|
||||
}
|
||||
|
||||
Toggle(isOn: $usesRandomSearchText) {
|
||||
Text("Random searchbar text")
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: InlineHeader("Plugin management")) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue