Skip to content

Commit

Permalink
add: load saved widget icon settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbhayel committed Nov 29, 2024
1 parent 352740e commit be8eba2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/settings/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import {
AdminTopBar,
BottomBar,
} from '@ea11y/components';
import { useNotificationSettings, useSettings } from '@ea11y/hooks';
import {
useNotificationSettings,
useSettings,
useSavedSettings,
} from '@ea11y/hooks';
import { usePluginSettingsContext } from './contexts/plugin-settings';
import { Sidebar } from './layouts/sidebar';

const App = () => {
const { isConnected } = usePluginSettingsContext();
const { notificationMessage, notificationType } = useNotificationSettings();
const { selectedMenu } = useSettings();
useSavedSettings();

// Accessing the selected menu item
const selectedParent = MenuItems[selectedMenu.parent];
Expand Down
1 change: 1 addition & 0 deletions modules/settings/assets/js/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { NotificationsProvider } from './use-notifications';
export { useNotificationSettings } from './use-notifications';
export { useIconPosition } from './use-icon-positioon';
export { useIconDesign } from './use-icon-design';
export { useSavedSettings } from './use-saved-settings';
30 changes: 30 additions & 0 deletions modules/settings/assets/js/hooks/use-saved-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useSettings } from '@ea11y/hooks';
import { store as coreDataStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';

export const useSavedSettings = () => {
const { setIconDesign, setIconPosition } = useSettings();

const result = useSelect((select) => {
return {
data: select(coreDataStore).getEntityRecord('root', 'site'),
hasFinishedResolution: select(coreDataStore).hasFinishedResolution(
'getEntityRecord',
['root', 'site'],
),
};
}, []);

useEffect(() => {
if (result.hasFinishedResolution) {
if (result?.data?.a11y_widget_icon_settings?.style) {
setIconDesign(result.data.a11y_widget_icon_settings.style);
}

if (result?.data?.a11y_widget_icon_settings?.position) {
setIconPosition(result.data.a11y_widget_icon_settings.position);
}
}
}, [result.hasFinishedResolution]);
};

0 comments on commit be8eba2

Please sign in to comment.