File size: 810 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Older version of the hook, used in the HelpSearch component.

import { useLocale } from '@automattic/i18n-utils';
import { useQuery } from '@tanstack/react-query';
import wpcomRequest from 'wpcom-proxy-request';
import type { LinksForSection } from '@automattic/data-stores';
export const useHelpSearchQuery = (
	search: string,
	queryOptions: Record< string, unknown > = {}
) => {
	const locale = useLocale();
	const params = new URLSearchParams( {
		include_post_id: '1',
		locale,
	} );

	if ( search ) {
		params.append( 'query', search );
	}

	return useQuery< { wordpress_support_links: LinksForSection[] } >( {
		queryKey: [ 'help', search ],
		queryFn: () =>
			wpcomRequest( { path: '/help/search', query: params.toString(), apiVersion: '1.1' } ),
		enabled: !! search,
		...queryOptions,
	} );
};