Skip to content

Commit 18f1177

Browse files
authored
Merge pull request #13 from oslabs-beta/mike/allstate
Mike/allstate
2 parents 4230fa2 + 1dceff1 commit 18f1177

File tree

9 files changed

+78
-41
lines changed

9 files changed

+78
-41
lines changed

app/src/components/main/AddLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function AddLink({ id, onClickHandler, linkDisplayed }) {
3939
state.childId = id;
4040
state.attributes.compLink = event.target.value;
4141
// dispatch({type: 'UPDATE ATTRIBUTES', payload: state})
42-
dispatch(updateAttributes({attributes: state}))
42+
dispatch(updateAttributes(state))
4343
return true;
4444
}
4545
});

app/src/components/main/AddRoute.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ function AddRoute({
99
}: AddRoutes) {
1010
// const [, dispatch] = useContext(StateContext);
1111
const dispatch = useDispatch();
12-
12+
const contextParam = useSelector(store => store.contextSlice)
1313
const handleClick = (id) => {
1414
dispatch(addChild({
1515
type: 'HTML Element',
1616
typeId: -1,
17-
childId: id // this is the id of the parent to attach it to
17+
childId: id, // this is the id of the parent to attach it to
18+
contextParam: store.contextSlice
1819
}))
1920
// dispatch({
2021
// type: 'ADD CHILD',

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 1 deletion
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,snapShotAction } 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);

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import AddRoute from './AddRoute';
1414
import AddLink from './AddLink';
1515
import { useDispatch, useSelector } from 'react-redux';
1616

17-
import { changeFocus, changePosition,addChild } from '../../redux/reducers/slice/appStateSlice';
17+
import { changeFocus, changePosition, addChild, snapShotAction } from '../../redux/reducers/slice/appStateSlice';
1818

1919
import { styleContext } from '../../containers/AppContainer';
2020

