Moved currentState out of Editor & Container

This commit is contained in:
Kavin Venkatachalam 2024-04-11 18:28:57 +05:30
parent 4745d0019c
commit 91897d5865
2 changed files with 11 additions and 12 deletions

View file

@ -13,7 +13,6 @@ import config from 'config';
import Spinner from '@/_ui/Spinner';
import { useHotkeys } from 'react-hotkeys-hook';
import { addComponents, addNewWidgetToTheEditor, isPDFSupported } from '@/_helpers/appUtils';
import { useCurrentState } from '@/_stores/currentStateStore';
import { useAppVersionStore } from '@/_stores/appVersionStore';
import { useEditorStore } from '@/_stores/editorStore';
import { useAppInfo } from '@/_stores/appDataStore';
@ -31,7 +30,7 @@ import { useDraggedSubContainer, useGridStore } from '@/_stores/gridStore';
const deviceWindowWidth = EditorConstants.deviceWindowWidth;
export const Container = ({
canvasWidth,
widthOfCanvas,
mode,
snapToGrid,
onComponentClick,
@ -72,10 +71,13 @@ export const Container = ({
shallow
);
const canvasWidth = widthOfCanvas
? widthOfCanvas
: document.getElementsByClassName('canvas-area')[0]?.getBoundingClientRect()?.width;
const gridWidth = canvasWidth / noOfGrids;
const { appId } = useAppInfo();
const currentState = useCurrentState();
const { appVersionsId, isVersionReleased } = useAppVersionStore(
(state) => ({
appVersionsId: state?.editingVersion?.id,
@ -762,7 +764,6 @@ export const Container = ({
onEvent,
appDefinition,
appDefinitionChanged,
currentState,
appLoading,
zoomLevel,
setSelectedComponent,

View file

@ -59,7 +59,7 @@ import { useDataSourcesStore } from '@/_stores/dataSourcesStore';
import { useDataQueriesStore } from '@/_stores/dataQueriesStore';
import { useAppVersionStore, useAppVersionActions } from '@/_stores/appVersionStore';
import { useQueryPanelStore } from '@/_stores/queryPanelStore';
import { useCurrentStateStore, useCurrentState, getCurrentState } from '@/_stores/currentStateStore';
import { useCurrentStateStore, getCurrentState } from '@/_stores/currentStateStore';
import {
computeAppDiff,
computeComponentPropertyDiff,
@ -184,8 +184,6 @@ const EditorComponent = (props) => {
shallow
);
const currentState = useCurrentState();
const [zoomLevel, setZoomLevel] = useState(1);
const [isQueryPaneDragging, setIsQueryPaneDragging] = useState(false);
const [isQueryPaneExpanded, setIsQueryPaneExpanded] = useState(false); //!check where this is used
@ -241,7 +239,7 @@ const EditorComponent = (props) => {
});
useCurrentStateStore.getState().actions.setCurrentState({
globals: {
...currentState.globals,
...getCurrentState().globals,
theme: { name: props?.darkMode ? 'dark' : 'light' },
urlparams: JSON.parse(JSON.stringify(queryString.parse(props.location.search))),
currentUser: userVars,
@ -621,7 +619,7 @@ const EditorComponent = (props) => {
const changeDarkMode = (newMode) => {
useCurrentStateStore.getState().actions.setCurrentState({
globals: {
...currentState.globals,
...getCurrentState().globals,
theme: { name: newMode ? 'dark' : 'light' },
},
});
@ -1618,7 +1616,7 @@ const EditorComponent = (props) => {
};
const globals = {
...currentState.globals,
...getCurrentState().globals,
};
useCurrentStateStore.getState().actions.setCurrentState({ globals, page });
};
@ -1660,7 +1658,7 @@ const EditorComponent = (props) => {
const queryParamsString = queryParams.map(([key, value]) => `${key}=${value}`).join('&');
const globals = {
...currentState.globals,
...getCurrentState().globals,
urlparams: JSON.parse(JSON.stringify(queryString.parse(queryParamsString))),
};
@ -2098,7 +2096,7 @@ const EditorComponent = (props) => {
{defaultComponentStateComputed && (
<>
<Container
canvasWidth={getCanvasWidth()}
widthOfCanvas={getCanvasWidth()}
socket={socket}
appDefinitionChanged={appDefinitionChanged}
snapToGrid={true}