|
1 |
| -import React, { Component } from 'react'; |
| 1 | +import React, { Component, useState } from 'react'; |
2 | 2 | import { connect } from 'react-redux';
|
3 | 3 | import { withStyles, Theme } from '@material-ui/core/styles';
|
4 | 4 | import HtmlAttr from '../components/bottom/HtmlAttr';
|
5 | 5 | import { PropsInt, ApplicationStateInt } from '../interfaces/Interfaces';
|
6 |
| -import Button from '@material-ui/core/Button'; |
| 6 | +import { Button, TextField } from '@material-ui/core'; |
7 | 7 | import { Link as RouteLink, withRouter } from 'react-router-dom';
|
8 | 8 |
|
9 | 9 | // const mapDispatchToProps = (dispatch: any) => ({
|
@@ -33,95 +33,101 @@ interface BottomTabsPropsInt extends PropsInt {
|
33 | 33 | codeReadOnly: boolean;
|
34 | 34 | }
|
35 | 35 |
|
36 |
| -class RightContainer extends Component<BottomTabsPropsInt> { |
37 |
| - constructor(props: BottomTabsPropsInt) { |
38 |
| - super(props); |
39 |
| - } |
| 36 | +function saveProject(project: ApplicationStateInt, name: String) { |
| 37 | + console.log('Saving project to DB...'); |
| 38 | + const body = JSON.stringify({ name, project }); |
| 39 | + console.log('Project name is', name); |
| 40 | + fetch('https://localhost:8080/saveProject', { |
| 41 | + method: 'POST', |
| 42 | + headers: { |
| 43 | + 'content-type': 'application/json' |
| 44 | + }, |
| 45 | + credentials: 'include', |
| 46 | + body |
| 47 | + }) |
| 48 | + .then(res => res.json()) |
| 49 | + .then(data => console.log('Saved project is', data)) |
| 50 | + .catch(err => console.log(err)); |
| 51 | +} |
| 52 | + |
| 53 | +function getProjects() { |
| 54 | + console.log("Loading user's projects..."); |
| 55 | + fetch('https://localhost:8080/getProjects', { |
| 56 | + credentials: 'include' |
| 57 | + }) |
| 58 | + .then(res => res.json()) |
| 59 | + .then(data => console.log("User's projects are", data)) |
| 60 | + .catch(err => console.log(err)); |
| 61 | +} |
| 62 | +const RightContainer = (props: BottomTabsPropsInt) => { |
| 63 | + const { classes, components, focusComponent, focusChild } = props; |
| 64 | + // looks through the children of currently focused component (based on left bar) and finds the number of child html elements it has |
| 65 | + const htmlAttribCount = focusComponent.childrenArray.filter( |
| 66 | + child => child.childType === 'HTML' |
| 67 | + ).length; |
40 | 68 |
|
41 |
| - saveProject(project: ApplicationStateInt) { |
42 |
| - console.log('Saving project to DB...'); |
43 |
| - const body = JSON.stringify(project); |
44 |
| - fetch('https://localhost:8080/saveProject', { |
45 |
| - method: 'POST', |
46 |
| - headers: { |
47 |
| - 'content-type': 'application/json' |
48 |
| - }, |
49 |
| - credentials: 'include', |
50 |
| - body |
51 |
| - }) |
52 |
| - .then(res => res.json()) |
53 |
| - .then(data => console.log('Saved project is', data)) |
54 |
| - .catch(err => console.log(err)); |
55 |
| - } |
| 69 | + const [projectName, setProjectName] = useState(''); |
56 | 70 |
|
57 |
| - getProjects() { |
58 |
| - console.log("Loading user's projects..."); |
59 |
| - fetch('https://localhost:8080/getProjects', { |
60 |
| - credentials: 'include' |
61 |
| - }) |
62 |
| - .then(res => res.json()) |
63 |
| - .then(data => console.log("User's projects are", data)) |
64 |
| - .catch(err => console.log(err)); |
65 |
| - } |
| 71 | + const handleChange = e => { |
| 72 | + let newVal = e.target.value; |
| 73 | + setProjectName(newVal); |
| 74 | + }; |
66 | 75 |
|
67 |
| - render(): JSX.Element { |
68 |
| - const { classes, components, focusComponent, focusChild } = this.props; |
69 |
| - // looks through the children of currently focused component (based on left bar) and finds the number of child html elements it has |
70 |
| - const htmlAttribCount = focusComponent.childrenArray.filter( |
71 |
| - child => child.childType === 'HTML' |
72 |
| - ).length; |
| 76 | + return ( |
| 77 | + <div |
| 78 | + className="column right" |
| 79 | + style={{ |
| 80 | + minWidth: '400px', |
| 81 | + color: 'white', |
| 82 | + textAlign: 'center', |
| 83 | + display: 'flex', |
| 84 | + flexDirection: 'column' |
| 85 | + }} |
| 86 | + > |
| 87 | + {/* <h3>This is the right column everyone!</h3> */} |
73 | 88 |
|
74 |
| - return ( |
75 |
| - <div |
76 |
| - className="column right" |
77 |
| - style={{ |
78 |
| - minWidth: '400px', |
79 |
| - color: 'white', |
80 |
| - textAlign: 'center', |
81 |
| - display: 'flex', |
82 |
| - flexDirection: 'column' |
| 89 | + <h4> |
| 90 | + {/* mimic the bottom tab label that shows how many html elements there are */} |
| 91 | + HTML Element Attributes {htmlAttribCount ? `(${htmlAttribCount})` : ''} |
| 92 | + </h4> |
| 93 | + {/* conditional rendering based on which component/element is currently focused */} |
| 94 | + {focusChild.childType === 'HTML' && <HtmlAttr />} |
| 95 | + {focusChild.childType !== 'HTML' && ( |
| 96 | + <p>Please select an HTML element to view attributes</p> |
| 97 | + )} |
| 98 | + |
| 99 | + <TextField |
| 100 | + required |
| 101 | + name="projectName" |
| 102 | + label="projectName" |
| 103 | + value={projectName} |
| 104 | + onChange={handleChange} |
| 105 | + /> |
| 106 | + |
| 107 | + <Button |
| 108 | + variant="contained" |
| 109 | + color="secondary" |
| 110 | + onClick={() => { |
| 111 | + saveProject(props.currentWorkspace, projectName); |
| 112 | + setProjectName(''); |
83 | 113 | }}
|
84 | 114 | >
|
85 |
| - {/* <h3>This is the right column everyone!</h3> */} |
86 |
| - |
87 |
| - <h4> |
88 |
| - {/* mimic the bottom tab label that shows how many html elements there are */} |
89 |
| - HTML Element Attributes{' '} |
90 |
| - {htmlAttribCount ? `(${htmlAttribCount})` : ''} |
91 |
| - </h4> |
92 |
| - {/* conditional rendering based on which component/element is currently focused */} |
93 |
| - {focusChild.childType === 'HTML' && <HtmlAttr />} |
94 |
| - {focusChild.childType !== 'HTML' && ( |
95 |
| - <p>Please select an HTML element to view attributes</p> |
96 |
| - )} |
| 115 | + Save Current Project |
| 116 | + </Button> |
| 117 | + <Button variant="contained" color="secondary" onClick={getProjects}> |
| 118 | + Get My Projects |
| 119 | + </Button> |
| 120 | + <RouteLink to={`/`} style={{ textDecoration: 'none', margin: '5px' }}> |
97 | 121 | <Button
|
98 | 122 | variant="contained"
|
99 | 123 | color="secondary"
|
100 |
| - onClick={() => { |
101 |
| - this.saveProject(this.props.currentWorkspace); |
102 |
| - }} |
| 124 | + style={{ alignSelf: 'bottom' }} |
103 | 125 | >
|
104 |
| - Save Current Project |
| 126 | + Sign Out |
105 | 127 | </Button>
|
106 |
| - <Button |
107 |
| - variant="contained" |
108 |
| - color="secondary" |
109 |
| - onClick={this.getProjects} |
110 |
| - > |
111 |
| - Get My Projects |
112 |
| - </Button> |
113 |
| - <RouteLink to={`/`} style={{ textDecoration: 'none', margin: '5px' }}> |
114 |
| - <Button |
115 |
| - variant="contained" |
116 |
| - color="secondary" |
117 |
| - style={{ alignSelf: 'bottom' }} |
118 |
| - > |
119 |
| - Sign Out |
120 |
| - </Button> |
121 |
| - </RouteLink> |
122 |
| - </div> |
123 |
| - ); |
124 |
| - } |
125 |
| -} |
| 128 | + </RouteLink> |
| 129 | + </div> |
| 130 | + ); |
| 131 | +}; |
126 | 132 |
|
127 | 133 | export default withRouter(connect(mapStateToProps)(RightContainer));
|
0 commit comments