Download wp-calypso/client/data/themes/use-active-theme-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 894 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/themes/use-active-theme-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/themes/use-active-theme-query.ts
-
curl -L -o use-active-theme-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/themes/use-active-theme-query.ts
894 Bytes
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import { useSelector } from 'calypso/state'; | |
| import { getSiteOption } from 'calypso/state/sites/selectors'; | |
| interface ThemeSupports { | |
| [ index: string ]: boolean; | |
| } | |
| export type ActiveTheme = { | |
| is_block_theme: boolean; | |
| template: string; | |
| theme_supports: ThemeSupports; | |
| stylesheet: string; | |
| }; | |
| export const useActiveThemeQuery = ( | |
| siteId: number, | |
| isEnabled = false | |
| ): UseQueryResult< ActiveTheme[] > => { | |
| const themeSlug = useSelector( ( state ) => getSiteOption( state, siteId, 'theme_slug' ) ); | |
| const queryKey = [ 'activeTheme', siteId, themeSlug ]; | |
| return useQuery< ActiveTheme[] >( { | |
| queryKey, | |
| queryFn: () => { | |
| return wpcom.req.get( { | |
| path: `/sites/${ siteId }/themes?status=active`, | |
| apiNamespace: 'wp/v2', | |
| } ); | |
| }, | |
| enabled: isEnabled && !! siteId, | |
| } ); | |
| }; | |