Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Add getInstalledPlugins resolver with preloaded data
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbitzer committed Mar 27, 2020
1 parent 10b736e commit b8b127e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions client/marketing/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import * as actions from './actions';
import * as selectors from './selectors';
import * as resolvers from './resolvers';

const { installedExtensions } = getSetting( 'marketing', {} );

const DEFAULT_STATE = {
installedPlugins: installedExtensions,
installedPlugins: [],
activatingPlugins: [],
recommendedPlugins: [],
blogPosts: [],
Expand Down Expand Up @@ -63,3 +61,7 @@ registerStore( STORE_KEY, {
},

} );

// Set installedPlugins from preloaded setting.
const { installedExtensions } = getSetting( 'marketing', {} );
actions.receiveInstalledPlugins( installedExtensions );
17 changes: 17 additions & 0 deletions client/marketing/data/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@ import { apiFetch } from '@wordpress/data-controls';
import {
handleFetchError,
receiveRecommendedPlugins,
receiveInstalledPlugins,
receiveBlogPosts,
} from './actions';
import { API_NAMESPACE } from './constants';

export function* getInstalledPlugins() {
try {
const response = yield apiFetch( {
path: `${ API_NAMESPACE }/overview/installed-plugins`
} );

if ( response ) {
yield receiveInstalledPlugins( response );
} else {
throw new Error();
}
} catch ( error ) {
yield handleFetchError( error, __( 'There was an error loading installed extensions.', 'woocommerce-admin' ) );
}
}

export function* getRecommendedPlugins() {
try {
const response = yield apiFetch( {
Expand Down

0 comments on commit b8b127e

Please sign in to comment.