first
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
export function apiFetch(request) {
|
||||
return {
|
||||
type: 'API_FETCH',
|
||||
request,
|
||||
};
|
||||
}
|
||||
|
||||
export function setPortfolioLayouts(layouts) {
|
||||
return {
|
||||
type: 'SET_PORTFOLIO_LAYOUTS',
|
||||
layouts,
|
||||
};
|
||||
}
|
26
wp-content/plugins/visual-portfolio/gutenberg/store/base/controls.js
vendored
Normal file
26
wp-content/plugins/visual-portfolio/gutenberg/store/base/controls.js
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
|
||||
export function API_FETCH({ request }) {
|
||||
return apiFetch(request)
|
||||
.catch((fetchedData) => {
|
||||
if (
|
||||
fetchedData &&
|
||||
fetchedData.error &&
|
||||
fetchedData.error_code === 'no_layouts_found'
|
||||
) {
|
||||
return {
|
||||
response: [],
|
||||
error: false,
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.then((fetchedData) => {
|
||||
if (fetchedData && fetchedData.success && fetchedData.response) {
|
||||
return fetchedData.response;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import { createReduxStore, register } from '@wordpress/data';
|
||||
|
||||
import * as actions from './actions';
|
||||
import * as controls from './controls';
|
||||
import reducer from './reducer';
|
||||
import * as resolvers from './resolvers';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
const store = createReduxStore('visual-portfolio', {
|
||||
selectors,
|
||||
actions,
|
||||
controls,
|
||||
resolvers,
|
||||
reducer,
|
||||
});
|
||||
|
||||
register(store);
|
@ -0,0 +1,18 @@
|
||||
function reducer(state = { layouts: [] }, action = {}) {
|
||||
switch (action.type) {
|
||||
case 'SET_PORTFOLIO_LAYOUTS':
|
||||
if (
|
||||
!state.layouts.length &&
|
||||
action.layouts &&
|
||||
action.layouts.length
|
||||
) {
|
||||
state.layouts = action.layouts;
|
||||
}
|
||||
return state;
|
||||
// no default
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export default reducer;
|
@ -0,0 +1,7 @@
|
||||
import * as actions from './actions';
|
||||
|
||||
export function* getPortfolioLayouts() {
|
||||
const query = '/visual-portfolio/v1/get_layouts/';
|
||||
const layouts = yield actions.apiFetch({ path: query });
|
||||
return actions.setPortfolioLayouts(layouts);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export function getPortfolioLayouts(state) {
|
||||
return state.layouts;
|
||||
}
|
Reference in New Issue
Block a user