Created
May 28, 2017 00:12
-
-
Save patientplatypus/c0f56e5f0de4c3e4dcec0ba2ef0fab89 to your computer and use it in GitHub Desktop.
unexpected token on function inside react class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import DayPicker from 'react-day-picker'; | |
import 'react-day-picker/lib/style.css' | |
import axios from 'axios'; | |
import ListGoal from './ListGoal'; | |
// const birthdays = { | |
// 3: [{ name: 'Mirko', age: 35 }, { name: 'Gianluca', age: 29 }], | |
// 8: [{ name: 'Elena', age: 21 }], | |
// 9: [{ name: 'Irene', age: 43 }], | |
// 12: [{ name: 'Paolo', age: 78 }, { name: 'Giorgia', age: 18 }], | |
// 18: [{ name: 'Claudia', age: 54 }], | |
// 22: [{ name: 'Maria', age: 9 }, { name: 'Luigi', age: 67 }], | |
// 25: [{ name: 'Simone', age: 31 }], | |
// 26: [{ name: 'Marta', age: 46 }], | |
// }; | |
const displayInfo = ()=>{ | |
axios.post('http://localhost:5000/calendar/alldateinfo') | |
.then((response)=>{ | |
var arryAll = []; | |
var tempObj = {}; | |
response.data.forEach((goal)=>{ | |
tempObj = {}; | |
tempObj.date = goal.dateDue; | |
tempObj.name = goal.name; | |
arryAll.push(tempObj); | |
}); | |
return(arryAll); | |
// self.setState({ | |
// allDays: arryAll | |
// }); | |
}); | |
} | |
// function renderDay(day) { | |
// const date = day.getDate(); | |
// console.log('the value of day (localdatestring) is, ', day.toLocaleDateString()); | |
// return ( | |
// <div> | |
// {date} | |
// <div className="Birthdays-List"> | |
// {birthdays[date] && | |
// birthdays[date].map((birthday, i) => ( | |
// <div key={i}> | |
// π {birthday.name} ({birthday.age}) | |
// </div> | |
// ))} | |
// </div> | |
// </div> | |
// ); | |
// } | |
// function renderDay(day) { | |
// const date = day.toLocaleDateString(); | |
// const dateDisplay = day.getDate(); | |
// // console.log('the value of day (localdatestring) is, ', day.toLocaleDateString()); | |
// console.log("value of displayInfo is, ", displayInfo); | |
// return ( | |
// <div> | |
// {dateDisplay} | |
// <div className="Info-List"> | |
// {displayInfo[date] && | |
// displayInfo[date].map((displayInfo, i) => ( | |
// <div key={i}> | |
// π {displayInfo.name} ({displayInfo.dateDue}) | |
// </div> | |
// ))} | |
// </div> | |
// </div> | |
// ); | |
// } | |
class CalendarPage extends Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
selectedDay: null, | |
allDays: [], | |
puppies: "puppies", | |
goalsToday: "nogoals", | |
// haveGoalsToday: false | |
} | |
} | |
componentWillMount() { | |
var self = this; | |
axios.post('http://localhost:5000/calendar/alldateinfo') | |
.then((response)=>{ | |
var arryAll = []; | |
var tempObj = {}; | |
response.data.forEach((goal)=>{ | |
tempObj = {}; | |
tempObj.date = goal.dateDue; | |
tempObj.name = goal.name; | |
arryAll.push(tempObj); | |
}); | |
self.setState({ | |
allDays: arryAll | |
}); | |
}); | |
} | |
function renderDay(day) { | |
const date = day.toLocaleDateString(); | |
const dateDisplay = day.getDate(); | |
// console.log('the value of day (localdatestring) is, ', day.toLocaleDateString()); | |
console.log("value of displayInfo is, ", displayInfo); | |
return ( | |
<div> | |
{dateDisplay} | |
<div className="Info-List"> | |
{displayInfo[date] && | |
displayInfo[date].map((displayInfo, i) => ( | |
<div key={i}> | |
π {displayInfo.name} ({displayInfo.dateDue}) | |
</div> | |
))} | |
</div> | |
</div> | |
); | |
} | |
handleDayClick = (day, { selected }) => { | |
const self = this; | |
var promise = new Promise((resolve)=>{ | |
self.setState({ | |
selectedDay: selected ? undefined : day | |
}, ()=>resolve()); | |
}); | |
promise.then((resolve)=>{ | |
console.log('this.state.selectedDay ', self.state.selectedDay); | |
if (this.state.selectedDay!=undefined){ | |
axios.post('http://localhost:5000/calendar/specificdateinfo',{ | |
datequery: self.state.selectedDay.toLocaleDateString() | |
}) | |
.then((response)=>{ | |
console.log("all the date info is ", response); | |
if(response.data.length>0){ | |
self.setState({ | |
goalsToday: response | |
}); | |
}else{ | |
self.setState({ | |
goalsToday: "nogoals" | |
}); | |
} | |
}); | |
}else{ | |
self.setState({ | |
goalsToday: "nogoals" | |
}); | |
} | |
}); | |
} | |
render() { | |
let listGoals; | |
// var self = this; | |
// const { haveGoalsToday } = false; | |
if(this.state.goalsToday!="nogoals"){ | |
console.log("this.state.goalsToday if is (first condition)", this.state.goalsToday); | |
listGoals = this.state.goalsToday.data.map(goal => { | |
return ( | |
<ListGoal key={goal._id} goal={goal} /> | |
); | |
}); | |
} | |
if(this.state.goalsToday==="nogoals"){ | |
console.log("this.state.goalsToday if is (second condition)", this.state.goalsToday); | |
listGoals = <div className="GoalsDue"><p>You have nothing due today!</p></div> | |
} | |
const { selectedDay } = this.state; | |
return ( | |
<div> | |
<div className='calendarContainer'> | |
<div className='calendar'> | |
<DayPicker | |
selectedDays={selectedDay} | |
numberOfMonths={2} | |
fixedWeeks | |
className="Birthdays" | |
renderDay={renderDay} | |
onDayClick={this.handleDayClick} | |
/> | |
</div> | |
</div> | |
<div className='calendarDetail'> | |
<p> | |
{selectedDay | |
? selectedDay.toLocaleDateString() | |
: 'Please select a day'} | |
</p> | |
</div> | |
<div className="goalsList"> | |
{listGoals} | |
</div> | |
</div> | |
); | |
} | |
} | |
export default CalendarPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment