Concurrency recipe fetcher, adds to list
This commit is contained in:
parent
428309488c
commit
31f220f78c
3 changed files with 24 additions and 8 deletions
|
@ -22,6 +22,9 @@
|
||||||
<HeaderNavLink @href="https://tailwindcss.com/docs/responsive-design">
|
<HeaderNavLink @href="https://tailwindcss.com/docs/responsive-design">
|
||||||
TailwindCSS
|
TailwindCSS
|
||||||
</HeaderNavLink>
|
</HeaderNavLink>
|
||||||
|
<HeaderNavLink @href="https://www.themealdb.com/">
|
||||||
|
TheMealDB
|
||||||
|
</HeaderNavLink>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="https://gitlab.com/gaiety/sortable-recipes" class="inline-block text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-teal-500 hover:bg-white mt-4 md:mt-0">
|
<a href="https://gitlab.com/gaiety/sortable-recipes" class="inline-block text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-teal-500 hover:bg-white mt-4 md:mt-0">
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
<button
|
||||||
|
{{on "click" this.addRecipe}}
|
||||||
|
class="bg-blue-500 hover:bg-blue-400 text-white font-bold py-2 px-4 border-b-4 border-blue-700 hover:border-blue-500 rounded">
|
||||||
|
Button
|
||||||
|
</button>
|
||||||
|
|
||||||
<SortableGroup
|
<SortableGroup
|
||||||
@model={{this.items}}
|
@model={{this.items}}
|
||||||
@onChange={{action this.reorderItems}}
|
@onChange={{action this.reorderItems}}
|
||||||
|
@ -8,7 +14,7 @@
|
||||||
as |item|>
|
as |item|>
|
||||||
<item.handle>
|
<item.handle>
|
||||||
<span class="handle">↕</span>
|
<span class="handle">↕</span>
|
||||||
{{modelItem.name}}
|
{{modelItem.strMeal}}
|
||||||
</item.handle>
|
</item.handle>
|
||||||
</group.item>
|
</group.item>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -2,18 +2,25 @@ import Component from '@glimmer/component';
|
||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { A } from '@ember/array';
|
import { A } from '@ember/array';
|
||||||
|
import { task } from 'ember-concurrency';
|
||||||
|
|
||||||
export default class RecipeListComponent extends Component {
|
export default class RecipeListComponent extends Component {
|
||||||
@tracked items = A([
|
@tracked items = A([]);
|
||||||
{
|
|
||||||
name: 'foo',
|
@(task(function * () {
|
||||||
}, {
|
let response = yield fetch('https://www.themealdb.com/api/json/v1/1/random.php');
|
||||||
name: 'bar',
|
response = yield response.json();
|
||||||
},
|
return response.meals[0];
|
||||||
]);
|
})) fetchRecipe;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
reorderItems(reorderedItems) {
|
reorderItems(reorderedItems) {
|
||||||
this.items = reorderedItems;
|
this.items = reorderedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
async addRecipe() {
|
||||||
|
let recipe = await this.fetchRecipe.perform();
|
||||||
|
this.items.pushObject(recipe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue