Download wp-calypso/packages/help-center/src/hooks/use-post-by-url.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/help-center/src/hooks/use-post-by-url.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/help-center/src/hooks/use-post-by-url.ts
-
curl -L -o use-post-by-url.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/help-center/src/hooks/use-post-by-url.ts
1.22 kB
| import { recordTracksEvent } from '@automattic/calypso-analytics'; | |
| import { localizeUrl } from '@automattic/i18n-utils'; | |
| import { useQuery } from '@tanstack/react-query'; | |
| import apiFetch from '@wordpress/api-fetch'; | |
| import wpcomRequest, { canAccessWpcomApis } from 'wpcom-proxy-request'; | |
| import { useHelpCenterContext } from '../contexts/HelpCenterContext'; | |
| import type { PostObject } from '../types'; | |
| export function usePostByUrl( url: string ) { | |
| const { sectionName } = useHelpCenterContext(); | |
| const postUrl = encodeURIComponent( localizeUrl( url ) ); | |
| return useQuery< PostObject >( { | |
| queryKey: [ 'support-status', url ], | |
| queryFn: () => | |
| canAccessWpcomApis() | |
| ? wpcomRequest( { | |
| path: `/help/article?post_url=${ postUrl }`, | |
| apiNamespace: 'wpcom/v2', | |
| } ) | |
| : apiFetch( { | |
| path: `/help-center/fetch-post?post_url=${ postUrl }`, | |
| } ), | |
| enabled: !! url, | |
| refetchOnWindowFocus: false, | |
| staleTime: 12 * 3600, // 12 hours | |
| throwOnError: () => { | |
| const tracksData = { | |
| force_site_id: true, | |
| location: 'help-center', | |
| section: sectionName, | |
| post_url: url, | |
| }; | |
| recordTracksEvent( 'calypso_helpcenter_post_by_url_error', tracksData ); | |
| return false; | |
| }, | |
| } ); | |
| } | |