2023-01-17 18:04:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { apiFetch } from '@wordpress/data-controls';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-01-19 11:33:51 +00:00
|
|
|
import {
|
2023-01-31 16:52:35 +00:00
|
|
|
receiveRegisteredChannelsSuccess,
|
|
|
|
receiveRegisteredChannelsError,
|
2023-01-19 11:33:51 +00:00
|
|
|
receiveRecommendedChannelsSuccess,
|
|
|
|
receiveRecommendedChannelsError,
|
|
|
|
} from './actions';
|
2023-01-31 16:52:35 +00:00
|
|
|
import { RegisteredChannel, RecommendedChannel } from './types';
|
2023-01-17 18:04:42 +00:00
|
|
|
import { API_NAMESPACE } from './constants';
|
|
|
|
import { isApiFetchError } from './guards';
|
|
|
|
|
2023-01-31 16:52:35 +00:00
|
|
|
export function* getRegisteredChannels() {
|
2023-01-17 18:04:42 +00:00
|
|
|
try {
|
2023-01-31 16:52:35 +00:00
|
|
|
const data: RegisteredChannel[] = yield apiFetch( {
|
2023-01-17 18:04:42 +00:00
|
|
|
path: `${ API_NAMESPACE }/channels`,
|
|
|
|
} );
|
|
|
|
|
2023-01-31 16:52:35 +00:00
|
|
|
yield receiveRegisteredChannelsSuccess( data );
|
2023-01-17 18:04:42 +00:00
|
|
|
} catch ( error ) {
|
|
|
|
if ( isApiFetchError( error ) ) {
|
2023-01-31 16:52:35 +00:00
|
|
|
yield receiveRegisteredChannelsError( error );
|
2023-01-17 18:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
2023-01-19 11:33:51 +00:00
|
|
|
|
|
|
|
export function* getRecommendedChannels() {
|
|
|
|
try {
|
2023-01-20 18:14:36 +00:00
|
|
|
const data: RecommendedChannel[] = yield apiFetch( {
|
2023-01-19 11:33:51 +00:00
|
|
|
path: `${ API_NAMESPACE }/recommendations?category=channels`,
|
|
|
|
} );
|
|
|
|
|
|
|
|
yield receiveRecommendedChannelsSuccess( data );
|
|
|
|
} catch ( error ) {
|
|
|
|
if ( isApiFetchError( error ) ) {
|
|
|
|
yield receiveRecommendedChannelsError( error );
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|