Search Channels by name in the Other search tab

The Other tab only listed Channels with the selected Tags, so typing a
Channel's name found nothing.  Channels now match the search text by name,
and the Tags when there are both.  The list and its estimate share one query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-10-07 15:37:07 -06:00
parent 4bd86d3eb1
commit 52cf7a9520
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
9 changed files with 88 additions and 38 deletions

View file

@ -2118,8 +2118,8 @@ export async function searchEstimateOthers(tagNames, searchStr) {
}
}
export async function searchChannels(tagNames) {
const body = {tag_names: tagNames};
export async function searchChannels(tagNames, searchStr) {
const body = {tag_names: tagNames, search_str: searchStr};
const response = await apiPost(`${API_URI}/videos/channels/search`, body);
if (response.ok) {
const content = await response.json();

View file

@ -601,7 +601,7 @@ export function OtherSearchView({loading}) {
const [activeValues, setActiveValues] = React.useState(['channels', 'repos']);
const activeTags = searchParams.getAll('tag');
const searchStr = searchParams.get('q') || '';
const {channels, loading: channelsLoading} = useSearchChannels(activeTags);
const {channels, loading: channelsLoading} = useSearchChannels(activeTags, searchStr);
const {repos} = useSearchRepos(searchStr, activeTags);
if (loading || channelsLoading || channels === null) {

View file

@ -2107,7 +2107,8 @@ export const useCalcQuery = () => {
return [calc, setCalc]
}
export const useSearchChannels = (defaultTagNames) => {
// Channels whose name matches `searchStr` and/or which have any of the tags.
export const useSearchChannels = (defaultTagNames, searchStr) => {
const [tagNames, setTagNames] = useState(defaultTagNames || []);
// null = pending, undefined = fetch failed, [] = no channels. A search starts on mount, so the
// first render is already loading; consumers must never see [] for a search that has not run.
@ -2121,7 +2122,7 @@ export const useSearchChannels = (defaultTagNames) => {
setChannels(null);
setLoading(true);
try {
const {channels: newChannels} = await searchChannels(tagNames);
const {channels: newChannels} = await searchChannels(tagNames, searchStr);
if (gen === requestGen.current) {
setChannels(newChannels || []);
}
@ -2147,7 +2148,7 @@ export const useSearchChannels = (defaultTagNames) => {
useEffect(() => {
localSearchChannels();
}, [tagNames]);
}, [tagNames, searchStr]);
return {
tagNames,

View file

@ -475,7 +475,7 @@ describe('useSearchChannels', () => {
const {result} = renderHook(() => useSearchChannels(['a']));
await act(async () => {
});
expect(searchChannels).toHaveBeenCalledWith(['a']);
expect(searchChannels).toHaveBeenCalledWith(['a'], undefined);
expect(result.current.channels).toEqual([{id: 1, name: 'One'}]);
expect(result.current.loading).toBe(false);
});
@ -510,11 +510,27 @@ describe('useSearchChannels', () => {
}));
rerender({tags: ['new']});
expect(searchChannels).toHaveBeenCalledTimes(2);
expect(searchChannels).toHaveBeenLastCalledWith(['new']);
expect(searchChannels).toHaveBeenLastCalledWith(['new'], undefined);
expect(result.current.channels).toBeNull();
expect(result.current.loading).toBe(true);
});
test('searches by the search text, and refetches when it changes', async () => {
searchChannels.mockResolvedValue({channels: [{id: 1, name: 'Cooking'}]});
const {result, rerender} = renderHook(({q}) => useSearchChannels([], q), {initialProps: {q: 'cook'}});
await act(async () => {
});
expect(searchChannels).toHaveBeenLastCalledWith([], 'cook');
expect(result.current.channels).toEqual([{id: 1, name: 'Cooking'}]);
searchChannels.mockReturnValue(new Promise(() => {
}));
rerender({q: 'garden'});
expect(searchChannels).toHaveBeenCalledTimes(2);
expect(searchChannels).toHaveBeenLastCalledWith([], 'garden');
expect(result.current.channels).toBeNull();
});
test('a new array with the same tags does not refetch', async () => {
searchChannels.mockResolvedValue({channels: []});
const {rerender} = renderHook(({tags}) => useSearchChannels(tags), {initialProps: {tags: ['a']}});