Skip to content

Commit d832222

Browse files
committed
fixes snapshotfunc in canvas
1 parent 64415dd commit d832222

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

app/src/components/main/Canvas.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Arrow from './Arrow';
1010
import { getRowsStateFromCache } from '@mui/x-data-grid/hooks/features/rows/gridRowsUtils';
1111
// Redux Toolkit test
1212
import { useDispatch, useSelector } from 'react-redux';
13-
import { changeFocus, addChild } from '../../redux/reducers/slice/appStateSlice';
13+
import { changeFocus, addChild,snapShotAction } from '../../redux/reducers/slice/appStateSlice';
1414

1515
function Canvas(props): JSX.Element {
1616
// const [state, dispatch] = useContext(StateContext);
@@ -89,24 +89,34 @@ function Canvas(props): JSX.Element {
8989
// stores a snapshot of state into the past array for UNDO. snapShotFunc is also invoked for nestable elements in DirectChildHTMLNestable.tsx
9090
const snapShotFunc = () => {
9191
// make a deep clone of state
92+
9293
const deepCopiedState = JSON.parse(JSON.stringify(state));
94+
9395
const focusIndex = state.canvasFocus.componentId - 1;
96+
console.log('about to dispatch snapshot')
9497
//pushes the last user action on the canvas into the past array of Component
95-
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
98+
// state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
99+
100+
dispatch(snapShotAction({focusIndex: focusIndex, deepCopiedState: deepCopiedState}))
101+
console.log('left snapshot dispatch moving on ')
96102
};
97103

98104
// This hook will allow the user to drag items from the left panel on to the canvas
99105
const [{ isOver }, drop] = useDrop({
100106
accept: ItemTypes.INSTANCE,
101107
drop: (item: DragItem, monitor: DropTargetMonitor) => {
102108
const didDrop = monitor.didDrop();
109+
103110
// takes a snapshot of state to be used in UNDO and REDO cases
111+
console.log('about to snapshot')
104112
snapShotFunc();
113+
console.log('achieved snopshopt')
105114
// returns false for direct drop target
115+
console.log('diddrop', didDrop)
106116
if (didDrop) {
107117
return;
108118
}
109-
console.log(currentComponent)
119+
110120
// if item dropped is going to be a new instance (i.e. it came from the left panel), then create a new child component
111121
if (item.newInstance && item.instanceType !== "Component") {
112122
dispatch(addChild({

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ const appStateSlice = createSlice({
398398
);
399399
components[canvasFocus.componentId - 1].children = addChildArray;
400400

401-
parentComponent.code = generateCode(
402-
components,
403-
parentComponentId,
404-
[...state.rootComponents],
405-
state.projectType,
406-
state.HTMLTypes,
407-
state.tailwind
408-
);
401+
// parentComponent.code = generateCode(
402+
// components,
403+
// parentComponentId,
404+
// [...state.rootComponents],
405+
// state.projectType,
406+
// state.HTMLTypes,
407+
// state.tailwind
408+
// );
409409

410410
return {
411411
...state,
@@ -1204,13 +1204,16 @@ const appStateSlice = createSlice({
12041204
saveTimer: !state.config.saveTimer
12051205
};
12061206
},
1207+
snapShotAction: (state,action) => {
1208+
state.components[action.payload.focusIndex].past.push(action.payload.deepCopiedState.components[action.payload.focusIndex].children);
1209+
}
12071210
}
12081211
});
12091212

12101213
// Exports the action creator function to be used with useDispatch
12111214

12121215

1213-
export const { addComponent, addChild, changeFocus, changeTailwind, changePosition, updateStateUsed, resetAllState, updateUseContext, updateCss, updateEvents, deleteEventAction, deletePage, deleteReusableComponent, setProjectName, changeProjectType, resetState, updateProjectName, deleteElement, updateAttributes, deleteChild, setInitialState, openProject, addElement, undo, redo, addState, addPassedInProps, deletePassedInProps, deleteState, toggleLoggedIn, configToggle } = appStateSlice.actions;
1216+
export const { addComponent, addChild, changeFocus, changeTailwind, changePosition, updateStateUsed, resetAllState, updateUseContext, updateCss, updateEvents, deleteEventAction, deletePage, deleteReusableComponent, setProjectName, changeProjectType, resetState, updateProjectName, deleteElement, updateAttributes, deleteChild, setInitialState, openProject, addElement, undo, redo, addState, addPassedInProps, deletePassedInProps, deleteState, toggleLoggedIn, configToggle, snapShotAction } = appStateSlice.actions;
12141217

12151218

12161219
// Exports so we can combine in rootReducer

0 commit comments

Comments
 (0)