File size: 1,085 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { useQuery } from '@tanstack/react-query';
import wpcomRequest from 'wpcom-proxy-request';
import { isValidId } from '../helpers';
export type ReadFeedResponse = {
URL: string;
blog_ID: string;
description: string;
feed_ID: string;
feed_URL: string;
image: string;
is_following: boolean;
last_checked: string;
last_update: string;
marked_for_refresh: boolean;
meta: {
links: {
self: string;
[ key: string ]: string;
};
};
name: string;
next_refresh_time: string | null;
organization_id: number;
subscribe_URL: string;
subscribers_count: number;
unseen_count: number;
subscription_id?: number; // Only present if the user is subscribed to the feed.
};
const useReadFeedQuery = ( enabled: boolean, feedId?: number | string ) => {
return useQuery( {
queryKey: [ 'read', 'feeds', Number( feedId ) ],
queryFn: async () => {
return wpcomRequest< ReadFeedResponse >( {
path: `/read/feed/${ feedId }`,
apiVersion: '1.1',
method: 'GET',
} );
},
enabled: enabled && isValidId( feedId ),
} );
};
export default useReadFeedQuery;
|