Skip to content

Commit b73ed63

Browse files
authored
Merge pull request #5 from oslabs-beta/feature/RDTK
Feature/rdtk
2 parents 5b5ebcc + e97402d commit b73ed63

File tree

7 files changed

+226
-126
lines changed

7 files changed

+226
-126
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React, { useContext, useState, Fragment, useEffect } from 'react';
22
import DataTable from '../CreateTab/components/DataTable';
3-
import { useStore, useDispatch } from 'react-redux';
43
import ContextDropDown from './components/ContextDropDown';
54
import ComponentDropDown from './components/ComponentDropDrown';
65
import Divider from '@mui/material/Divider';
76
import Grid from '@mui/material/Grid';
87
import ComponentTable from './components/ComponentTable';
98
import { Button } from '@mui/material';
109
import DoubleArrowIcon from '@mui/icons-material/DoubleArrow';
11-
import * as actions from '../../../redux/actions/actions';
10+
// import * as actions from '../../../redux/actions/actions';
1211
import StateContext from '../../../context/context';
12+
import {addComponentToContext} from '../../../redux/reducers/slice/contextReducer'
13+
import {useSelector, useDispatch , useStore,} from 'react-redux';
1314

1415
const AssignContainer = () => {
1516
const store = useStore();
@@ -22,11 +23,12 @@ const AssignContainer = () => {
2223
const [componentInput, setComponentInput] = React.useState(null);
2324
const [componentTable, setComponentTable] = useState([]);
2425
const [stateContext, dispatchContext] = useContext(StateContext);
26+
const allContext = useSelector(state => state.contextSlice);
2527

2628
//fetching data from redux store
2729
useEffect(() => {
28-
setState(store.getState().contextSlice);
29-
}, []);
30+
setState(allContext);
31+
}, [allContext]);
3032

