mirror of
https://gh.wpcy.net/https://github.com/elementor/hello-theme.git
synced 2026-04-24 11:45:02 +08:00
32 lines
912 B
JavaScript
32 lines
912 B
JavaScript
import { createContext, useEffect } from 'react';
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
export const AdminContext = createContext();
|
|
|
|
export const AdminProvider = ( { children } ) => {
|
|
const [ isLoading, setIsLoading ] = React.useState( true );
|
|
const [ promotionsLinks, setPromotionsLinks ] = React.useState( [] );
|
|
const [ adminSettings, setAdminSettings ] = React.useState( {} );
|
|
|
|
useEffect( () => {
|
|
Promise.all( [
|
|
apiFetch( { path: '/elementor-hello-elementor/v1/promotions' } ),
|
|
apiFetch( { path: '/elementor-hello-elementor/v1/admin-settings' } ),
|
|
] ).then( ( [ links, settings ] ) => {
|
|
setPromotionsLinks( links.links );
|
|
setAdminSettings( settings.config );
|
|
} ).finally( () => {
|
|
setIsLoading( false );
|
|
} );
|
|
}, [] );
|
|
|
|
return (
|
|
<AdminContext.Provider value={ {
|
|
promotionsLinks,
|
|
adminSettings,
|
|
isLoading,
|
|
} }>
|
|
{ children }
|
|
</AdminContext.Provider>
|
|
);
|
|
};
|