Skip to content

Commit c17d37a

Browse files
committed
removed use of statecontext
1 parent c9f7548 commit c17d37a

File tree

16 files changed

+64
-33
lines changed

16 files changed

+64
-33
lines changed

app/src/components/ContextAPIManager/AssignTab/components/ComponentDropDrown.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TextField from '@mui/material/TextField';
33
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
44
import Box from '@mui/material/Box';
55
import StateContext from '../../../../context/context';
6+
import { useSelector } from 'react-redux';
67

78
const filter = createFilterOptions();
89

@@ -13,7 +14,8 @@ const ComponentDropDown = ({
1314
setComponentInput
1415
}) => {
1516
const { allContext } = contextStore;
16-
const [componentList] = useContext(StateContext);
17+
// const [componentList] = useContext(StateContext);
18+
const state = useSelector(store => store.appState)
1719

1820
const onChange = (event, newValue) => {
1921
if (typeof newValue === 'string') {
@@ -77,7 +79,7 @@ const ComponentDropDown = ({
7779
selectOnFocus
7880
clearOnBlur
7981
handleHomeEndKeys
80-
options={componentList.components || []}
82+
options={state.components || []}
8183
getOptionLabel={getOptionLabel}
8284
renderOption={renderOption}
8385
sx={{ width: 425 }}

app/src/components/ContextAPIManager/CreateTab/components/AddContextForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Button from '@mui/material/Button';
55
import Box from '@mui/material/Box';
66
import { Typography } from '@mui/material';
77
import StateContext from '../../../../context/context';
8+
import { useSelector } from 'react-redux';
89

910
const filter = createFilterOptions();
1011

@@ -18,7 +19,8 @@ const AddContextForm = ({
1819
}) => {
1920
const { allContext } = contextStore;
2021
const [btnDisabled, setBtnDisabled] = useState(false);
21-
const [state, dispatch] = useContext(StateContext);
22+
// const [state, dispatch] = useContext(StateContext);
23+
const state = useSelector(store => store.appState)
2224

2325
const handleClick = () => {
2426
if (contextInput === '' || contextInput === null) return;

app/src/components/StateManagement/DisplayTab/DataTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Paper from '@mui/material/Paper';
88
import { styled } from '@mui/material/styles';
99
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
1010
import StateContext from '../../../context/context';
11+
import { useSelector } from 'react-redux';
1112

1213
const StyledTableCell = styled(TableCell)(({ theme }) => ({
1314
[`&.${tableCellClasses.head}`]: {
@@ -33,7 +34,8 @@ export default function DataTable(props) {
3334
const {
3435
currComponentState, parentProps, clickedComp, data,
3536
} = props;
36-
const [state, dispatch] = useContext(StateContext);
37+
// const [state, dispatch] = useContext(StateContext);
38+
const state = useSelector(store => store.appState)
3739

3840
// determine if the current component is a root component
3941
let isRoot = false;

app/src/components/StateManagement/DisplayTab/DisplayContainer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { Typography } from '@mui/material';
55
import DataTable from './DataTable';
66
import Tree from './Tree';
77
import StateContext from '../../../context/context';
8+
import { useSelector } from 'react-redux';
89

910
function DisplayContainer({ data, props }) { // "data" is referring to components from state - passed in from StateManagement
1011
// grabbing intialized state from App using UseContext
1112
const [currComponentState, setCurrComponentState] = useState([]);
1213
const [parentProps, setParentProps] = useState([]);
13-
const [state, dispatch] = useContext(StateContext);
14-
14+
// const [state, dispatch] = useContext(StateContext);
15+
const state = useSelector(store => store.appState)
16+
1517
let root = '';
1618

1719
// check the canvasFocus

app/src/components/StateManagement/DisplayTab/Tree.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
import cloneDeep from 'lodash/cloneDeep';
66
import useResizeObserver from './useResizeObserver';
77
import StateContext from '../../../context/context';
8+
import { useSelector } from 'react-redux';
89

910
function usePrevious(value) {
1011
const ref = useRef();
@@ -15,7 +16,8 @@ function usePrevious(value) {
1516
function Tree({
1617
data, currComponentState, setCurrComponentState, parentProps, setParentProps, setClickedComp,
1718
}) {
18-
const [state, dispatch] = useContext(StateContext);
19+
// const [state, dispatch] = useContext(StateContext);
20+
const state = useSelector(store => store.appState)
1921
const svgRef = useRef();
2022
const wrapperRef = useRef();
2123
const xPosition = 50;

app/src/components/StateManagement/StateManagement.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TabContext from '@mui/lab/TabContext';
66
import TabList from '@mui/lab/TabList';
77
import TabPanel from '@mui/lab/TabPanel';
88
import StateContext from '../../context/context';
9+
import { useSelector } from 'react-redux';
910

1011
import CreateContainer from './CreateTab/CreateContainer';
1112
import DisplayContainer from './DisplayTab/DisplayContainer';
@@ -20,7 +21,8 @@ const useStyles = makeStyles({
2021
});
2122

2223
const StateManager = (props): JSX.Element => {
23-
const [state, dispatch] = useContext(StateContext);
24+
// const [state, dispatch] = useContext(StateContext);
25+
const state = useSelector(store => store.appState)
2426
const { components, HTMLTypes } = state;
2527
const classes = useStyles();
2628
const [value, setValue] = React.useState<string>('1');

app/src/components/bottom/CodePreview.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { fetchPlugin } from '../../plugins/fetch-plugin';
1616
import * as esbuild from 'esbuild-wasm';
1717
import store from '../../redux/store';
1818
import {codePreviewSave, codePreviewInput} from "../../redux/reducers/slice/codePreviewSlice";
19-
import { useDispatch } from 'react-redux';
19+
import { useDispatch, useSelector } from 'react-redux';
2020
// import { store } from './../../index';
2121
const CodePreview: React.FC<{
2222
theme: string | null;
@@ -39,7 +39,8 @@ const CodePreview: React.FC<{
3939
const dimensions = useResizeObserver(wrapper);
4040
const { height } = dimensions || 0;
4141

42-
const [state] = useContext(StateContext);
42+
// const [state] = useContext(StateContext);
43+
const state = useSelector(store => store.appState)
4344
const [, setDivHeight] = useState(0);
4445
let currentComponent = state.components.find(
4546
(elem: Component) => elem.id === state.canvasFocus.componentId

app/src/components/bottom/UseStateModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import React, {useState, useContext, useRef} from 'react';
22
import Modal from '@mui/material/Modal';
33
import StateContext from '../../context/context';
44
import TableStateProps from './TableStateProps';
5+
import { useSelector } from 'react-redux';
56

67

78
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
8-
const [state, dispatch] = useContext(StateContext);
9+
// const [state, dispatch] = useContext(StateContext);
10+
const state = useSelector(store => store.appState)
911
const [open, setOpen] = useState(false);
1012
const [stateKey, setStateKey] = useState('');
1113
const [statePropsId, setStatePropsId] = useState(-1);

app/src/components/right/ComponentDrag.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { useSelector } from 'react-redux';
88
// The component panel section of the left panel displays all components and has the ability to add new components
99
const ComponentDrag = ({ isThemeLight }): JSX.Element => {
1010
const classes = useStyles();
11-
const [state,] = useContext(StateContext);
11+
// const [state,] = useContext(StateContext);
12+
const state = useSelector(store => store.appState)
1213
const isDarkMode = useSelector(store => store.darkMode.isDarkMode);
1314
const isFocus = (targetId: Number) => {
1415
return state.canvasFocus.componentId === targetId ? true : false;

app/src/components/right/ComponentPanelRoutingItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import StateContext from '../../context/context';
55
import { useDrag } from 'react-dnd';
66
import { ItemTypes } from '../../constants/ItemTypes';
77
import Select from '@mui/material/Select';
8+
import { useSelector } from 'react-redux';
89

910
// ------------------------------------------------
1011
import MenuItem from '@mui/material/MenuItem';
@@ -26,7 +27,8 @@ Dragging works in the same manner as in ComponentPanelItem.tsx
2627
// a component panel routing item is a Next.js component that allows the user to navigate between pages
2728
const ComponentPanelRoutingItem: React.FC<{}> = () => {
2829
const classes = useStyles(); 's there, '
29-
const [state,] = useContext(StateContext);
30+
// const [state,] = useContext(StateContext);
31+
const state = useSelector(store => store.appState)
3032

3133
// find the root components that can be associated with a route
3234
// These will be the components that are displayed in the dropdown adjacent to "Route Link"

app/src/components/right/ExportButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import Button from '@mui/material/Button';
88
import exportProject from '../../utils/exportProject.util';
99
import createModal from './createModal';
1010
import { styleContext } from '../../containers/AppContainer';
11+
import { useSelector } from 'react-redux';
1112
export default function ExportButton() {
1213
const [modal, setModal] = useState(null);
13-
const [state] = useContext(StateContext);
14+
// const [state] = useContext(StateContext);
15+
const state = useSelector(store => store.appState)
1416

1517
const genOptions: string[] = [
1618
'Export components',

app/src/components/right/LoginButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import ExitToAppIcon from '@mui/icons-material/ExitToApp';
44
import { useHistory } from 'react-router-dom';
55
import makeStyles from '@mui/styles/makeStyles';
66
import StateContext from '../../context/context';
7+
import { useSelector } from 'react-redux';
78

89
export default function LoginButton() {
910
const history = useHistory();
10-
const [state,] = useContext(StateContext);
11+
// const [state,] = useContext(StateContext);
12+
const state = useSelector(store => store.appState)
1113
// const handleLogout = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
1214
// e.preventDefault();
1315
// // clear local storage

app/src/helperFunctions/renderChildren.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import DirectChildHTMLNestable from '../components/main/DirectChildHTMLNestable'
66
import SeparatorChild from '../components/main/SeparatorChild';
77
import RouteLink from '../components/main/RouteLink';
88
import StateContext from '../context/context';
9+
import { useSelector } from 'react-redux';
910

1011
// helper method to render all direct children of a component
1112
// direct children are clickable and draggable
1213
// direct children may also have their own indirect children (grandchildren, great-grandchildren, etc) which are not draggable and clickable
1314
// there are four types of direct children that can be rendered on the screen
1415
const renderChildren = (children: ChildElement[]) => {
15-
const [state, dispatch] = useContext(StateContext);
16-
16+
// const [state, dispatch] = useContext(StateContext);
17+
const state = useSelector(store => store.appState)
18+
1719
return children.map((child: ChildElement, i: number) => {
1820
const { type, style, childId, children, attributes, name } = child;
1921
let { typeId } = child;

app/src/redux/HTMLTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const HTMLTypes = [
1515
style: {},
1616
placeHolderShort: 'div',
1717
placeHolderLong: '',
18-
icon: HeaderIcon,
18+
// icon: HeaderIcon,
1919
framework: 'reactClassic',
2020
nestable: true
2121
},

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,12 @@ const appStateSlice = createSlice({
237237
if (
238238
typeof action.payload.componentName !== 'string' ||
239239
action.payload.componentName === ''
240-
)
241-
return state;
242-
const components = [...state.components];
240+
) {
241+
// return state;
242+
return
243+
}
244+
245+
// const components = [...state.components];
243246
const newComponent = {
244247
id: state.components.length + 1,
245248
name: action.payload.componentName,
@@ -255,10 +258,10 @@ const appStateSlice = createSlice({
255258
useStateCodes: [],
256259
passedInProps: []
257260
};
258-
components.push(newComponent);
261+
state.components.push(newComponent);
259262
// functionality if the new component will become the root component
260-
const rootComponents = [...state.rootComponents];
261-
if (action.payload.root) rootComponents.push(newComponent.id);
263+
// const rootComponents = [...state.rootComponents];
264+
if (action.payload.root) state.rootComponents.push(newComponent.id);
262265
// updates the focus to the new component, which redirects to the new blank canvas of said new component
263266

264267
// change canvas focus to just created component
@@ -269,23 +272,24 @@ const appStateSlice = createSlice({
269272
// };
270273
const nextComponentId = state.nextComponentId + 1;
271274
newComponent.code = generateCode(
272-
components,
275+
state.components,
273276
newComponent.id,
274277
[...state.rootComponents],
275278
state.projectType,
276279
state.HTMLTypes,
277280
state.tailwind
278281
);
279-
return {
280-
...state,
281-
components,
282-
rootComponents,
283-
nextComponentId
282+
283+
// return {
284+
// ...state,
285+
// components,
286+
// rootComponents,
287+
// nextComponentId
284288
// canvasFocus
285-
};
289+
// },
286290
// state.components = components;
287291
// state.rootComponents = rootComponents;
288-
// state.nextComponentId = nextComponentId
292+
state.nextComponentId = nextComponentId
289293

290294

291295
},

app/src/tree/TreeChart.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cloneDeep from 'lodash/cloneDeep';
44
import useResizeObserver from './useResizeObserver';
55
import StateContext from '../context/context';
66
import { element } from 'prop-types';
7+
import { useSelector } from 'react-redux';
78

89
function usePrevious(value) {
910
const ref = useRef(); // creates a ref obj w/ current: value
@@ -14,7 +15,9 @@ function usePrevious(value) {
1415
}
1516

1617
function TreeChart({ data }) { // data is components from state - passed in from BottomTabs
17-
const [state, dispatch] = useContext(StateContext);
18+
// const [state, dispatch] = useContext(StateContext);
19+
const state = useSelector(store => store.appState)
20+
1821
const canvasId = state.canvasFocus.componentId;
1922

2023
const svgRef = useRef();

0 commit comments

Comments
 (0)