/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { apiFetch } from '@wordpress/data-controls';
* Internal dependencies
import {
handleFetchError,
receiveRecommendedPlugins,
receiveBlogPosts,
setError,
} from './actions';
import { API_NAMESPACE } from './constants';
export function* getRecommendedPlugins( category ) {
try {
const categoryParam = yield category ? `&category=${ category }` : '';
const response = yield apiFetch( {
path: `${ API_NAMESPACE }/recommended?per_page=6${ categoryParam }`,
} );
if ( response ) {
yield receiveRecommendedPlugins( response, category );
} else {
throw new Error();
}
} catch ( error ) {
yield handleFetchError(
error,
__(
'There was an error loading recommended extensions.',
'woocommerce-admin'
)
);
export function* getBlogPosts( category ) {
const categoryParam = yield category ? `?category=${ category }` : '';
path: `${ API_NAMESPACE }/knowledge-base${ categoryParam }`,
method: 'GET',
yield receiveBlogPosts( response, category );
yield setError( category, error );