Skip to content

Commit 904f870

Browse files
Bianca PicassoBianca Picasso
authored andcommitted
add data to redux form
Co-authored-by: Sal Saluga [email protected] Co-authored-by: Ken Bains [email protected] Co-authored-by: Huy Pham [email protected]
1 parent 600582e commit 904f870

File tree

3 files changed

+64
-24
lines changed

3 files changed

+64
-24
lines changed

app/src/components/ContextAPIManager/CreatorComponent/ContextCreator.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { Typography } from '@material-ui/core';
2-
import React from 'react';
2+
import React, {useEffect, useState } from 'react';
33
import { useStore } from 'react-redux'
44

55
import CreatorForm from './CreatorForm';
66

77
const ContextCreator = () => {
88
const store = useStore();
9-
console.log(store.getState())
9+
const [state, setState] = useState([]);
10+
11+
useEffect(() => {
12+
setState(store.getState().contextSlice)
13+
}, [])
1014
return (
1115
<>
12-
<CreatorForm />
16+
<CreatorForm contextStore={state}/>
1317
</>
1418
)
1519
};

app/src/components/ContextAPIManager/CreatorComponent/CreatorForm.tsx

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//context stored in an object
2-
//it will have another object within to hold the key value pairs
2+
//it will have another object within to hold the key contextInput pairs
33

4-
import React, { Fragment } from 'react';
4+
import React, { Fragment, useState, useEffect } from 'react';
5+
import { useDispatch } from 'react-redux'
56
import TextField from '@mui/material/TextField';
67
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
78
import Button from '@mui/material/Button';
@@ -13,6 +14,7 @@ import TableRow from '@mui/material/TableRow';
1314
import Paper from '@mui/material/Paper';
1415
import { styled } from '@mui/material/styles';
1516
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
17+
import Box from '@mui/material/Box';
1618

1719
import ContextTable from './ContextTable';
1820

@@ -22,23 +24,23 @@ const filter = createFilterOptions();
2224
const contextArr = [
2325
{
2426
name : 'theme',
25-
values: [
26-
{key: 'dark', value: 'black'},
27-
{key: 'light', value: 'white'},
28-
{key: 'darker', value: 'darkest'}
27+
contextInputs: [
28+
{key: 'dark', contextInput: 'black'},
29+
{key: 'light', contextInput: 'white'}
2930
]
3031

3132
},
3233

3334
{
3435
name : 'mood',
35-
values : [
36-
{key: 'happy', value: 'rainbow'},
37-
{key: 'sad', value: 'blue'},
36+
contextInputs : [
37+
{key: 'happy', contextInput: 'rainbow'},
38+
{key: 'sad', contextInput: 'blue'},
3839
]
3940
}
4041
]
4142

43+
//START - Table styling
4244
const StyledTableCell = styled(TableCell)(({ theme }) => ({
4345
[`&.${tableCellClasses.head}`]: {
4446
backgroundColor: theme.palette.common.black,
@@ -58,34 +60,55 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
5860
border: 0
5961
}
6062
}));
63+
//END - table styling
64+
65+
66+
67+
const CreatorForm = ({contextStore}) => {
68+
// const [contextInput, setContextInput] = useState('');
69+
70+
//array storing all contexts
71+
const {allContext} = contextStore
72+
73+
const [contextInput, setContextInput] = React.useState(null);
74+
75+
76+
const dispatch = useDispatch()
77+
78+
const handleClickSelectContext = () => {
79+
console.log(document.getElementById("autoCompleteContextField"))
80+
console.log('COMING FROM CLICK EVENT', contextInput);
81+
82+
// dispatch({type: })
83+
}
6184

62-
const CreatorForm = () => {
63-
// const arr = [1,2,3,4]
64-
const [value, setValue] = React.useState(null);
6585

6686
return (
6787
<Fragment>
88+
<Box
89+
sx={{ display: 'flex'}} >
6890
<Autocomplete
69-
value={value}
91+
id="autoCompleteContextField"
92+
value={contextInput}
7093
onChange={(event, newValue) => {
7194
if (typeof newValue === 'string') {
72-
setValue({
95+
setContextInput({
7396
name: newValue,
7497
});
7598
} else if (newValue && newValue.inputValue) {
76-
// Create a new value from the user input
77-
setValue({
99+
// Create a new contextInput from the user input
100+
setContextInput({
78101
name: newValue.inputValue,
79102
});
80103
} else {
81-
setValue(newValue);
104+
setContextInput(newValue);
82105
}
83106
}}
84107
filterOptions={(options, params) => {
85108
const filtered = filter(options, params);
86109

87110
const { inputValue } = params;
88-
// Suggest the creation of a new value
111+
// Suggest the creation of a new contextInput
89112
const isExisting = options.some((option) => inputValue === option.name);
90113
if (inputValue !== '' && !isExisting) {
91114
filtered.push({
@@ -100,7 +123,7 @@ const CreatorForm = () => {
100123
clearOnBlur
101124
handleHomeEndKeys
102125
id="free-solo-with-text-demo"
103-
options={contextArr}
126+
options={allContext || []}
104127
getOptionLabel={(option) => {
105128
// Value selected with enter, right from the input
106129
if (typeof option === 'string') {
@@ -120,7 +143,11 @@ const CreatorForm = () => {
120143
<TextField {...params} label="Free solo with text demo" />
121144
)}
122145
/>
123-
<ContextTable target={contextArr[0].values}/>
146+
<Button variant="contained" onClick={handleClickSelectContext}>Select/Create</Button>
147+
{/* <Button variant="contained">Delete</Button> */}
148+
</Box>
149+
<ContextTable target={contextArr[0].contextInputs}/>
150+
124151
</Fragment>
125152
);
126153
}

app/src/redux/reducers/slice/contextReducer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import * as types from '../../constants/actionTypes';
22

33
const initialState = {
4-
allContext: []
4+
allContext: [
5+
{
6+
name: "MainContext1",
7+
values: [{key : "testKey1", value: 'testValue1'}, {key: "testKey2", value: "testValue2"}]
8+
},
9+
{
10+
name: "MainContext3",
11+
values: [{key : "testKey3", value: 'testValue3'}, {key: "testKey33", value: "testValue33"}]
12+
}
13+
]
514
}
615

716
const contextReducer = (state = initialState, action) => {

0 commit comments

Comments
 (0)