Download wp-calypso/client/state/activitypub/use-activitypub-status.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/activitypub/use-activitypub-status.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/activitypub/use-activitypub-status.js
-
curl -L -o use-activitypub-status.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/activitypub/use-activitypub-status.js
1.03 kB
| import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| export const useActivityPubStatus = ( blogId, onUpdate = () => {} ) => { | |
| const path = `/sites/${ blogId }/activitypub/status`; | |
| const apiNamespace = 'wpcom/v2'; | |
| const queryKey = [ path, apiNamespace ]; | |
| const { data, isInitialLoading, isError } = useQuery( { | |
| queryKey, | |
| staleTime: 0, // refetches are important here, lots of stuff in play while doing upgrades, activation, etc | |
| gcTime: 5 * 60 * 1000, // 5 mins | |
| queryFn: () => wpcom.req.get( { path, apiNamespace } ), | |
| } ); | |
| const queryClient = useQueryClient(); | |
| const { mutate, isLoading } = useMutation( { | |
| mutationFn: ( enabled ) => wpcom.req.post( { path, apiNamespace }, { enabled } ), | |
| onSuccess: ( responseData ) => { | |
| queryClient.setQueryData( queryKey, responseData ); | |
| onUpdate( responseData ); | |
| }, | |
| } ); | |
| return { | |
| isEnabled: !! data?.enabled, | |
| setEnabled: mutate, | |
| isLoading: isInitialLoading || isLoading, | |
| isError, | |
| data, | |
| }; | |
| }; | |