From d3aa1c48995e6a8b1d66e32e281ff48cc1525eaa Mon Sep 17 00:00:00 2001 From: arpitnath Date: Thu, 2 Nov 2023 04:19:45 +0530 Subject: [PATCH] Revert "multi-edit: ymap-fix" This reverts commit 92f49c0cde33818c9a85478f8dfc3b59a629c3d7. --- frontend/src/Editor/Container.jsx | 7 +--- frontend/src/Editor/Editor.jsx | 65 ++++------------------------- frontend/src/_stores/editorStore.js | 4 +- 3 files changed, 10 insertions(+), 66 deletions(-) diff --git a/frontend/src/Editor/Container.jsx b/frontend/src/Editor/Container.jsx index 51ac45dcd7..501b6c923d 100644 --- a/frontend/src/Editor/Container.jsx +++ b/frontend/src/Editor/Container.jsx @@ -60,7 +60,7 @@ export const Container = ({ shallow ); - const { appId, areOthersOnSameVersionAndPage } = useAppInfo(); + const { appId } = useAppInfo(); const currentState = useCurrentState(); const { appVersionsId, enableReleasedVersionPopupState, isVersionReleased } = useAppVersionStore( @@ -206,8 +206,7 @@ export const Container = ({ const shouldUpdate = !_.isEmpty(diff(appDefinition, newDefinition)); if (shouldUpdate) { - console.log('[arpit]:: updating ==>'); - appDefinitionChanged(newDefinition, { ...opts, areOthersOnSameVersionAndPage }); + appDefinitionChanged(newDefinition, opts); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -301,8 +300,6 @@ export const Container = ({ }, }; - console.log('[arpit]:: adding new component'); - setBoxes(newBoxes); setSelectedComponent(newComponent.id, newComponent.component); diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 910f0ac099..6f321d3f3e 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -110,7 +110,6 @@ const EditorComponent = (props) => { showLeftSidebar, queryConfirmationList, currentPageId, - currentSessionId, } = useEditorState(); const dataQueries = useDataQueries(); @@ -143,7 +142,7 @@ const EditorComponent = (props) => { const [showPageDeletionConfirmation, setShowPageDeletionConfirmation] = useState(null); const [isDeletingPage, setIsDeletingPage] = useState(false); - // const [currentSessionId, setCurrentSessionId] = useState(null); + const [currentSessionId, setCurrentSessionId] = useState(null); const [undoStack, setUndoStack] = useState([]); const [redoStack, setRedoStack] = useState([]); @@ -205,7 +204,7 @@ const EditorComponent = (props) => { $componentDidMount(); - // setCurrentSessionId(() => uuid()); + setCurrentSessionId(() => uuid()); // 6. Unsubscribe from the observable when the component is unmounted return () => { @@ -240,17 +239,6 @@ const EditorComponent = (props) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify({ appDefinition, currentPageId, dataQueries })]); - // useEffect(() => { - // if (config.ENABLE_MULTIPLAYER_EDITING) { - // props.ymap?.set('eventsUpdated', { - // allEvents: events, - // editingVersionId: editingVersion?.id, - // currentSessionId, - // areOthersOnSameVersionAndPage, - // }); - // } - // }, [JSON.stringify({ events })]); - useEffect( () => { const components = appDefinition?.pages?.[currentPageId]?.components || {}; @@ -381,8 +369,6 @@ const EditorComponent = (props) => { skipAutoSave: true, skipYmapUpdate: true, currentSessionId: ymapUpdates.currentSessionId, - componentAdded: ymapUpdates.componentAdded, - componentDeleted: ymapUpdates.componentDeleted, }); }); }; @@ -802,40 +788,10 @@ const EditorComponent = (props) => { }); } let updatedAppDefinition; - const copyOfAppDefinition = JSON.parse(JSON.stringify(useEditorStore.getState().appDefinition)); + const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition)); if (opts?.skipYmapUpdate && opts?.currentSessionId !== currentSessionId) { - updatedAppDefinition = produce(copyOfAppDefinition, (draft) => { - const _currentPageId = useEditorStore.getState().currentPageId; - - if (opts?.componentDeleted) { - const currentPageComponentIds = Object.keys(copyOfAppDefinition.pages[_currentPageId]?.components); - const newComponentIds = Object.keys(newDefinition.pages[_currentPageId]?.components); - - const finalComponents = _.omit( - draft?.pages[_currentPageId]?.components, - _.difference(currentPageComponentIds, newComponentIds) - ); - - console.log('---arpit appDefinitionChanged--- ymap only', { - finalComponents, - }); - - draft.pages[_currentPageId].components = finalComponents; - } else if (opts?.componentAdded) { - const currentPageComponentIds = Object.keys(copyOfAppDefinition.pages[_currentPageId]?.components); - const newComponentIds = Object.keys(newDefinition.pages[_currentPageId]?.components); - - const finalComponents = _.pick( - newDefinition?.pages[_currentPageId]?.components, - _.difference(newComponentIds, currentPageComponentIds) - ); - - draft.pages[_currentPageId].components = finalComponents; - } else { - Object.assign(draft, newDefinition); - } - }); + updatedAppDefinition = newDefinition; } else { updatedAppDefinition = produce(copyOfAppDefinition, (draft) => { if (_.isEmpty(draft)) return; @@ -860,14 +816,9 @@ const EditorComponent = (props) => { }); } - const diffPatches = diff(copyOfAppDefinition, updatedAppDefinition); - // console.log('---arpit diffPatches--- ymap only', { - // copyOfAppDefinition, - // appDefinition, - // updatedAppDefinition, - // }); + const diffPatches = diff(appDefinition, updatedAppDefinition); - const inversePatches = diff(updatedAppDefinition, copyOfAppDefinition); + const inversePatches = diff(updatedAppDefinition, appDefinition); const shouldUpdate = !_.isEmpty(diffPatches) && !isEqual(appDefinitionDiff, diffPatches); if (shouldUpdate) { @@ -917,8 +868,6 @@ const EditorComponent = (props) => { editingVersionId: editingVersion?.id, currentSessionId, areOthersOnSameVersionAndPage, - componentAdded: opts?.componentAdded, - componentDeleted: opts?.componentDeleted, }); } }; @@ -1044,7 +993,7 @@ const EditorComponent = (props) => { }); }; - const realtimeSave = debounce(appDefinitionChanged, 900); + const realtimeSave = debounce(appDefinitionChanged, 500); const autoSave = debounce(saveEditingVersion, 200); function handlePaths(prevPatch, path = [], appJSON) { diff --git a/frontend/src/_stores/editorStore.js b/frontend/src/_stores/editorStore.js index ada3156f1d..a42dc2ae88 100644 --- a/frontend/src/_stores/editorStore.js +++ b/frontend/src/_stores/editorStore.js @@ -1,5 +1,4 @@ -import { create } from './utils'; -import { v4 as uuid } from 'uuid'; +import { create, zustandDevTools } from './utils'; const STORE_NAME = 'Editor'; @@ -40,7 +39,6 @@ const initialState = { showLeftSidebar: true, queryConfirmationList: [], currentPageId: null, - currentSessionId: uuid(), }; export const useEditorStore = create(