Don't restart search if query is unchanged

This commit is contained in:
MM20 2022-10-18 18:16:18 +02:00
parent cb5fe404e2
commit a3be3188fa
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -28,7 +28,7 @@ class SearchVM : ViewModel(), KoinComponent {
private val websearchRepository: WebsearchRepository by inject()
val isSearching = MutableLiveData(false)
val searchQuery = MutableLiveData("")
val searchQuery = MutableLiveData<String>("")
val isSearchEmpty = MutableLiveData(true)
val showLabels = dataStore.data.map { it.grid.showLabels }.asLiveData()
@ -55,11 +55,12 @@ class SearchVM : ViewModel(), KoinComponent {
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(), replay = 1)
init {
search("")
search("", true)
}
var searchJob: Job? = null
fun search(query: String) {
fun search(query: String, forceRestart: Boolean = false) {
if (searchQuery.value == query && !forceRestart) return
searchQuery.value = query
isSearchEmpty.value = query.isEmpty()
hiddenResults.value = emptyList()