Skip to content

Commit 8bc0bbf

Browse files
authored
Merge pull request #5 from oslabs-beta/c2
2 parents 745370f + 3979fc6 commit 8bc0bbf

File tree

4 files changed

+127
-3
lines changed

4 files changed

+127
-3
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, {useRef, useState, useContext, useEffect } from 'react';
2+
import Modal from '@material-ui/core/Modal';
3+
import StateContext from '../../context/context';
4+
import TableStateProps from '../right/TableStateProps';
5+
6+
// TODO: typescript interface or type check
7+
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
8+
const [open, setOpen] = useState(false);
9+
10+
// TODO: choose state source
11+
const componentProviderId = 1; // for now set to App
12+
13+
// selectHandler function to pass into TableStateProps
14+
// get id of selected component
15+
// access the ChildElement
16+
17+
// return the selected state's ID back so the value of it can be updated in the customizationpanel. to the assign the value of selected state to attribute tied to useState button (currently just text)
18+
// attribute to change as parameter for UseStateModal
19+
const body = (
20+
<div className="useState-position">
21+
<div className="useState-header">
22+
<span>Choose State Source</span>
23+
<button
24+
style={{ padding: '1px', float: 'right' }}
25+
onClick={() => setOpen(false)}
26+
>
27+
X
28+
</button>
29+
</div>
30+
<div className="useState-window">
31+
<div className="useState-dropdown">
32+
<button>Choose Stateful Component</button>
33+
<div>
34+
<a href="#">component 1</a>
35+
<a href="#">component 2</a>
36+
</div>
37+
</div>
38+
<div className="useState-stateDisplay">
39+
<TableStateProps
40+
selectHandler={(table) => {
41+
console.log('table.row.id',table.row.id);
42+
updateAttributeWithState(attributeToChange, componentProviderId, table.row.id)
43+
}}
44+
deleteHandler={() => func()}
45+
isThemeLight={true}
46+
/>
47+
</div>
48+
</div>
49+
</div>
50+
);
51+
52+
return (
53+
<div>
54+
<button onClick={() => setOpen(true)}>Use State</button>
55+
<Modal open={open}>{body}</Modal>
56+
</div>
57+
);
58+
}
59+
60+
export default UseStateModal;

app/src/containers/CustomizationPanel.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ProjectManager from '../components/right/ProjectManager';
2929
import StateContext from '../context/context';
3030
import FormSelector from '../components/form/Selector';
3131
import { config } from 'ace-builds';
32+
import UseStateModal from '../components/bottom/UseStateModal';
3233
// Previously named rightContainer, Renamed to Customizationpanel this now hangs on BottomTabs
3334
// need to pass in props to use the useHistory feature of react router
3435
const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
@@ -203,6 +204,22 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
203204
return isLinked;
204205
};
205206

207+
// function to pass into UseStateModal to use state to update attribute
208+
const updateAttributeWithState = (attributeName, componentProviderId, statePropsId) => {
209+
210+
// get the stateProps of the componentProvider
211+
const currentComponent = state.components[componentProviderId - 1];
212+
const currentComponentProps = currentComponent.stateProps;
213+
const newInput = currentComponentProps[statePropsId - 1].value;
214+
215+
if (attributeName === 'compText') setCompText(newInput);
216+
if (attributeName === 'compLink') setCompLink(newInput);
217+
218+
// TODO: set something to signify that state was used
219+
// so it can be handled in generateCode
220+
221+
}
222+
206223
// dispatch to 'UPDATE CSS' called when save button is clicked,
207224
// passing in style object constructed from all changed input values
208225
const handleSave = (): Object => {
@@ -298,7 +315,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
298315
key={'not delete'}
299316
button
300317
onClick={closeModal}
301-
ƒ
302318
style={{
303319
border: '1px solid #3f51b5',
304320
marginBottom: '2%',
@@ -517,7 +533,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
517533
</div>
518534
</div>
519535
<div>
520-
521536
<div className={classes.configRow}>
522537
<div
523538
className={
@@ -545,6 +560,12 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
545560
/>
546561
</FormControl>
547562
</div>
563+
<div>
564+
<UseStateModal
565+
updateAttributeWithState={updateAttributeWithState}
566+
attributeToChange="compText"
567+
childId={state.canvasFocus.childId}/>
568+
</div>
548569
</div>
549570
<div className={classes.configRow}>
550571
<div
@@ -573,6 +594,11 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
573594
/>
574595
</FormControl>
575596
</div>
597+
<div>
598+
<UseStateModal
599+
updateAttributeWithState={updateAttributeWithState} attributeToChange="compLink"
600+
childId={state.canvasFocus.childId}/>
601+
</div>
576602
</div>
577603
<div className={classes.configRow}>
578604
<div

app/src/interfaces/Interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface Component {
3636
isPage: boolean;
3737
past: any[];
3838
future: any[];
39-
stateProps: StateProp[]; // state: [ { key: value, type }, {key: value, type}, {key: value, type} ]
39+
stateProps: StateProp[]; // state: [ { id, key, value, type }, ...]
4040
annotations?: string;
4141
useStateCodes: string[];
4242
}

app/src/public/styles/style.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,41 @@ a.nav_link:hover {
608608
right: 30px ;
609609
z-index: 999;
610610
}
611+
612+
/* UseStateModal Styling */
613+
614+
.useState-position {
615+
display: flex;
616+
flex-direction: column;
617+
position: fixed;
618+
align-items:flex-start;
619+
top: 30%;
620+
left: 30%;
621+
622+
}
623+
624+
.useState-header {
625+
font-size: 35px;
626+
background-color: #003366;
627+
color: rgb(241, 240, 240);
628+
width: 600px;
629+
border: 3px;
630+
border-style: solid;
631+
border-color: black;
632+
font-family: 'Open Sans', sans-serif;
633+
border-radius: 15px 15px 0px 0px;
634+
}
635+
636+
.useState-window {
637+
width: 600px;
638+
height: 300px;
639+
resize: none;
640+
white-space: pre-line;
641+
font-size: 18px;
642+
border: 3px;
643+
border-style: solid;
644+
border-color: black;
645+
border-radius: 0px 0px 15px 15px;
646+
font-family: Arial, Helvetica, sans-serif;
647+
background-color: rgb(241, 240, 240);;
648+
}

0 commit comments

Comments
 (0)