Move exact matches of searched categories to the top (#379)

This commit is contained in:
Su-Shing Chen 2024-08-17 08:27:14 +10:00 • committed by GitHub
parent c022db9c20
commit 5a374f74bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -83,6 +83,16 @@ abstract class SearchStoreBase with Store {
query: query,
headers: authStore.headersTwitch,
)
.then((categories) {
// Move exact matches to the first result
final matchingIndex = categories.data
.indexWhere((c) => c.name.toLowerCase() == query.toLowerCase());
if (matchingIndex >= 1) {
final matchingCategory = categories.data.removeAt(matchingIndex);
categories.data.insert(0, matchingCategory);
}
return categories;
})
.asObservable();
}