1
0
Fork 0

Fixed sorting/adding bug

This commit is contained in:
Ava Gaiety Wroten 2019-12-22 12:35:58 -06:00
parent 793f8ba79a
commit a57ca025f5
3 changed files with 15 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<div class="rounded-md shadow-md">
<SortableGroup
@model={{this.items}}
@onChange={{action this.reorderItems}}
@model={{this.sortedItems}}
@onChange={{action this.reorderMeals}}
as |group|>
{{#each group.model as |meal|}}
<group.item

View file

@ -13,13 +13,23 @@ export default class RecipeListComponent extends Component {
this.assignExistingItems();
}
get sortedItems() {
console.log('sorted items called');
return this.items.sortBy('listOrder');
}
async assignExistingItems() {
let items = await this.store.peekAll('meal');
this.items = items;
}
@action
reorderItems(reorderedItems) {
this.items = reorderedItems;
async reorderMeals(reorderedMeals) {
let orderedIds = reorderedMeals.map(meal => meal.id);
for (let index = 0; index < orderedIds.length; index++) {
let meal = await this.store.peekRecord('meal', orderedIds[index]);
meal.listOrder = index;
}
}
}

View file

@ -11,4 +11,5 @@ export default class MealModel extends Model {
@attr tags;
@attr youtube;
@attr source;
@attr('number', { defaultValue: Infinity }) listOrder;
}