Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove second calendar #20

Merged
merged 2 commits into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -6,9 +6,11 @@
"axios": "^0.19.0",
"node-sass": "^4.12.0",
"react": "^16.8.6",
"react-date-picker": "^7.5.1",
"react-datetime-picker": "^2.4.0",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
"react-scripts": "3.0.1",
"react-time-picker": "^3.5.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
31 changes: 17 additions & 14 deletions src/App.js
Expand Up @@ -13,8 +13,9 @@ class App extends Component {
super();
this.state = {
data: [],
dateTimeStart: new Date(),
dateTimeEnd: new Date(),
timeStart: "00:00",
timeEnd: "00:00",
date: new Date(),
location: "",
displayResult: false,
// eventsJSX: "",
Expand All @@ -29,10 +30,9 @@ class App extends Component {

//handle change function
handleChange = (event, name) => {
console.log(event);
// when console.log event, our location gets the object but for dateTimePicker we get the actual value
// if the item onChange has (name) tsParameterProperty, do the following
if(name) {
if (name) {
this.setState({
[name]: event
})
Expand All @@ -45,10 +45,11 @@ class App extends Component {
}


//time input format localStartEndDateTime=2019-06-05T17:00:00,2019-06-05T20:00:00
//time input format localStartEndDateTime=2019-06-05T17:00:00,2019-06-05T20:00:00
onSubmit = (e) => {
e.preventDefault();
if (this.state.dateTimeStart && this.state.dateTimeEnd &&this.state.location) {
if (this.state.timeStart && this.state.timeEnd && this.state.location &&
Date.parse(`01/01/2011 ${this.state.timeEnd}:00`) > Date.parse(`01/01/2011 ${this.state.timeStart}:00`)) {
this.setState({
displayResult: true,
})
Expand All @@ -58,19 +59,21 @@ class App extends Component {
return (
<div className="App">
<Header />
<SearchForm
dateTimeStart={this.state.dateTimeStart}
dateTimeEnd={this.state.dateTimeEnd}
<SearchForm
timeStart={this.state.timeStart}
timeEnd={this.state.timeEnd}
date={this.state.date}
handleChange={this.handleChange}
onSubmit={this.onSubmit}
location={this.state.location}
/>
{this.state.displayResult &&
<DisplayResults
dateTimeStart={this.state.dateTimeStart}
dateTimeEnd={this.state.dateTimeEnd}
location={this.state.location}
/>
<DisplayResults
date={this.state.date}
timeStart={this.state.timeStart}
timeEnd={this.state.timeEnd}
location={this.state.location}
/>
}
<EmailForm />
{/* <EmailSent /> */}
Expand Down
36 changes: 17 additions & 19 deletions src/components/DisplayResults.js
Expand Up @@ -11,7 +11,7 @@ class DisplayResults extends Component{
}
}
// converting time function to string so it can be passed as a number in template literals
formatDate = (dateObject) => {
formatDate = (dateObject, time) => {
let year = dateObject.getFullYear();
let month = dateObject.getMonth() + 1;
if (month < 10) {
Expand All @@ -21,24 +21,23 @@ class DisplayResults extends Component{
if (day < 10) {
day = '0' + day;
}
let hours = dateObject.getHours();
if (hours < 10) {
hours = '0' + hours;
}
let minutes = dateObject.getMinutes();
if (minutes < 10) {
minutes = '0' + minutes;
}
let hours = time.substr(0,2);
console.log(hours);
let minutes = time.substr(3, 5);
console.log(minutes);
let dateString = `${year}-${month}-${day}T${hours}:${minutes}:00`;
return dateString
}

//time input format localStartEndDateTime=2019-06-05T17:00:00,2019-06-05T20:00:00
getTicketmasterData = (city, startDate, endDate) => {

getTicketmasterData = (location, startDate, endDate) => {
console.log('parameters that go to the API Call')
console.log("location: ", location)
console.log("Start Date: ",startDate);
console.log("End Date: ",endDate);
axios({
method: "GET",
url: `https://app.ticketmaster.com/discovery/v2/events.json?apikey=cpqJuV2A3YqkXOJylkTrDzVGLRKZ5hp5&city=${city}&localStartEndDateTime=${startDate},${endDate}`,
url: `https://app.ticketmaster.com/discovery/v2/events.json?apikey=cpqJuV2A3YqkXOJylkTrDzVGLRKZ5hp5&city=${location}&localStartEndDateTime=${startDate},${endDate}`,
dataResponse: "jsonp",
}).then((response) => {
// console.log(response);
Expand All @@ -52,22 +51,21 @@ class DisplayResults extends Component{
})
}
componentDidMount(){
let dateStart = this.formatDate(this.props.dateTimeStart);
let dateEnd = this.formatDate(this.props.dateTimeEnd);
let date = this.props.date;
let timeStart = this.props.timeStart;
let timeEnd = this.props.timeEnd;
let startDateTime = this.formatDate(date, timeStart);
let endDateTime = this.formatDate(date, timeEnd);
let location = this.props.location;
this.getTicketmasterData(location, dateStart, dateEnd);
this.getTicketmasterData(location, startDateTime, endDateTime);
}
render(){
return(
this.state.isLoading ? <h1>Getting Your Events...</h1>:

<div className="display-events">
<div className="display-content">

{/* errorhandling here : write a condition if city name is found in API, do below. else "Please enter a valid city name and date/time range*/}



{this.state.data.map((eventObject) => {
return (
<ResultCard
Expand Down
69 changes: 45 additions & 24 deletions src/components/SearchForm.js
@@ -1,9 +1,30 @@
import React, { Component } from 'react';
import DatePicker from 'react-date-picker';
import TimePicker from 'react-time-picker'
import DateTimePicker from 'react-datetime-picker';

class SearchForm extends Component{
//error handling function. if startTime is "10:00", make sure the endTime is atleast "11:00"
addOneHourToTime = (time) => {
let hour = parseInt(this.props.timeStart.substr(0,2),10)
if (hour >= 23){
hour = "00"
}
else{
hour = hour+1;
if (hour<10){
hour = `0`+hour;
}
}
let minute=parseInt(this.props.timeStart.substr(3,5),10);
if (minute<10){
minute = `0`+ minute;
}

let newTime=`${hour}:${minute}`;
return newTime


}

render(){
return (
Expand All @@ -22,34 +43,34 @@ class SearchForm extends Component{
value={this.props.location}/>
</div>
<div>
<label htmlFor="">Datetime Range Start</label>
<DateTimePicker

// "dateTimeStart" is [name] and event returns the value for dateTimePicker
onChange={(event, name)=> {this.props.handleChange(event, "dateTimeStart")}}


<label htmlFor="">Date</label>
<DatePicker
onChange={(event, name)=> {this.props.handleChange(event, "date")}}
required={true}
format="y-MM-dd HH:mm"

// name="dateTimeStart"

// value is so this item will SHOW on screen
value={this.props.dateTimeStart}
format="y-MM-dd"
name="date"
value={this.props.date}
/>
</div>
<div>
<label htmlFor="time">Datetime Range End</label>
<DateTimePicker

onChange={(event, name)=> {this.props.handleChange(event, "dateTimeEnd")}}

<label htmlFor="time">Time Range Start</label>
<TimePicker
onChange={(event, name)=> {this.props.handleChange(event, "timeStart")}}
required={true}
format="y-MM-dd HH:mm"
// name="dateTimeEnd"


value={this.props.dateTimeEnd}
format="HH:mm"
name="timeStart"
value={this.props.timeStart}
/>
</div>
<div>
<label htmlFor="time">Time Range End</label>
<TimePicker
onChange={(event, name)=> {this.props.handleChange(event, "timeEnd")}}
required={true}
format="HH:mm"
name="timeEnd"
value={this.props.timeEnd}
minTime={this.addOneHourToTime(this.props.timeStart)}
/>
</div>
<button
Expand Down