Download wp-calypso/client/data/stats/use-has-never-published-post.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/stats/use-has-never-published-post.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/stats/use-has-never-published-post.ts
-
curl -L -o use-has-never-published-post.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/stats/use-has-never-published-post.ts
1.07 kB
| import { useQuery } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import type { QueryOptions, UseQueryResult } from '@tanstack/react-query'; | |
| export const useHasNeverPublishedPostCacheKey = ( | |
| siteId: number | null, | |
| includePages: boolean | |
| ) => [ 'site-has-never-published-post', siteId, includePages ]; | |
| interface Options extends QueryOptions { | |
| enabled?: boolean; | |
| } | |
| export const useHasNeverPublishedPost = ( | |
| siteId: number | null, | |
| includePages: boolean, | |
| queryOptions: Options | |
| ): UseQueryResult< boolean > => { | |
| const { enabled = true } = queryOptions; | |
| return useQuery( { | |
| queryKey: useHasNeverPublishedPostCacheKey( siteId, includePages ), | |
| queryFn: () => fetchHasNeverPublishedPost( siteId, includePages ), | |
| ...queryOptions, | |
| enabled: !! siteId && enabled, | |
| } ); | |
| }; | |
| function fetchHasNeverPublishedPost( | |
| siteId: number | null, | |
| includePages: boolean | |
| ): Promise< boolean > { | |
| return wpcom.req.get( | |
| { | |
| path: `/sites/${ siteId }/site-has-never-published-post`, | |
| apiNamespace: 'wpcom/v2', | |
| }, | |
| { 'include-pages': includePages } | |
| ); | |
| } | |