Commit 993bbc41 authored by NaduniRanasinghe's avatar NaduniRanasinghe

modified post page

parent 7f06949d
......@@ -6883,8 +6883,7 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"aproba": {
"version": "1.2.0",
......@@ -6921,8 +6920,7 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"concat-map": {
"version": "0.0.1",
......@@ -6931,8 +6929,7 @@
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -7035,8 +7032,7 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"optional": true
"bundled": true
},
"ini": {
"version": "1.3.5",
......@@ -7046,7 +7042,6 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -7059,20 +7054,17 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true,
"optional": true
"bundled": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -7089,7 +7081,6 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -7162,8 +7153,7 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"optional": true
"bundled": true
},
"object-assign": {
"version": "4.1.1",
......@@ -7173,7 +7163,6 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -7249,8 +7238,7 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"optional": true
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
......@@ -7280,7 +7268,6 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -7298,7 +7285,6 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......@@ -7337,13 +7323,11 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"optional": true
"bundled": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"optional": true
"bundled": true
}
}
}
......
import React, { Component } from 'react'
import axios from 'axios'
import constant from '../service/constant';
class CreatePost extends Component {
......@@ -7,16 +9,108 @@ class CreatePost extends Component {
super(pros)
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(){
return(
const { title,image, content,course} = this.state;
return (
<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>
);
}
}
......
......@@ -9,6 +9,7 @@ import Register from './components/Register';
import Login from './components/Login';
import Student from './components/Student';
import Lecturer from './components/Lecturer';
import CreatePost from './components/CreatePost';
ReactDOM.render(
<Router>
......@@ -18,7 +19,8 @@ ReactDOM.render(
<a className="navbar-brand " href="#"><h4 className="navBarTitle">E-Learning Platform</h4></a>
</nav>
<br/>
<Route exact path='/' component={Login} />
<Route exact path='/' component={CreatePost} />
{/* <Route exact path='/' component={Login} /> */}
<Route path='/Register' component={Register} />
<Route path='/App' component={App} />
<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