1
1
//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
3
3
4
- import React , { Fragment } from 'react' ;
4
+ import React , { Fragment , useState , useEffect } from 'react' ;
5
+ import { useDispatch } from 'react-redux'
5
6
import TextField from '@mui/material/TextField' ;
6
7
import Autocomplete , { createFilterOptions } from '@mui/material/Autocomplete' ;
7
8
import Button from '@mui/material/Button' ;
@@ -13,6 +14,7 @@ import TableRow from '@mui/material/TableRow';
13
14
import Paper from '@mui/material/Paper' ;
14
15
import { styled } from '@mui/material/styles' ;
15
16
import TableCell , { tableCellClasses } from '@mui/material/TableCell' ;
17
+ import Box from '@mui/material/Box' ;
16
18
17
19
import ContextTable from './ContextTable' ;
18
20
@@ -22,23 +24,23 @@ const filter = createFilterOptions();
22
24
const contextArr = [
23
25
{
24
26
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' }
29
30
]
30
31
31
32
} ,
32
33
33
34
{
34
35
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' } ,
38
39
]
39
40
}
40
41
]
41
42
43
+ //START - Table styling
42
44
const StyledTableCell = styled ( TableCell ) ( ( { theme } ) => ( {
43
45
[ `&.${ tableCellClasses . head } ` ] : {
44
46
backgroundColor : theme . palette . common . black ,
@@ -58,34 +60,55 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
58
60
border : 0
59
61
}
60
62
} ) ) ;
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
+ }
61
84
62
- const CreatorForm = ( ) => {
63
- // const arr = [1,2,3,4]
64
- const [ value , setValue ] = React . useState ( null ) ;
65
85
66
86
return (
67
87
< Fragment >
88
+ < Box
89
+ sx = { { display : 'flex' } } >
68
90
< Autocomplete
69
- value = { value }
91
+ id = "autoCompleteContextField"
92
+ value = { contextInput }
70
93
onChange = { ( event , newValue ) => {
71
94
if ( typeof newValue === 'string' ) {
72
- setValue ( {
95
+ setContextInput ( {
73
96
name : newValue ,
74
97
} ) ;
75
98
} 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 ( {
78
101
name : newValue . inputValue ,
79
102
} ) ;
80
103
} else {
81
- setValue ( newValue ) ;
104
+ setContextInput ( newValue ) ;
82
105
}
83
106
} }
84
107
filterOptions = { ( options , params ) => {
85
108
const filtered = filter ( options , params ) ;
86
109
87
110
const { inputValue } = params ;
88
- // Suggest the creation of a new value
111
+ // Suggest the creation of a new contextInput
89
112
const isExisting = options . some ( ( option ) => inputValue === option . name ) ;
90
113
if ( inputValue !== '' && ! isExisting ) {
91
114
filtered . push ( {
@@ -100,7 +123,7 @@ const CreatorForm = () => {
100
123
clearOnBlur
101
124
handleHomeEndKeys
102
125
id = "free-solo-with-text-demo"
103
- options = { contextArr }
126
+ options = { allContext || [ ] }
104
127
getOptionLabel = { ( option ) => {
105
128
// Value selected with enter, right from the input
106
129
if ( typeof option === 'string' ) {
@@ -120,7 +143,11 @@ const CreatorForm = () => {
120
143
< TextField { ...params } label = "Free solo with text demo" />
121
144
) }
122
145
/>
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
+
124
151
</ Fragment >
125
152
) ;
126
153
}
0 commit comments