From 31f220f78cdf546feecdf1704cf3cdb0bf7c267e Mon Sep 17 00:00:00 2001 From: Ava Gaiety Wroten Date: Sat, 21 Dec 2019 15:51:34 -0600 Subject: [PATCH] Concurrency recipe fetcher, adds to list --- app/components/header-nav.hbs | 3 +++ app/components/recipe-list.hbs | 8 +++++++- app/components/recipe-list.js | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/components/header-nav.hbs b/app/components/header-nav.hbs index 8002534..c050bd4 100644 --- a/app/components/header-nav.hbs +++ b/app/components/header-nav.hbs @@ -22,6 +22,9 @@ TailwindCSS + + TheMealDB +
diff --git a/app/components/recipe-list.hbs b/app/components/recipe-list.hbs index a725546..2986a43 100644 --- a/app/components/recipe-list.hbs +++ b/app/components/recipe-list.hbs @@ -1,3 +1,9 @@ + + - {{modelItem.name}} + {{modelItem.strMeal}} {{/each}} diff --git a/app/components/recipe-list.js b/app/components/recipe-list.js index a702917..0928a38 100644 --- a/app/components/recipe-list.js +++ b/app/components/recipe-list.js @@ -2,18 +2,25 @@ import Component from '@glimmer/component'; import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; import { A } from '@ember/array'; +import { task } from 'ember-concurrency'; export default class RecipeListComponent extends Component { - @tracked items = A([ - { - name: 'foo', - }, { - name: 'bar', - }, - ]); + @tracked items = A([]); + + @(task(function * () { + let response = yield fetch('https://www.themealdb.com/api/json/v1/1/random.php'); + response = yield response.json(); + return response.meals[0]; + })) fetchRecipe; @action reorderItems(reorderedItems) { this.items = reorderedItems; } + + @action + async addRecipe() { + let recipe = await this.fetchRecipe.perform(); + this.items.pushObject(recipe); + } }