Page layout refactoring (#14535)
In this PR: - Refactored the page layout renderer - Converted all the states to component states - Removed the page layout edition in settings TODOs in next PRs: - Fix bug with the drag selector not taking the scroll into account to display the dragged area - Readd the tab edition in edit mode
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages';
|
||||
import { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';
|
||||
|
||||
import { useNavigatePageLayoutCommandMenu } from '@/command-menu/pages/page-layout/hooks/useNavigatePageLayoutCommandMenu';
|
||||
import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';
|
||||
import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';
|
||||
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { WidgetType } from '~/generated/graphql';
|
||||
|
||||
export const useEditPageLayoutWidget = (pageLayoutIdFromProps?: string) => {
|
||||
const pageLayoutId = useAvailableComponentInstanceIdOrThrow(
|
||||
PageLayoutComponentInstanceContext,
|
||||
pageLayoutIdFromProps,
|
||||
);
|
||||
|
||||
const setPageLayoutEditingWidgetId = useSetRecoilComponentState(
|
||||
pageLayoutEditingWidgetIdComponentState,
|
||||
pageLayoutId,
|
||||
);
|
||||
|
||||
const { navigatePageLayoutCommandMenu } = useNavigatePageLayoutCommandMenu();
|
||||
|
||||
const handleEditWidget = useCallback(
|
||||
({
|
||||
widgetId,
|
||||
widgetType,
|
||||
}: {
|
||||
widgetId: string;
|
||||
widgetType: WidgetType;
|
||||
}) => {
|
||||
setPageLayoutEditingWidgetId(widgetId);
|
||||
|
||||
if (widgetType === WidgetType.IFRAME) {
|
||||
navigatePageLayoutCommandMenu({
|
||||
commandMenuPage: CommandMenuPages.PageLayoutIframeConfig,
|
||||
pageTitle: t`Edit iFrame`,
|
||||
});
|
||||
}
|
||||
},
|
||||
[setPageLayoutEditingWidgetId, navigatePageLayoutCommandMenu],
|
||||
);
|
||||
|
||||
return {
|
||||
handleEditWidget,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user