Commit 993bbc41 authored by NaduniRanasinghe's avatar NaduniRanasinghe

modified post page

parent 7f06949d
...@@ -6883,8 +6883,7 @@ ...@@ -6883,8 +6883,7 @@
}, },
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
...@@ -6921,8 +6920,7 @@ ...@@ -6921,8 +6920,7 @@
}, },
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
...@@ -6931,8 +6929,7 @@ ...@@ -6931,8 +6929,7 @@
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -7035,8 +7032,7 @@ ...@@ -7035,8 +7032,7 @@
}, },
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -7046,7 +7042,6 @@ ...@@ -7046,7 +7042,6 @@
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -7059,20 +7054,17 @@ ...@@ -7059,20 +7054,17 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -7089,7 +7081,6 @@ ...@@ -7089,7 +7081,6 @@
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -7162,8 +7153,7 @@ ...@@ -7162,8 +7153,7 @@
}, },
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -7173,7 +7163,6 @@ ...@@ -7173,7 +7163,6 @@
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -7249,8 +7238,7 @@ ...@@ -7249,8 +7238,7 @@
}, },
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
...@@ -7280,7 +7268,6 @@ ...@@ -7280,7 +7268,6 @@
"string-width": { "string-width": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -7298,7 +7285,6 @@ ...@@ -7298,7 +7285,6 @@
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
...@@ -7337,13 +7323,11 @@ ...@@ -7337,13 +7323,11 @@
}, },
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.3", "version": "3.0.3",
"bundled": true, "bundled": true
"optional": true
} }
} }
} }
......
import React, { Component } from 'react' import React, { Component } from 'react'
import axios from 'axios'
import constant from '../service/constant';
class CreatePost extends Component { class CreatePost extends Component {
...@@ -7,16 +9,108 @@ class CreatePost extends Component { ...@@ -7,16 +9,108 @@ class CreatePost extends Component {
super(pros) super(pros)
this.state = { this.state = {
title:'',
content:'',
image:'',
courses:[],
course:'',
} }
} }
changeHandler = (e) => {
const state = this.state
state[e.target.name] = e.target.value;
this.setState(state)
}
userTypeHandler = (e) => {
const state = this.state
state[e.target.name] = e.target.value;
this.setState(state)
}
componentDidMount() {
axios.get(constant()+'/courses').then(
data => {
this.setState({
courses: data.data,
course:data.data[0].id //get first object id from courses list and set status to defult course
})
}
).catch(error => {
console.log(error)
})
}
submitHandler = (e) => {
e.preventDefault()
console.log(this.state)
axios.post(constant()+'/save/post', this.state)
.then(response => {
console.log(response)
if(response.data !== ''){
alert(`Post added successfully`);
this.props.history.push("/createpost")
}
})
.catch(error => {
console.log(error)
})
}
SubmitButtonHandler = () => {
this.props.history.push("/createpost")
}
render(){ render(){
return( const { title,image, content,course} = this.state;
return (
<div className="container"> <div className="container">
<h2>New Post Page</h2> <div className="panel panel-default">
<div className="panel-heading">
<h3 className="panel-title">
Create New Post
</h3>
</div>
<div className="panel-body">
<form onSubmit={this.submitHandler}>
<div className="form-group">
<label>Title:</label>
<input type='text' id="title" className="form-control" name="title" value={title} onChange={this.changeHandler} placeholder="Title" pattern="^[a-zA-Z0-9_]+$" title="Title is required"/>
</div>
<div className="form-group">
<label>Content:</label>
<textarea className="form-control" name="content" value={content} onChange={this.changeHandler} placeholder="Content" />
</div>
<div className="form-group">
<label>Image:</label>
<input type='text' className="form-control" name="image" value={image} onChange={this.changeHandler} placeholder="Image" />
</div>
<div className="form-group">
<label>Course:</label>
<select className="form-control" name="course" onChange={this.changeHandler} value={course}>
{
this.state.courses.map(sub => {
return (
<option key={sub.id} value={sub.id}>{sub.cname}</option>
)
})
}
</select>
</div>
<button type="button" className="btn btn-outline-secondary loginBtn" onClick={this.SubmitButtonHandler}>Submit</button>
</form>
</div>
</div>
</div> </div>
) );
} }
} }
......
...@@ -9,6 +9,7 @@ import Register from './components/Register'; ...@@ -9,6 +9,7 @@ import Register from './components/Register';
import Login from './components/Login'; import Login from './components/Login';
import Student from './components/Student'; import Student from './components/Student';
import Lecturer from './components/Lecturer'; import Lecturer from './components/Lecturer';
import CreatePost from './components/CreatePost';
ReactDOM.render( ReactDOM.render(
<Router> <Router>
...@@ -18,7 +19,8 @@ ReactDOM.render( ...@@ -18,7 +19,8 @@ ReactDOM.render(
<a className="navbar-brand " href="#"><h4 className="navBarTitle">E-Learning Platform</h4></a> <a className="navbar-brand " href="#"><h4 className="navBarTitle">E-Learning Platform</h4></a>
</nav> </nav>
<br/> <br/>
<Route exact path='/' component={Login} /> <Route exact path='/' component={CreatePost} />
{/* <Route exact path='/' component={Login} /> */}
<Route path='/Register' component={Register} /> <Route path='/Register' component={Register} />
<Route path='/App' component={App} /> <Route path='/App' component={App} />
<Route path='/Student' component={Student} /> <Route path='/Student' component={Student} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment