Download wp-calypso/packages/data-stores/src/queries/use-all-domains-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/queries/use-all-domains-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/data-stores/src/queries/use-all-domains-query.ts
-
curl -L -o use-all-domains-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/queries/use-all-domains-query.ts
1.81 kB
| import { UseQueryOptions, useQuery } from '@tanstack/react-query'; | |
| import { addQueryArgs } from '@wordpress/url'; | |
| import wpcomRequest from 'wpcom-proxy-request'; | |
| import type { DomainData } from './use-site-domains-query'; | |
| // The data returned by the /all-domains endpoint only includes the basic data | |
| // related to a domain. | |
| export type PartialDomainData = Pick< | |
| DomainData, | |
| | 'auto_renewing' | |
| | 'blog_id' | |
| | 'current_user_can_add_email' | |
| | 'current_user_is_owner' | |
| | 'domain' | |
| | 'email_forwards_count' | |
| | 'expiry' | |
| | 'google_apps_subscription' | |
| | 'has_registration' | |
| | 'is_wpcom_staging_domain' | |
| | 'is_hundred_year_domain' | |
| | 'registration_date' | |
| | 'titan_mail_subscription' | |
| | 'tld_maintenance_end_time' | |
| | 'type' | |
| | 'wpcom_domain' | |
| | 'domain_status' | |
| >; | |
| export interface AllDomainsQueryFnData { | |
| domains: PartialDomainData[]; | |
| } | |
| export interface AllDomainsQueryArgs { | |
| no_wpcom?: boolean; | |
| resolve_status?: boolean; | |
| } | |
| export const getAllDomainsQueryKey = ( queryArgs: AllDomainsQueryArgs = {} ) => [ | |
| 'all-domains', | |
| queryArgs, | |
| ]; | |
| export function useAllDomainsQuery< TError = unknown, TData = AllDomainsQueryFnData >( | |
| queryArgs: AllDomainsQueryArgs = {}, | |
| options: Omit< UseQueryOptions< AllDomainsQueryFnData, TError, TData >, 'queryKey' > = {} | |
| ) { | |
| return useQuery< AllDomainsQueryFnData, TError, TData >( { | |
| queryKey: getAllDomainsQueryKey( queryArgs ), | |
| queryFn: () => | |
| wpcomRequest< AllDomainsQueryFnData >( { | |
| path: addQueryArgs( '/all-domains', queryArgs ), | |
| apiVersion: '1.1', | |
| } ), | |
| // It's reasonable to assume that users won't register a domain in another tab | |
| // and then expect the list to update automatically when they switch back. | |
| // We expect users to refresh the page after making substantial domain changes. | |
| refetchOnWindowFocus: false, | |
| ...options, | |
| } ); | |
| } | |