Skip to content

Commit 4232f35

Browse files
committed
added basic code editor
1 parent 45ffba8 commit 4232f35

File tree

6 files changed

+129
-33
lines changed

6 files changed

+129
-33
lines changed

client/components/CodeEditor.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, { Component } from 'react';
2+
import Draft, { Editor, EditorState} from 'draft-js';
3+
import CodeUtils from 'draft-js-code';
4+
5+
export class CodeEditor extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
editorState: this.props.editorState
10+
};
11+
}
12+
13+
// handleKeyCommand = (command) => {
14+
// const { editorState } = this.state;
15+
// let newState;
16+
17+
// if (CodeUtils.hasSelectionInBlock(editorState)) {
18+
// newState = CodeUtils.handleKeyCommand(editorState, command);
19+
// }
20+
21+
// if (!newState) {
22+
// newState = RichUtils.handleKeyCommand(editorState, command);
23+
// }
24+
25+
// if (newState) {
26+
// this.onChange(newState);
27+
// return 'handled';
28+
// }
29+
// return 'not-handled';
30+
// }
31+
32+
// keyBindingFn = (evt) => {
33+
// const { editorState } = this.state;
34+
// if (!CodeUtils.hasSelectionInBlock(editorState)) return Draft.getDefaultKeyBinding(evt);
35+
36+
// const command = CodeUtils.getKeyBinding(evt);
37+
38+
// return command || Draft.getDefaultKeyBinding(evt);
39+
// }
40+
41+
// handleReturn = (evt) => {
42+
// const { editorState } = this.state;
43+
// if (!CodeUtils.hasSelectionInBlock(editorState)) return 'not-handled';
44+
45+
// this.onChange(CodeUtils.handleReturn(evt, editorState));
46+
// return 'handled';
47+
// }
48+
49+
// onTab = (evt) => {
50+
// const { editorState } = this.state;
51+
// if (!CodeUtils.hasSelectionInBlock(editorState)) return 'not-handled';
52+
53+
// this.onChange(CodeUtils.onTab(evt, editorState));
54+
// return 'handled';
55+
// }
56+
57+
render() {
58+
59+
console.log('WHAT IS THIS', this.state)
60+
61+
return (
62+
<Editor
63+
editorState={this.props.editorState}
64+
onChange={this.props.onChange}
65+
// keyBindingFn={this.keyBindingFn}
66+
// handleKeyCommand={this.handleKeyCommand}
67+
// handleReturn={this.handleReturn}
68+
// onTab={this.onTab}
69+
/>
70+
);
71+
}
72+
}

client/components/main.js

+46-31
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,55 @@
1-
import React from 'react'
1+
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import {connect} from 'react-redux'
44
import {withRouter, Link} from 'react-router-dom'
5+
import { Editor, EditorState} from 'draft-js';
56
import {logout} from '../store'
7+
import AceEditor from 'react-ace'
8+
import brace from 'brace';
9+
import 'brace/mode/javascript';
10+
import 'brace/theme/monokai';
611

7-
/**
8-
* COMPONENT
9-
* The Main component is our 'picture frame' - it displays the navbar and anything
10-
* else common to our entire app. The 'picture' inside the frame is the space
11-
* rendered out by the component's `children`.
12-
*/
13-
const Main = (props) => {
14-
const {children, handleClick, isLoggedIn} = props
12+
class Main extends Component {
13+
constructor(props) {
14+
super(props);
15+
this.onChange = this.onChange.bind(this)
16+
}
17+
18+
onChange = (obj) => {
19+
console.log(obj)
20+
}
21+
22+
render () {
23+
return (
24+
<AceEditor
25+
mode="javascript"
26+
theme="monokai"
27+
height="50em"
28+
onChange={this.onChange}
29+
/>
30+
)
31+
}
1532

16-
return (
17-
<div>
18-
<h1>BOILERMAKER</h1>
19-
<nav>
20-
{
21-
isLoggedIn
22-
? <div>
23-
{/* The navbar will show these links after you log in */}
24-
<Link to="/home">Home</Link>
25-
<a href="#" onClick={handleClick}>Logout</a>
26-
</div>
27-
: <div>
28-
{/* The navbar will show these links before you log in */}
29-
<Link to="/login">Login</Link>
30-
<Link to="/signup">Sign Up</Link>
31-
</div>
32-
}
33-
</nav>
34-
<hr />
35-
{children}
36-
</div>
37-
)
33+
// <div>
34+
// <h1>BOILERMAKER</h1>
35+
// <nav>
36+
// {
37+
// isLoggedIn
38+
// ? <div>
39+
// {/* The navbar will show these links after you log in */}
40+
// <Link to="/home">Home</Link>
41+
// <a href="#" onClick={handleClick}>Logout</a>
42+
// </div>
43+
// : <div>
44+
// {/* The navbar will show these links before you log in */}
45+
// <Link to="/login">Login</Link>
46+
// <Link to="/signup">Sign Up</Link>
47+
// </div>
48+
// }
49+
// </nav>
50+
// <hr />
51+
// {children}
52+
// </div>
3853
}
3954

4055
/**

client/index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ nav a {
1818
form div {
1919
margin: 1em;
2020
display: inline-block;
21-
}
21+
}

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
"dependencies": {
2424
"axios": "^0.15.3",
2525
"body-parser": "^1.16.1",
26+
"brace": "^0.11.0",
2627
"compression": "^1.7.1",
2728
"connect-session-sequelize": "^4.1.0",
2829
"css-loader": "^0.28.8",
30+
"draft-js": "^0.10.4",
31+
"draft-js-code": "^0.3.0",
32+
"draft-js-prism": "^1.0.5",
2933
"express": "^4.14.1",
3034
"express-session": "^1.15.1",
3135
"history": "^4.6.3",
@@ -35,8 +39,10 @@
3539
"passport-google-oauth": "^1.0.0",
3640
"pg": "^6.4.2",
3741
"pg-hstore": "^2.3.2",
42+
"prismjs": "^1.9.0",
3843
"prop-types": "^15.5.8",
3944
"react": "^16.0.0",
45+
"react-ace": "^5.9.0",
4046
"react-dom": "^16.0.0",
4147
"react-redux": "^5.0.2",
4248
"react-router-dom": "^4.1.1",
@@ -63,6 +69,7 @@
6369
"eslint": "^4.10.0",
6470
"eslint-config-fullstack": "^3.0.0",
6571
"eslint-plugin-react": "^7.4.0",
72+
"file-loader": "^1.1.6",
6673
"mocha": "^3.3.0",
6774
"nodemon": "^1.12.1",
6875
"react-test-renderer": "^16.0.0",

public/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<meta name='viewport' content='width=device-width initial-scale=1.0'>
66
<title>Boilermaker</title>
77
<link rel="stylesheet" href="/style.css" />
8+
<link rel="stylesheet" href="/Draft.css" />
9+
<link rel="stylesheet" href="/prism.css" />
810
<script defer src="/bundle.js"></script>
911
</head>
1012
<body>

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
use: [
2525
'style-loader',
2626
'css-loader',
27-
'sass-loader'
27+
'sass-loader',
2828
]
2929
},
3030
{

0 commit comments

Comments
 (0)