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

Andrew's favourites #39

Merged
merged 3 commits into from
Oct 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/recipes.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ <h2><a href="planner.html">Planner</a></h2>
<h2><a href="app.html">Home</a></h2>
<h2><a href="#!">Recipes</a></h2>
</nav>
<div class="andrews-recipes">
<button onclick="getAndrews()">Show Top picks for Andrew!</button>
<div id="andrews-recipe-container">
</div>
</div>
<div class="recipes">
<div class="save-recipes">
<button onclick="getSaved()">Show saved Recipes</button>
Expand Down
17 changes: 17 additions & 0 deletions assets/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ function getSaved(){
}
}

function getAndrews(){
try {
const jsonRecipes = GetAndrews();
const recipes = JSON.parse(jsonRecipes);
console.log("Recipes:", recipes);
document.getElementById('andrews-recipe-container').innerHTML = "";

for (let recipe of recipes) {
displayCard(recipe, 'andrews-recipe-container');
}
} catch (error) {
console.error("Error fetching recipes:", error);
alert("Failed to fetch recipes. Please try again later.");
}
}


function getFeatured(){
try {
const jsonRecipes = ShowFeatured();
Expand Down
23 changes: 23 additions & 0 deletions src/MyApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,28 @@ JSValue MyApp::GetSaved(const JSObject &thisObject, const JSArgs &args)
return JSValue(jsonRecipes.c_str());
}

JSValue MyApp::GetAndrews(const JSObject &thisObject, const JSArgs &args)
{
std::cout << "Get saved called" << std::endl;
std::vector<int> andrewsList;
andrewsList.push_back(496252);
andrewsList.push_back(537453);
andrewsList.push_back(537034);
andrewsList.push_back(540717);
std::vector<Recipe> returnAndrews;
// std::sort (savedRecipes.begin(), savedRecipes.end());
// savedRecipes.erase(std::unique(savedRecipes.begin(), savedRecipes.end(), savedRecipes.end()));
RecipeDatabase recipeDB;
for (int recipe : andrewsList)
{
// std::cout << recipe << std::endl;
returnAndrews.push_back(recipeDB.getRecipeById(recipe));
}
std::string jsonRecipes = convertRecipesToJson(returnAndrews);

return JSValue(jsonRecipes.c_str());
}

JSValue MyApp::ShowFeatured(const JSObject &thisObject, const JSArgs &args){
std::cout<<"show featured called"<< std::endl;

Expand Down Expand Up @@ -429,6 +451,7 @@ void MyApp::OnDOMReady(ultralight::View *caller,
global["AddToMealPlanner"] = BindJSCallbackWithRetval(&MyApp::AddToMealPlanner);
global["SaveRecipe"] = BindJSCallback(&MyApp::SaveRecipe);
global["GetSaved"] = BindJSCallbackWithRetval(&MyApp::GetSaved);
global["GetAndrews"] = BindJSCallbackWithRetval(&MyApp::GetAndrews);
global["ShowFeatured"] = BindJSCallbackWithRetval(&MyApp::ShowFeatured);
global["GetIngredientsByRecipe"] = BindJSCallbackWithRetval(&MyApp::GetIngredientsByRecipe);
global["GetReviewsByRecipe"] = BindJSCallbackWithRetval(&MyApp::GetReviewsByRecipe);
Expand Down
2 changes: 2 additions & 0 deletions src/MyApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ JSValue AddToMealPlanner(const JSObject& thisObject, const JSArgs& args);

JSValue GetSaved(const JSObject& thisObject, const JSArgs& args);

JSValue GetAndrews(const JSObject& thisObject, const JSArgs& args);

JSValue ShowFeatured(const JSObject& thisObject, const JSArgs& args);

void SaveRecipe(const JSObject& thisObject, const JSArgs& args);
Expand Down
Loading