app: search dropdown offers "Channels: No results" only after a search (#730)

useSuggestions started with channels: [] and reset to that on every
keystroke, and the normalizer treats an empty list as "the server
found none".  So the global search dropdown showed a "Channels: No
results" row on focus before anything was typed, and on every
keystroke through the debounce and the request.  Because that row
counts as a result, the SearchBox's own "Searching…" state never
appeared.

The channel, domain, author and subject groups now start as null,
meaning not fetched; an empty list only ever comes from the server.
The count summary tolerates the null.  Tests render the hook and
check no Channels group exists before a search or while the request
is pending, and that the "No results" row and real rows still appear
after the response.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-09-26 15:06:43 -06:00 • committed by Roland
parent 5dda94492e
commit ae745f1a18
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
2 changed files with 113 additions and 6 deletions

View file

@ -131,12 +131,14 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
}
export function useSuggestions(searchStr, tagNames, filter, anyTag) {
// The general groups are null until the suggestion request returns: an empty list means the
// server found none, and the dropdown may say "No results" only for that.
const defaultSuggestions = {
fileGroups: [],
channels: [],
domains: [],
authors: [],
subjects: [],
channels: null,
domains: null,
authors: null,
subjects: null,
zimsEstimates: [],
}
const [suggestions, setSuggestions] = React.useState(defaultSuggestions);
@ -401,8 +403,8 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag)
zims: zimSum,
otherSum: otherSum,
mapPlaces: newSuggestions.mapPlaces || 0,
channels: newSuggestions.channels.length,
domains: newSuggestions.domains.length,
channels: newSuggestions.channels?.length,
domains: newSuggestions.domains?.length,
authors: newSuggestions.authors?.length,
subjects: newSuggestions.subjects?.length,
tags: matchingTags?.length,