mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-23 17:03:34 +08:00
# Conflicts: # composer.json # modules/settings/assets/js/components/bottom-bar/index.js # modules/settings/assets/js/components/my-account-menu/popup-menu.js # modules/settings/assets/js/components/statement-generator/index.js # modules/settings/assets/js/layouts/statement-link/index.js # package-lock.json
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
import { useToastNotification } from '@ea11y-apps/global/hooks';
|
|
import {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useEffect,
|
|
useState,
|
|
} from '@wordpress/element';
|
|
import { __ } from '@wordpress/i18n';
|
|
import APISettings from '../api';
|
|
|
|
const PluginSettingsContext = createContext({});
|
|
|
|
export const PluginSettingsProvider = ({ children }) => {
|
|
const { error } = useToastNotification();
|
|
const [pluginSettings, setPluginSettings] = useState();
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
const refreshPluginSettings = useCallback(() => {
|
|
APISettings.getPluginSettings()
|
|
.then((settings) => {
|
|
if ('isConnected' in settings) {
|
|
settings.isConnected = Boolean(settings.isConnected);
|
|
}
|
|
|
|
if ('closePostConnectModal' in settings) {
|
|
settings.closePostConnectModal = Boolean(
|
|
settings.closePostConnectModal,
|
|
);
|
|
}
|
|
|
|
if ('isUrlMismatch' in settings) {
|
|
settings.isUrlMismatch = Boolean(settings.isUrlMismatch);
|
|
}
|
|
|
|
if ('unfilteredUploads' in settings) {
|
|
settings.unfilteredUploads = Boolean(settings.unfilteredUploads);
|
|
}
|
|
|
|
setPluginSettings(settings);
|
|
setLoaded(true);
|
|
})
|
|
.catch(() => {
|
|
error(__('An error occurred.', 'pojo-accessibility'));
|
|
setLoaded(true);
|
|
});
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
refreshPluginSettings();
|
|
}, [refreshPluginSettings]);
|
|
|
|
return (
|
|
<PluginSettingsContext.Provider
|
|
value={{ ...pluginSettings, loaded, refreshPluginSettings }}
|
|
>
|
|
{children}
|
|
</PluginSettingsContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const usePluginSettingsContext = () => {
|
|
return useContext(PluginSettingsContext);
|
|
};
|