@@ -30,7 +30,11 @@ function DirectChildHTMLNestable({
3030
// const [state, dispatch] = useContext(StateContext);
3131
const { isThemeLight } = useContext(styleContext);
3232
const isDarkMode = useSelector(store => store.darkMode.isDarkMode);
33-
const state = useSelector(store => store.appState);
33+
// const state = useSelector(store => store.appState);
34+
const { state, contextParam } = useSelector((store) => ({
35+
state: store.appState,
36+
contextParam: store.contextSlice,
37+
}));
3438
const dispatch = useDispatch();
3539
const ref = useRef(null);
3640
// const [linkDisplayed, setLinkDisplayed] = useState('');
@@ -41,9 +45,9 @@ function DirectChildHTMLNestable({
4145
const deepCopiedState = JSON.parse(JSON.stringify(state));
4246
const focusIndex = state.canvasFocus.componentId - 1;
4347
//pushes the last user action on the canvas into the past array of Component
44-
state.components[focusIndex].past.push(
45-
deepCopiedState.components[focusIndex].children
46-
);
48+
// state.components[focusIndex].past.push(
49+
// deepCopiedState.components[focusIndex].children
50+
dispatch(snapShotAction({focusIndex: focusIndex, deepCopiedState: deepCopiedState}))
4751
};
4852

4953
// find the HTML element corresponding with this instance of an HTML element
@@ -96,7 +100,8 @@ function DirectChildHTMLNestable({
96100
dispatch(addChild({
97101
type: item.instanceType,
98102
typeId: item.instanceTypeId,
99-
childId: childId
103+
childId: childId,
104+
contextParam: contextParam
100105
}))
101106
// dispatch({
102107
// type: 'ADD CHILD',

app/src/components/main/SeparatorChild.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import validateNewParent from '../../helperFunctions/changePositionValidation'
1010
import componentNest from '../../helperFunctions/componentNestValidation'
1111
import { useDispatch, useSelector } from 'react-redux';
1212

13-
import { changeFocus, changePosition,addChild } from '../../redux/reducers/slice/appStateSlice';
13+
import { changeFocus, changePosition, addChild } from '../../redux/reducers/slice/appStateSlice';
1414

1515

1616

@@ -22,7 +22,11 @@ function DirectChildHTMLNestable({
2222
children
2323
}: ChildElement) {
2424
// const [state, dispatch] = useContext(StateContext);
25-
const state = useSelector(store => store.appState);
25+
// const state = useSelector(store => store.appState);
26+
const { state, contextParam } = useSelector((store) => ({
27+
state: store.appState,
28+
contextParam: store.contextSlice,
29+
}));
2630
const dispatch = useDispatch();
2731
const ref = useRef(null);
2832

@@ -67,6 +71,7 @@ function DirectChildHTMLNestable({
6771
type: item.instanceType,
6872
typeId: item.instanceTypeId,
6973
childId: childId,
74+
contextParam: contextParam
7075
}))
7176
// dispatch({
7277
// type: 'ADD CHILD',

app/src/components/right/DeleteProjects.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function ProjectsDialog(props: ProjectDialogProps) {
4646
deleteProject(selectedProject);
4747
localforage.removeItem(window.localStorage.getItem('ssid'));
4848
// dispatch({ type: 'SET INITIAL STATE', payload: initialState });
49-
dispatch(setInitialState({}))
49+
dispatch(setInitialState(initialState))
5050
onClose();
5151
};
5252

app/src/components/right/OpenProjects.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function ProjectsDialog(props: ProjectDialogProps) {
3737
(project: any) => project.name === value
3838
)[0];
3939
// dispatch({ type: 'OPEN PROJECT', payload: selectedProject });
40-
dispatch(openProject({selectedProject}))
40+
dispatch(openProject(selectedProject))
4141
onClose();
4242
};
4343
return (

app/src/containers/CustomizationPanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
307307

308308
const deleteEvent = selectedEvent => {
309309
dispatch(deleteEventAction({ event: selectedEvent }))
310-
// dispatch({
311-
// type: 'DELETE EVENT',
312-
// payload: { event: selectedEvent }
313-
// });
310+
// dispatch({
311+
// type: 'DELETE EVENT',
312+
// payload: { event: selectedEvent }
313+
// });
314314
};
315315

316316

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

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ const appStateSlice = createSlice({
291291
// },
292292
// state.components = components;
293293
// state.rootComponents = rootComponents;
294-
// state.nextComponentId = nextComponentId
294+
state.nextComponentId = nextComponentId
295295

296296

297297
},
@@ -412,14 +412,19 @@ const appStateSlice = createSlice({
412412
state.tailwind,
413413
action.payload.contextParam
414414
);
415-
console.log('entered the addchild2')
415+
416416
// return {
417417
// ...state,
418418
// components,
419419
// nextChildId,
420420
// canvasFocus,
421421
// nextTopSeparatorId
422422
// };
423+
state.components =components;
424+
state.nextChildId = nextChildId;
425+
state.canvasFocus = canvasFocus;
426+
state.nextTopSeparatorId = nextTopSeparatorId;
427+
423428
},
424429
changeTailwind: (state, action) => {
425430
return { ...state, tailwind: action.payload }
@@ -471,7 +476,8 @@ const appStateSlice = createSlice({
471476
[...state.rootComponents],
472477
state.projectType,
473478
state.HTMLTypes,
474-
state.tailwind
479+
state.tailwind,
480+
action.payload.contextParam
475481
);
476482
return { ...state, components };
477483
},
@@ -527,7 +533,8 @@ const appStateSlice = createSlice({
527533
[...state.rootComponents],
528534
state.projectType,
529535
state.HTMLTypes,
530-
state.tailwind
536+
state.tailwind,
537+
action.payload.contextParam
531538
);
532539
return { ...state, components, nextTopSeparatorId };
533540
},
@@ -542,7 +549,8 @@ const appStateSlice = createSlice({
542549
[...state.rootComponents],
543550
state.projectType,
544551
state.HTMLTypes,
545-
state.tailwind
552+
state.tailwind,
553+
action.payload.contextParam
546554
);
547555
return { ...state, components };
548556
},
@@ -565,7 +573,8 @@ const appStateSlice = createSlice({
565573
[...state.rootComponents],
566574
state.projectType,
567575
state.HTMLTypes,
568-
state.tailwind
576+
state.tailwind,
577+
action.payload.contextParam
569578
);
570579
return { ...state, components };
571580
},
@@ -590,7 +599,8 @@ const appStateSlice = createSlice({
590599
[...state.rootComponents],
591600
state.projectType,
592601
state.HTMLTypes,
593-
state.tailwind
602+
state.tailwind,
603+
action.payload.contextParam
594604
);
595605
return { ...state, components };
596606
},
@@ -611,7 +621,8 @@ const appStateSlice = createSlice({
611621
[...state.rootComponents],
612622
state.projectType,
613623
state.HTMLTypes,
614-
state.tailwind
624+
state.tailwind,
625+
action.payload.contextParam
615626
);
616627
return { ...state, components };
617628
},
@@ -664,7 +675,8 @@ const appStateSlice = createSlice({
664675
rootComponents,
665676
state.projectType,
666677
state.HTMLTypes,
667-
state.tailwind
678+
state.tailwind,
679+
action.payload.contextParam
668680
);
669681
}
670682
const canvasFocus = { componentId: 1, childId: null };
@@ -698,7 +710,8 @@ const appStateSlice = createSlice({
698710
[...state.rootComponents],
699711
projectType,
700712
state.HTMLTypes,
701-
state.tailwind
713+
state.tailwind,
714+
action.payload.contextParam
702715
);
703716
});
704717
return { ...state, components, projectType };
@@ -756,7 +769,8 @@ const appStateSlice = createSlice({
756769
rootComponents,
757770
state.projectType,
758771
state.HTMLTypes,
759-
state.tailwind
772+
state.tailwind,
773+
action.payload.contextParam
760774
);
761775
});
762776
return {
@@ -808,7 +822,8 @@ const appStateSlice = createSlice({
808822
[...state.rootComponents],
809823
state.projectType,
810824
state.HTMLTypes,
811-
state.tailwind
825+
state.tailwind,
826+
action.payload.contextParam
812827
);
813828
return { ...state, components, canvasFocus, nextTopSeparatorId };
814829
},
@@ -857,7 +872,8 @@ const appStateSlice = createSlice({
857872
state.rootComponents,
858873
state.projectType,
859874
state.HTMLTypes,
860-
state.tailwind
875+
state.tailwind,
876+
action.payload.contextParam
861877
);
862878
});
863879
return {
@@ -885,7 +901,8 @@ const appStateSlice = createSlice({
885901
state.rootComponents,
886902
state.projectType,
887903
state.HTMLTypes,
888-
state.tailwind
904+
state.tailwind,
905+
action.payload.contextParam
889906

890907
);
891908
});
@@ -910,7 +927,8 @@ const appStateSlice = createSlice({
910927
[...state.rootComponents],
911928
state.projectType,
912929
state.HTMLTypes,
913-
state.tailwind
930+
state.tailwind,
931+
action.payload.contextParam
914932
);
915933
return { ...state, components };
916934
},
@@ -962,7 +980,8 @@ const appStateSlice = createSlice({
962980
[...state.rootComponents],
963981
state.projectType,
964982
state.HTMLTypes,
965-
state.tailwind
983+
state.tailwind,
984+
action.payload.contextParam
966985
);
967986
//update code preview for parent component (since we have added it to the children array)
968987
parent.code = generateCode(
@@ -971,7 +990,8 @@ const appStateSlice = createSlice({
971990
[...state.rootComponents],
972991
state.projectType,
973992
state.HTMLTypes,
974-
state.tailwind
993+
state.tailwind,
994+
action.payload.contextParam
975995
);
976996

977997
return { ...state, components };
@@ -1025,7 +1045,8 @@ const appStateSlice = createSlice({
10251045
[...state.rootComponents],
10261046
state.projectType,
10271047
state.HTMLTypes,
1028-
state.tailwind
1048+
state.tailwind,
1049+
action.payload.contextParam
10291050
);
10301051
};
10311052
//delete from the components passedInProps array
@@ -1048,7 +1069,8 @@ const appStateSlice = createSlice({
10481069
[...state.rootComponents],
10491070
state.projectType,
10501071
state.HTMLTypes,
1051-
state.tailwind
1072+
state.tailwind,
1073+
action.payload.contextParam
10521074
);
10531075
return;
10541076
}
@@ -1070,7 +1092,8 @@ const appStateSlice = createSlice({
10701092
[...state.rootComponents],
10711093
state.projectType,
10721094
state.HTMLTypes,
1073-
state.tailwind
1095+
state.tailwind,
1096+
action.payload.contextParam
10741097
);
10751098
};
10761099

@@ -1083,7 +1106,8 @@ const appStateSlice = createSlice({
10831106
[...state.rootComponents],
10841107
state.projectType,
10851108
state.HTMLTypes,
1086-
state.tailwind
1109+
state.tailwind,
1110+
action.payload.contextParam
10871111
);
10881112
return { ...state, components };
10891113
},
@@ -1186,7 +1210,8 @@ const appStateSlice = createSlice({
11861210
[...state.rootComponents],
11871211
state.projectType,
11881212
state.HTMLTypes,
1189-
state.tailwind
1213+
state.tailwind,
1214+
action.payload.contextParam
11901215
);
11911216
}
11921217

@@ -1197,7 +1222,8 @@ const appStateSlice = createSlice({
11971222
[...state.rootComponents],
11981223
state.projectType,
11991224
state.HTMLTypes,
1200-
state.tailwind
1225+
state.tailwind,
1226+
action.payload.contextParam
12011227
);
12021228
});
12031229
return { ...state, components };

0 commit comments

Comments
 (0)