3133
const renderTable = targetContext => {
3234
if (targetContext === null || !targetContext.values) {
@@ -65,7 +67,7 @@ const AssignContainer = () => {
6567
)
6668
return;
6769
dispatch(
68-
actions.addComponentToContext({
70+
addComponentToContext({
6971
context: contextInput,
7072
component: componentInput
7173
})
@@ -76,7 +78,7 @@ const AssignContainer = () => {
7678
payload: 'FAKE_ID'
7779
});
7880

79-
setState(store.getState().contextSlice);
81+
// setState(allContext);
8082
renderComponentTable(componentInput);
8183
};
8284

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
import React, { useEffect, useState, useContext } from 'react';
22
import { useStore } from 'react-redux';
3-
import { useDispatch } from 'react-redux';
43
import Divider from '@mui/material/Divider';
54
import Grid from '@mui/material/Grid';
65
import DataTable from './components/DataTable';
76
import AddDataForm from './components/AddDataForm';
87
import AddContextForm from './components/AddContextForm';
9-
import * as actions from '../../../redux/actions/actions';
8+
// import * as actions from '../../../redux/actions/actions';
109
import { Typography } from '@mui/material';
1110
import StateContext from '../../../context/context';
11+
import { addContext, addContextValues, deleteContext, getAllContext, addComponentToContext} from '../../../redux/reducers/slice/contextReducer';
12+
import {useSelector, useDispatch } from 'react-redux';
1213

1314
const CreateContainer = () => {
1415
const defaultTableData = [{ key: 'Enter Key', value: 'Enter value' }];
16+
const allContext = useSelector(state => state.contextSlice);
17+
1518
const store = useStore();
1619
const [state, setState] = useState([]);
1720
const [tableState, setTableState] = React.useState(defaultTableData);
1821
const [contextInput, setContextInput] = React.useState(null);
1922
const [stateContext, dispatchContext] = useContext(StateContext);
23+
const dispatch = useDispatch();
2024

2125
//pulling data from redux store
2226
useEffect(() => {
23-
setState(store.getState().contextSlice);
24-
}, []);
27+
console.log('allcon',allContext)
28+
setState(allContext)
29+
// setState(store.getState().contextSlice);
30+
31+
}, [allContext]);
32+
2533

26-
const dispatch = useDispatch();
2734

2835
//update data store when user adds a new context
2936
const handleClickSelectContext = () => {
@@ -34,23 +41,24 @@ const CreateContainer = () => {
3441
}
3542
}
3643
setContextInput('');
37-
dispatch(actions.addContextActionCreator(contextInput));
38-
setState(store.getState().contextSlice);
44+
dispatch(addContext(contextInput));
45+
46+
// setState(allContext);
3947
};
4048

4149
//update data store when user add new key-value pair to context
4250
const handleClickInputData = ({ name }, { inputKey, inputValue }) => {
4351
dispatch(
44-
actions.addContextValuesActionCreator({ name, inputKey, inputValue })
52+
addContext({ name, inputKey, inputValue })
4553
);
46-
setState(store.getState().contextSlice);
54+
// setState(allContext);
4755
};
4856

4957
//update data store when user deletes context
5058
const handleDeleteContextClick = () => {
51-
dispatch(actions.deleteContext(contextInput));
59+
dispatch(deleteContext(contextInput));
5260
setContextInput('');
53-
setState(store.getState().contextSlice);
61+
// setState(allContext);
5462
setTableState(defaultTableData);
5563
dispatchContext({
5664
type: 'DELETE ELEMENT',

app/src/components/bottom/CodePreview.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { unpkgPathPlugin } from '../../plugins/unpkg-path-plugin';
1515
import { fetchPlugin } from '../../plugins/fetch-plugin';
1616
import * as esbuild from 'esbuild-wasm';
1717
import store from '../../redux/store';
18+
import {codePreviewSave, codePreviewInput} from "../../redux/reducers/slice/codePreviewSlice";
19+
import { useDispatch } from 'react-redux';
1820
// import { store } from './../../index';
1921
const CodePreview: React.FC<{
2022
theme: string | null;
@@ -31,6 +33,7 @@ const CodePreview: React.FC<{
3133
wasmURL: 'https://unpkg.com/[email protected]/esbuild.wasm'
3234
});
3335
};
36+
const dispatch = useDispatch();
3437

3538
const wrapper = useRef();
3639
const dimensions = useResizeObserver(wrapper);
@@ -54,10 +57,11 @@ const CodePreview: React.FC<{
5457

5558
useEffect(() => {
5659
setInput(currentComponent.code);
57-
store.dispatch({
58-
type: 'CODE_PREVIEW_INPUT',
59-
payload: currentComponent.code
60-
});
60+
dispatch(codePreviewInput(currentComponent.code));
61+
// store.dispatch({
62+
// type: 'CODE_PREVIEW_INPUT',
63+
// payload: currentComponent.code
64+
// });
6165
}, [currentComponent, state.components]);
6266

6367
/**
@@ -67,7 +71,8 @@ const CodePreview: React.FC<{
6771
const handleChange = async (data) => {
6872
// console.log('changed');
6973
setInput(data);
70-
store.dispatch({ type: 'CODE_PREVIEW_INPUT', payload: data });
74+
dispatch(codePreviewInput(data));
75+
// store.dispatch({ type: 'CODE_PREVIEW_INPUT', payload: data });
7176
if (!ref.current) {
7277
return;
7378
}
@@ -83,10 +88,11 @@ const CodePreview: React.FC<{
8388
global: 'window'
8489
}
8590
});
86-
store.dispatch({
87-
type: 'CODE_PREVIEW_SAVE',
88-
payload: result.outputFiles[0].text
89-
});
91+
dispatch(codePreviewSave(result.outputFiles[0].text))
92+
// store.dispatch({
93+
// type: 'CODE_PREVIEW_SAVE',
94+
// payload: result.outputFiles[0].text
95+
// });
9096
};
9197

9298
return (

app/src/redux/actions/actions.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ import * as types from '../constants/actionTypes';
55
// });
66

77
//actions for context slice
8-
export const addContextActionCreator = (contextName) => ({
9-
type: types.ADD_CONTEXT,
10-
payload: contextName
11-
});
8+
// export const addContextActionCreator = (contextName) => ({
9+
// type: types.ADD_CONTEXT,
10+
// payload: contextName
11+
// });
1212

13-
export const addContextValuesActionCreator = (newEntry) => ({
14-
type: types.ADD_CONTEXT_VALUES,
15-
payload: newEntry
16-
});
13+
// export const addContextValuesActionCreator = (newEntry) => ({
14+
// type: types.ADD_CONTEXT_VALUES,
15+
// payload: newEntry
16+
// });
1717

18-
export const addComponentToContext = (newEntry) => ({
19-
type: types.ADD_COMPONENT_TO_CONTEXT,
20-
payload: newEntry
21-
});
18+
// export const addComponentToContext = (newEntry) => ({
19+
// type: types.ADD_COMPONENT_TO_CONTEXT,
20+
// payload: newEntry
21+
// });
2222

23-
export const deleteContext = (contextInput) => ({
24-
type: types.DELETE_CONTEXT,
25-
payload: contextInput
26-
});
23+
// export const deleteContext = (contextInput) => ({
24+
// type: types.DELETE_CONTEXT,
25+
// payload: contextInput
26+
// });
2727

28-
export const getAllContext = () => ({
29-
type: types.GET_ALL_CONTEXT
30-
});
28+
// export const getAllContext = () => ({
29+
// type: types.GET_ALL_CONTEXT
30+
// });
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// save all action as constants here
22
// export const DARK_MODE_TOGGLE = 'DARK_MODE_TOGGLE';
3-
export const CODE_PREVIEW_SAVE = 'CODE_PREVIEW_SAVE';
4-
export const CODE_PREVIEW_INPUT = 'CODE_PREVIEW_INPUT';
5-
export const ADD_CONTEXT = 'ADD_CONTEXT';
6-
export const ADD_CONTEXT_VALUES = 'ADD_CONTEXT_VALUES';
7-
export const ADD_COMPONENT_TO_CONTEXT = 'ADD_COMPONENT_TO_CONTEXT';
8-
export const DELETE_CONTEXT = 'DELETE_CONTEXT';
9-
export const GET_ALL_CONTEXT = 'GET_ALL_CONTEXT';
3+
// export const CODE_PREVIEW_SAVE = 'CODE_PREVIEW_SAVE';
4+
// export const CODE_PREVIEW_INPUT = 'CODE_PREVIEW_INPUT';
5+
// export const ADD_CONTEXT = 'ADD_CONTEXT';
6+
// export const ADD_CONTEXT_VALUES = 'ADD_CONTEXT_VALUES';
7+
// export const ADD_COMPONENT_TO_CONTEXT = 'ADD_COMPONENT_TO_CONTEXT';
8+
// export const DELETE_CONTEXT = 'DELETE_CONTEXT';
9+
// export const GET_ALL_CONTEXT = 'GET_ALL_CONTEXT';
Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
1-
import * as types from '../../constants/actionTypes';
1+
import { createSlice } from '@reduxjs/toolkit';
22

33
const initialState = {
44
code: ``,
55
input: ``
66
};
77

8-
const codePreviewReducer = (state = initialState, action) => {
9-
switch (action.type) {
10-
case types.CODE_PREVIEW_SAVE:
11-
return {
12-
...state,
13-
code: action.payload
14-
};
15-
case types.CODE_PREVIEW_INPUT:
16-
return {
17-
...state,
18-
input: action.payload
19-
};
20-
default:
21-
return state;
8+
const codePreviewSlice = createSlice({
9+
name: 'codePreview',
10+
initialState,
11+
reducers: {
12+
codePreviewSave: (state,action) => {
13+
state.code = action.payload
14+
},
15+
codePreviewInput: (state, action) => {
16+
state.input = action.payload
17+
}
2218
}
23-
};
19+
})
20+
21+
22+
export const { codePreviewSave, codePreviewInput } = codePreviewSlice.actions;
23+
24+
export default codePreviewSlice.reducer;
25+
// import * as types from '../../constants/actionTypes';
26+
27+
// const initialState = {
28+
// code: ``,
29+
// input: ``
30+
// };
31+
32+
// const codePreviewReducer = (state = initialState, action) => {
33+
// switch (action.type) {
34+
// case types.CODE_PREVIEW_SAVE:
35+
// return {
36+
// ...state,
37+
// code: action.payload
38+
// };
39+
// case types.CODE_PREVIEW_INPUT:
40+
// return {
41+
// ...state,
42+
// input: action.payload
43+
// };
44+
// default:
45+
// return state;
46+
// }
47+
// };
2448

25-
export default codePreviewReducer;
49+
// export default codePreviewReducer;

0 commit comments

Comments
 (0)