fix(search): resolve notification loops causing multiple API requests
- Make auth_token() public for catalog/search endpoint authentication - Fix setSearchQuery to skip notification when value unchanged - Fix setSearchState to only notify listeners when query actually changed - Add title case transformation for better most_popular API results - Add stale result detection to ignore outdated search responses - Preserve most_popular when API returns inconsistent results - Clean up debug logging
This commit is contained in:
1 parent
d8bd93374f
commit
f699cf0e63
4 files changed
+90
-19
No files matched your search
@@ -48,9 +48,12 @@ export function getSearchState<Album, Track, Artist>(): SearchState<Album, Track
|
||||
}
|
||||
|
||||
export function setSearchState<Album, Track, Artist>(next: SearchState<Album, Track, Artist>): void {
|
||||
const prevQuery = searchState.query;
|
||||
searchState = next as SearchState<unknown, unknown, unknown>;
|
||||
// Notify query listeners when query changes
|
||||
queryListeners.forEach(fn => fn(searchState.query));
|
||||
// Only notify query listeners when query actually changes
|
||||
if (prevQuery !== searchState.query) {
|
||||
queryListeners.forEach(fn => fn(searchState.query));
|
||||
}
|
||||
}
|
||||
|
||||
// Signal to trigger scroll-to-top and focus on search input
|
||||
@@ -75,6 +78,7 @@ export function getSearchQuery(): string {
|
||||
}
|
||||
|
||||
export function setSearchQuery(query: string): void {
|
||||
if (searchState.query === query) return; // No change, don't notify
|
||||
searchState.query = query;
|
||||
queryListeners.forEach(fn => fn(query));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user