Fix creating page not changing the slug.

This commit is contained in:
Nakul Nagargade 2023-10-13 11:00:11 +05:30
parent 576e4422b1
commit 0ff9c18ab8

View file

@ -141,6 +141,7 @@ const EditorComponent = (props) => {
undo: [],
redo: [],
});
const [newPageId, setNewPageId] = useState('');
// refs
const canvasContainerRef = useRef(null);
@ -826,7 +827,6 @@ const EditorComponent = (props) => {
isUpdatingEditorStateInProcess: updatingEditorStateInProcess,
appDefinition: updatedAppDefinition,
});
computeComponentState(updatedAppDefinition.pages[currentPageId]?.components);
}
@ -1247,7 +1247,6 @@ const EditorComponent = (props) => {
components: {},
index: Object.keys(copyOfAppDefinition.pages).length + 1,
};
setCurrentPageId(newPageId);
setHoveredComponent(null);
updateEditorState({
@ -1261,8 +1260,17 @@ const EditorComponent = (props) => {
switchPage: true,
pageId: newPageId,
});
setNewPageId(newPageId);
};
// This UseEffect is used when new page is created
useEffect(() => {
if (newPageId) {
switchPage(newPageId);
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [newPageId, JSON.stringify(appDefinition)]);
const switchPage = (pageId, queryParams = []) => {
if (currentPageId === pageId && currentState.page.handle === appDefinition?.pages[pageId]?.handle) {
return;
@ -1272,7 +1280,6 @@ const EditorComponent = (props) => {
if (!name || !handle) return;
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
const queryParamsString = queryParams.map(([key, value]) => `${key}=${value}`).join('&');
props?.navigate(`/${getWorkspaceId()}/apps/${appId}/${handle}?${queryParamsString}`);
const { globals: existingGlobals } = currentState;
@ -1296,6 +1303,8 @@ const EditorComponent = (props) => {
const currentPageEvents = events.filter((event) => event.target === 'page' && event.sourceId === page.id);
handleEvent('onPageLoad', currentPageEvents);
// Always set new Page id to empty after switching
setNewPageId('');
};
const deletePageRequest = (pageId, isHomePage = false, pageName = '') => {