Skip to content

Commit

Permalink
Push for testing merge of updated JavaScript with updated styling
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrissgailey committed Jan 30, 2021
1 parent e7c8e59 commit 46c8050
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 138 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
</div>
<br>

<form id="search-btn" class="hide">
<form id="search-term" class="hide">
<h2>Where are you?</h2>
<input type="text" id="search-term" name="city">
<button>go</button>
<input type="text" id="search-input" name="city">
<button id="search-btn">Go</button>
</form>
<div id="questions-page" class="hide">
<h1 id="question"></h1>
Expand Down
189 changes: 69 additions & 120 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ var currentQuestion = 0;
var questions;
var totalQuestions;
var answers = [];
var grabInput;
var startScreen = document.getElementById("start-screen");
var searchTerm = document.getElementById("search-term");
var searchInput = document.getElementById("search-input");
var searchBtn = document.getElementById("search-btn");
var questionsPage = document.getElementById("questions-page");
var eatHomeBtn = document.getElementById("eat-home-btn");
var eatHome;
var eatOut;
var eatOutBtn = document.getElementById("eat-out-btn");
var nextButton = document.getElementById("next-button");

Expand Down Expand Up @@ -56,7 +60,7 @@ nextButton.addEventListener("click", function (event) {
} else {
if (eatHome === true) {
callRecipeAPI();
} else {
} else if (eatOut === true) {
callRestaurantAPI();
}
// Hide questionsPage and show resultsPage
Expand All @@ -77,19 +81,23 @@ eatHomeBtn.addEventListener("click", function () {
});
// Eat Out button, load restaurant questions, hide start screen and show questions page
eatOutBtn.addEventListener("click", function () {
// var eatHome = false;
eatOut = true;

startScreen.setAttribute("class", "hide");
searchBtn.setAttribute("class", "show")
searchTerm.setAttribute("class", "show")
});

searchBtn.addEventListener("click", function () {
searchBtn.addEventListener("click", function (event) {
event.preventDefault();
console.log(searchBtn);
searchInput = document.querySelector('#search-input').value.trim()
console.log(searchInput);
questions = restaurantQuestions;
totalQuestions = questions.length;
getQuestions(currentQuestion, questions);
questionsPage.setAttribute("class", "show");
searchBtn.setAttribute("class", "hide");
})
searchTerm.setAttribute("class", "hide");
});

// Gets recipe data from the spoonacular API
function callRecipeAPI() {
Expand Down Expand Up @@ -142,121 +150,62 @@ function callRecipeAPI() {
function callRestaurantAPI() {
console.log("hello");



// document.querySelector('#search').addEventListener('submit', function (event) {
// event.preventDefault()
// var searchTerm = document.querySelector('#search-term').value.trim()
// console.log(searchTerm);
// // var key = "0494ac0d19d3768669eba3cb4cc8a747";
// // var city = "Salt Lake City";

// var queryURL = "https://developers.zomato.com/api/v2.1/locations?query=" + searchTerm;

// $.ajax({
// url: queryURL,
// method: "GET",
// headers: {
// "user-key": "0494ac0d19d3768669eba3cb4cc8a747",
// "content-type": "application/json",
// }
// }).then(function (cityInfo) {
// console.log(queryURL);
// console.log(cityInfo);


// console.log(cityInfo.location_suggestions[0].latitude);
// console.log(cityInfo.location_suggestions[0].longitude);
// console.log(cityInfo.location_suggestions[0].entity_id);
// console.log(cityInfo.location_suggestions[0].entity_type);

// var cityId = cityInfo.location_suggestions[0].entity_id;
// var cityType = cityInfo.location_suggestions[0].entity_type;

// var restURL1 = "https://developers.zomato.com/api/v2.1/location_details?entity_id=" + cityId + "&entity_type=" + cityType;

// $.ajax({
// url: restURL1,
// method: "GET",
// headers: {
// "user-key": "0494ac0d19d3768669eba3cb4cc8a747",
// "content-type": "application/json",
// }
// }).then(function (restaurantAPI1) {
// console.log(restaurantAPI1);
// console.log(restaurantAPI1.best_rated_restaurant[0].restaurant.photos_url);

// var restImg = $("<img>");
// restImg.attr("src", restaurantAPI1.best_rated_restaurant[0].restaurant.photos_url);
// $("#imgTest").append(restImg)

// })

// var latitude = cityInfo.location_suggestions[0].latitude;
// var longitude = cityInfo.location_suggestions[0].longitude;

// var restURL2 = "https://developers.zomato.com/api/v2.1/search?lat=" + latitude + "&lon=" + longitude;

// $.ajax({
// url: restURL2,
// method: "GET",
// headers: {
// "user-key": "0494ac0d19d3768669eba3cb4cc8a747",
// "content-type": "application/json",
// }
// }).then(function (restaurantAPI2) {
// console.log(restaurantAPI2);
// })
var meal = answers[0];
// var meal = "chicken";
var cuisine = answers[1];
var dessert = answers[2];
var diet = answers[3];
var alcohol = answers[4];
var cookingTools = answers[5];

// document.querySelector('#search-btn').addEventListener('submit', function (event) {
// event.preventDefault()

// searchInput = document.querySelector('#search-input').value.trim()
// console.log(searchInput);

// })

// })



// // These variables will need to change based on the user's response but for now I hard coded them in
// var meal = answers[0];
// // var meal = "chicken";
// var cuisine = answers[1];
// var dessert = answers[2];
// var diet = answers[3];
// var alcohol = answers[4];
// var cookingTools = answers[5];
// console.log(meal);
// console.log(cuisine);
// console.log(dessert);
// console.log(diet);
// console.log(alcohol);
// console.log(cookingTools);

// spoonacular URL
// var APIkey = "b76df6aa9f3f42a2850529cba2ce87ae";
// var APIkey = "674f6fda78664e8d8eb605383a63dc97"; //This is a second APIKey if we have too many calls
// var queryURL = "https://api.spoonacular.com/recipes/complexSearch?query=" + meal + "&cuisine=" + cuisine + "&number=1&addRecipeInformation=true&addRecipeNutrition=true&apiKey=" + APIkey;

// AJAX call spoonacular API
// $.ajax({
// url: queryURL,
// method: "GET"
// }).then(function(response) {

// // Log the queryURL and response
// console.log(queryURL);
// console.log(response);
var queryURL = "https://developers.zomato.com/api/v2.1/locations?query=" + searchInput;
console.log(queryURL);

// Below is an example of displaying to the results page. It will need to be modified according to our results page
$.ajax({
url: queryURL,
method: "GET",
headers: {
"user-key": "0494ac0d19d3768669eba3cb4cc8a747",
"content-type": "application/json",
}
}).then(function (cityInfo) {
// console.log(queryURL);

// $(".recipe-title1").text(response.results[0].title);
// $(".recipe-image1").attr("src",response.results[0].image);
// $(".cook-time1").text("Time: " + response.results[0].readyInMinutes + " minutes");
// $(".servings1").text("Servings: " + response.results[0].servings);
// $(".calories1").text("Calories: " + response.results[0].nutrition.nutrients[0].amount + " cal");
// $(".carbs1").text("Carbohydrates: " + response.results[0].nutrition.nutrients[3].amount + " g");
// $(".protein1").text("Protein: " + response.results[0].nutrition.nutrients[8].amount + " g");
// $(".fat1").text("Fat: " + response.results[0].nutrition.nutrients[1].amount + " g");
// $(".recipe-url1").text("Recipe Link")
// $(".recipe-url1").attr("href",response.results[0].sourceUrl)
// var recipeId = response.results[0].id;
// })
}

console.log(cityInfo.location_suggestions[0].latitude);
console.log(cityInfo.location_suggestions[0].longitude);
console.log(cityInfo.location_suggestions[0].entity_id);
console.log(cityInfo.location_suggestions[0].entity_type);

var cityId = cityInfo.location_suggestions[0].entity_id;
var cityType = cityInfo.location_suggestions[0].entity_type;


var latitude = cityInfo.location_suggestions[0].latitude;
var longitude = cityInfo.location_suggestions[0].longitude;

var restURL2 = "https://developers.zomato.com/api/v2.1/search?lat=" + latitude + "&lon=" + longitude + "&cuisines=" + cuisine;

$.ajax({
url: restURL2,
method: "GET",
headers: {
"user-key": "0494ac0d19d3768669eba3cb4cc8a747",
"content-type": "application/json",
}
}).then(function (restaurantAPI2) {
console.log(restaurantAPI2);
console.log(restaurantAPI2.restaurants[0].restaurant.highlights)
})


})

// })
}
35 changes: 20 additions & 15 deletions questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ var homeQuestions= [

var restaurantQuestions= [
{
questionText: "R What meal is it?",
choices: ["R Breakfast", "Lunch", "Dinner", "Brunch", "Hangover"]
questionText: "What meal is it?",
choices: ["Breakfast", "Lunch", "Dinner", "Brunch"]
},

{
questionText: "R Which type of food are you hungry for?",
choices: ["R American", "Italian",],
questionText: "Which type of food are you hungry for?",
choices: ["American", "Italian", "Mexican"],

},

{
questionText: "R Do you have a sugar craving? Would you like a desert?",
choices: ["R Yes", "No"],
questionText: "What is your price range?",
choices: ["1", "2", "3", "4", "5"],

},

{
questionText: "R Are you on a diet?",
choices: ["R Yes", "No",],
},
// {
// questionText: "R Do you have a sugar craving? Would you like a desert?",
// choices: ["R Yes", "No"],
// },

{
questionText: "R Do you want to get drunk",
choices: ["R Yes", "No", "Maybe"],
},
// {
// questionText: "R Are you on a diet?",
// choices: ["R Yes", "No",],
// },

// {
// questionText: "R Do you want to get drunk",
// choices: ["R Yes", "No", "Maybe"],
// },
];

0 comments on commit 46c8050

Please sign in to comment.