Refactor SearchController

This commit is contained in:
Marvin Elsen 2024-10-24 21:13:10 +02:00
parent a1a7567bd0
commit 959a5c2680
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2

View File

@ -16,22 +16,18 @@ class SearchController(private val model: Model) {
@FXML @FXML
@Suppress("UnusedPrivateMember") @Suppress("UnusedPrivateMember")
private fun initialize() { private fun initialize() {
textFieldSearch.textProperty().addListener { _, _, newValue -> textFieldSearch.textProperty().addListener { _, _, _ -> search() }
if (newValue.isNullOrBlank()) { searchModeToggleGroup.selectedToggleProperty().addListener { _, _, _ -> search() }
return@addListener }
}
val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode private fun search() {
model.search(newValue, searchMode) val searchQuery = textFieldSearch.text
val searchMode = searchModeToggleGroup.selectedToggle.userData as SearchMode
if (searchQuery.isNullOrBlank()) {
return
} }
searchModeToggleGroup.selectedToggleProperty().addListener { _, _, newValue -> model.search(searchQuery, searchMode)
if (textFieldSearch.text.isNullOrBlank()) {
return@addListener
}
val searchMode = newValue.userData as SearchMode
model.search(textFieldSearch.text, searchMode)
}
} }
} }