Skip to content

Commit

Permalink
some other change
Browse files Browse the repository at this point in the history
  • Loading branch information
jw20191n committed Dec 4, 2019
1 parent e916a1b commit 847f2ce
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 113 deletions.
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import Login from './components/Login';
import SignUp from './components/SignUp';
import AdminPage from './components/AdminPage';
import StudentPage from './components/StudentPage';
import StudentProfile from './components/studentProfile';
import StudentProfile from './components/StudentProfile';
import StudentHistory from './components/StudentHistory';
import CreateLesson from './components/CreateLesson';
import Lessons from './components/Lessons';
import Canvas from './components/Canvas';
Expand Down Expand Up @@ -43,6 +44,7 @@ class App extends React.Component {
<Route exact path='/signup' render={(routerProps) => <SignUp {...routerProps} setCurrentUser={this.setCurrentUser}/> } />
<Route exact path='/student' render={(routerProps) => <StudentPage currentUser={this.state.currentUser} {...routerProps} setCurrentUser={this.setCurrentUser} /> } />
<Route exact path='/stdprofile' render={(routerProps) => <StudentProfile currentUser={this.state.currentUser} {...routerProps} /> } />
<Route exact path='/stdhistory' render={(routerProps) => <StudentHistory currentUser={this.state.currentUser} {...routerProps} /> } />
<Route exact path='/admin' render={() => <AdminPage currentUser={this.state.currentUser}/> } />
<Route exact path='/createlesson' render={(routerProps) => <CreateLesson currentUser={this.state.currentUser} {...routerProps}/> } />
<Route exact path='/lessons' render={(routerProps) => <Lessons currentUser={this.state.currentUser} {...routerProps}/> } />
Expand Down
4 changes: 2 additions & 2 deletions src/components/AdminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class AdminPage extends Component {
<div >
<h1>Welcome, {this.props.currentUser.username}!</h1>
<ul className='admin-btn-list'>
{/* <li className='admin-page-btn'><NavLink to="/createlesson" exact>Create Lesson</NavLink></li>
<li className='admin-page-btn'><NavLink to="/lessons" exact >All Lessons</NavLink></li> */}
<li className='admin-page-btn'><NavLink to="/createlesson" exact>Create Lesson</NavLink></li>
<li className='admin-page-btn'><NavLink to="/lessons" exact >All Lessons</NavLink></li>
</ul>
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions src/components/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class Chat extends Component {
}

componentDidUpdate(){
// console.log()

}

handleChange = (event) => {
Expand Down Expand Up @@ -82,15 +82,15 @@ export default class Chat extends Component {


sendGuessright = (data) => {

console.log('in here');
if(data.user === this.props.currentUser){
let foundWord = {};

fetch('http://localhost:3001/words')
.then(resp => resp.json())
.then(resp => {
foundWord = resp.find(obj => obj.text === data.word )
// console.log(foundWord.text);
console.log(foundWord.text);
fetch('http://localhost:3001/guessrights',{
method: "POST",
headers:{
Expand Down
50 changes: 19 additions & 31 deletions src/components/CreateLesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React, { Component } from 'react';

export default class CreateLesson extends Component {
state={
name: "",
passcode: "",
description: ""
name: ""
}

handleChange = (event) => {
Expand All @@ -16,26 +14,24 @@ export default class CreateLesson extends Component {
handleSubmit = (event) => {
event.preventDefault();

// if(this.props.currentUser){
// fetch('http://localhost:3001/lessons',{
// method: "POST",
// headers:{
// "Content-Type": "application/json",
// "Accept": "application/json"
// },
// body: JSON.stringify({
// name: this.state.name,
// passcode: this.state.passcode,
// description: this.state.description,
// admin_id: this.props.currentUser.id,
// })
// }).then(resp => resp.json())
// .then(data => {
// console.log(data);
// this.props.history.push('/admin');
// alert('you successfully created the class!')
// })
// }
if(this.props.currentUser){
fetch('http://localhost:3001/lessons',{
method: "POST",
headers:{
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
name: this.state.name,
admin_id: this.props.currentUser.id
})
}).then(resp => resp.json())
.then(data => {
console.log(data);
this.props.history.push('/admin');
alert('you successfully created the class!')
})
}
}

render() {
Expand All @@ -47,14 +43,6 @@ export default class CreateLesson extends Component {
<label>Class Name</label>
<input type="text" name="name" placeholder="class name" onChange={this.handleChange} value={this.state.name}/>
</li>
<li>
<label>Passcode</label>
<input type="text" name="passcode" placeholder="class passcode" onChange={this.handleChange} value={this.state.passcode}/>
</li>
<li>
<label>Class Description</label>
<input type="text" name="description" placeholder="class description" onChange={this.handleChange} value={this.state.description}/>
</li>
<li>
<input type="submit" value="submit" className="submit-btn" />
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Game extends Component {
}
}else if(data.game_status){
console.log('game ended');
setTimeout(()=>{ this.props.history.push('/stdprofile') },5000)
setTimeout(()=>{ this.props.history.push('/stdhistory') },5000)
socket.disconnect();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/LessonDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default class LessonDetail extends Component {

componentDidUpdate(){
this.printWords();
console.log(this.state.words);
}


handleChange = (event) => {
console.log(event.target.value);
this.setState({
[event.target.name]:event.target.value
})
Expand Down Expand Up @@ -61,13 +61,13 @@ export default class LessonDetail extends Component {
})
}).then(resp => resp.json())
.then(data => {
console.log(data);
this.setState({
words: [...this.state.words, this.state.word]
words: [...this.state.words, data]
})
})
}


render() {

return(
Expand Down
7 changes: 0 additions & 7 deletions src/components/Lessons.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default class CreateLesson extends Component {
return(
<div className="card" key={i}>
<p>Name: {lesson.name}</p>
<p>Passcode: {lesson.passcode}</p>
<p>Description: {lesson.description}</p>
{/* <button type="button" className="btn btn-secondary" onClick={()=>this.openDetail(lesson.id)}>detail</button> */}
<LessonDetail id={lesson.id}/>
</div>
Expand All @@ -47,11 +45,6 @@ export default class CreateLesson extends Component {
return(<div>You have no lessons, please create one</div>)
}
}

// openDetail = (id) => {
// console.log(id);
// return <LessonDetail id={id}/>
// }

render() {
return(
Expand Down
85 changes: 85 additions & 0 deletions src/components/StudentHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { Component } from 'react';
// import io from 'socket.io-client';

// let socket;

export default class StudentHistory extends Component {

state={
words: [],
right: [],
wrong: []
}

componentDidMount(){
this.fetchLessonWords();
}

componentDidUpdate(){
// console.log(this.state.words);
console.log(this.state.right, this.state.wrong);
}

fetchLessonWords = () => {
if(this.props.currentUser){
fetch('http://localhost:3001/words')
.then(resp => resp.json())
.then(data => {
let wordsArray = data.filter(word => word.lesson_id === this.props.currentUser.lesson_id)
this.setState({
words: wordsArray
})
this.fetchGuessedWords();
})
}
}

fetchGuessedWords = () => {

fetch('http://localhost:3001/guessrights')
.then(resp => resp.json())
.then(data => {
let rightWords = data.filter(word => word.student_id === this.props.currentUser.id);
rightWords = rightWords.filter(word => word.lesson_id === this.props.currentUser.lesson_id);
let right = [];
rightWords.forEach(wordObj=>{
this.state.words.forEach(word=>{
if(wordObj.id === word.id){
right.push(word.text);
}
})
})
let allWords = this.state.words.map(word => word.text);
console.log('all', allWords);
let wrongWords = [];
allWords.forEach(word=>{
if(!right.includes(word)){
wrongWords.push(word);
}
})
this.setState({
right: right,
wrong: wrongWords
})
})

}

printWrongWords = () => {
let div = document.getElementsByClassName('history-inner')[0];
this.state.wrongWords.forEach(word => {
div.innerText += `<p>${word}</p>`
})
}

render() {
return(
<div className="std-history">
Study List:
<div className="history-inner">
</div>
</div>
)

}
}
68 changes: 3 additions & 65 deletions src/components/studentProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,17 @@ import React, { Component } from 'react';

export default class StudentProfile extends Component {

state={
words: [],
right: [],
wrong: []
}

componentDidMount(){
this.fetchLessonWords();
}

componentDidUpdate(){
console.log(this.state.words);
console.log(this.state.right, this.state.wrong);
}

fetchLessonWords = () => {
if(this.props.currentUser){
fetch('http://localhost:3001/words')
.then(resp => resp.json())
.then(data => {
let wordsArray = data.filter(word => word.lesson_id === this.props.currentUser.lesson_id)
this.setState({
words: wordsArray
})
this.fetchGuessedWords();
})
}
}

fetchGuessedWords = () => {

fetch('http://localhost:3001/guessrights')
.then(resp => resp.json())
.then(data => {
let rightWords = data.filter(word => word.student_id === this.props.currentUser.id);
rightWords = rightWords.filter(word => word.lesson_id === this.props.currentUser.lesson_id);
let right = [];
rightWords.forEach(wordObj=>{
this.state.words.forEach(word=>{
if(wordObj.id === word.id){
right.push(word.text);
}
})
})
let allWords = this.state.words.map(word => word.text);
console.log('all', allWords);
let wrongWords = [];
allWords.forEach(word=>{
if(!right.includes(word)){
wrongWords.push(word);
}
})
this.setState({
right: right,
wrong: wrongWords
})
})

}
componentDidMount(){

printWrongWords = () => {
let div = document.getElementsByClassName('profile-inner')[0];
this.state.wrongWords.forEach(word => {
div.innerText += `<p>${word}</p>`
})
}


render() {
return(
<div className="std-profile">
Study List:
<div className="profile-inner">
</div>

</div>
)

Expand Down

0 comments on commit 847f2ce

Please sign in to comment.