Skip to content

Commit

Permalink
completed some of update
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyrm committed Mar 8, 2020
1 parent b5f877f commit a8b8b3d
Show file tree
Hide file tree
Showing 18 changed files with 6,475 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
350 changes: 348 additions & 2 deletions client/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<div id='app'>
<h1>Loading</h1>
</div>

<script> src="/bundle.js" </script>
</body>
</html>
17 changes: 12 additions & 5 deletions client/src/components/Add.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import Axios from 'axios';


export default class Add extends React.Component {
Expand All @@ -13,22 +14,28 @@ export default class Add extends React.Component {
}

changeHandler(e){

let {name, value} = e.target
this.setState({
[name]: value
})
}

handleSubmit(e){

e.preventDefault();
Axios.post('/api/students', this.state)
.then(() => {console.log('success')})
.catch((err) => {console.error(err)})
}

render() {
return (
<div>
<form>
<label>Student Name: </label>
<input type="text" name="name" />
<input type="text" name="name" onChange={this.changeHandler}/>
<label>Image URL: </label>
<input type="text" name="imgurl" />
<button type="submit" value="Submit">Submit</button>
<input type="text" name="imgurl" value={this.state.name} onChange={this.changeHandler}/>
<button type="submit" value="Submit" onClick={this.handleSubmit}>Submit</button>
</form>
</div>
)
Expand Down
41 changes: 27 additions & 14 deletions client/src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';




import Axios from 'axios';
import Random from './Random.jsx';
import List from './Add.jsx';
import Add from './List.jsx';

export default class App extends React.Component {
constructor(props){
Expand All @@ -11,20 +11,33 @@ export default class App extends React.Component {
'page': 'home',
'studentlist' : []
}


this.getStudents = this.getStudents.bind(this);
this.changepage = this.changepage.bind(this);
}

componentDidMount(){
componentDidMount() {
this.getStudents()
}

getStudents(){

Axios.get('/api/students')
.then((students) => {
this.setState({
studentlist: students.data
}, () => {console.log(this.state)})
})
.catch((err) => {
console.error(err)
})
}

changepage(e){

if (e.target.value === 'home') {
this.getStudents();
}
this.setState({
page: e.target.value
}, () => {console.log(this.state.page)})
}

render() {
Expand All @@ -38,23 +51,23 @@ export default class App extends React.Component {
} else if (this.state.page === 'list'){
return (
<div>
<List />
<List students={this.state.studentList} getStudents={this.getStudents}/>
<button value='home' onClick={(e) => this.changepage(e)}>Back</button>
</div>
)
} else if (this.state.page === 'random'){
return (
<div>
<Random />
<Random students={this.state.students}/>
<button value='home' onClick={(e) => this.changepage(e)}>Back</button>
</div>
)
} else {
return (
<div>
<button value='add' >Add Student</button>
<button value='list' >List Students</button>
<button value='random' >Random Student</button>
<button value='add' onCLick={this.changepage}>Add Student</button>
<button value='list' onCLick={this.changepage}>List Students</button>
<button value='random' onCLick={this.changepage}>Random Student</button>
</div>
)
}
Expand Down
25 changes: 3 additions & 22 deletions client/src/components/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,9 @@ import ListElement from './ListElement.jsx';

const List = (props) =>
<div>
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
<ListElement />
{props.getStudents.map((student, index) => (
<ListElement student={student} key={index} getStudents={}/>
))}
</div>


Expand Down
74 changes: 68 additions & 6 deletions client/src/components/ListElement.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,72 @@
import React from 'react';
import axios from 'axios';
import Axios from 'axios';

const ListElement = () =>
<span>
<div>Evelyn</div>
<img src='https://ca.slack-edge.com/T2SV1LBC6-URC6Z49K9-0731cf8087a9-512'></img>
</span>
// const ListElement = (props) =>
// <span>
// <div>{props.student.name}</div>
// <img src={props.student.imgurl}></img>
// </span>

export default ListElement extends React.Component {
constructor(props) {
super(props);
this.state = {
updateName: false,
studentId: 0,
studentName: this.props.student.name
}
this.updateStudent = this.updateStudent.bind(this);
this.clickHandler = this.clickHandler.bind(this);
this.changeHandler = this.changeHandler.bind(this);
this.submitHandler = this.submitHandler.bind(this);
}

export default ListElement
updateStudent() {
Axios.put(`/api/students/${id}`, {
name: this.state.studentName
})
.then(() => {
this.props.getStudent()
})
.catch((err) => {
console.error(err);
})
}

clickHandler(id) {
this.setState({
updateName: true,
studentId: id
})
}

changeHandler() {
this.setState({
studentName: e.target.value
})
}

submitHandler() {
e.preventDefault();
this.setState({
updateName: false
}, () => {
this.updateStudent(this.state.students)
})
}

render() {
return(
this.state.updateName ?
<span>
<input onChange={this.changeHandler} value={this.state.studentName}></input>
<button onClick={this.submitHandler}>Change Name</button>
<div>src={this.props.student.imgurl}</div>
</span> :
<span>
<div onClick={() => this.clickHandler}>{this.props.student.name}</div>
<img src={this.props.student.imgurl}></img>
</span>
}
}
15 changes: 10 additions & 5 deletions client/src/components/Random.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ export default class Random extends React.Component {
this.getRandomStudent = this.getRandomStudent.bind(this);
}


componentDidMount() {

}

getRandomStudent(){

let index = Math.floor(Math.random() * this.props.students.length)
this.setState({
student: this.props.students[index]
}, () => {console.log(this.state)})
}

render() {
return (
<div>
<div>
<img src='https://ca.slack-edge.com/T2SV1LBC6-UT9N1BX1A-c2a4df2e7442-512'></img>
<h1>Lee</h1>
<img src={this.state.student.imgurl}></img>
<h1>{this.state.student.name}</h1>
</div>
<button >Randomize</button>
<button onClick={this.getRandomStudent}>Randomize</button>
</div>
)
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './components/App.jsx';

// render your App component to your HTML
ReactDOM.render(<App />, document.getElementById('app'));
7 changes: 4 additions & 3 deletions db/dbhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ var db = require('./');
module.exports = {
students: {
// fetch all students
getStudent: () => {},
//find all
getStudent: () => db.find({}),
// add a student
postName: (student) => {},
postName: (student) => db.create(student),
// update a student's name
updateName: (_id, name) => {},
updateName: (_id, name) => db.findOneAndUpdate(_id, name)
}
};
4 changes: 3 additions & 1 deletion db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var db = mongoose.connect(mongoURI)
.then(()=>{console.log('connected to mongoDB')});

// specify your model "Student" here
//made for mongodb; instance of what the collection would look like
var Student = mongoose.model('Students', studentSchema)

// export your model
module.exports = Student;
module.exports = Student;

Loading

0 comments on commit a8b8b3d

Please sign in to comment.