Delete To-do items in a batched single request (#18662)

This commit is contained in:
Allen Porter 2023-11-16 00:52:03 -08:00 committed by GitHub
parent a909c6d905
commit 244868348b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -82,16 +82,16 @@ export const createItem = (
{ entity_id }
);
export const deleteItem = (
export const deleteItems = (
hass: HomeAssistant,
entity_id: string,
uid: string
uids: string[]
): Promise<ServiceCallResponse> =>
hass.callService(
"todo",
"remove_item",
{
item: uid,
item: uids,
},
{ entity_id }
);

View File

@ -35,7 +35,7 @@ import {
TodoItemStatus,
TodoListEntityFeature,
createItem,
deleteItem,
deleteItems,
fetchItems,
moveItem,
updateItem,
@ -433,7 +433,7 @@ export class HuiTodoListCard
} else if (
this.todoListSupportsFeature(TodoListEntityFeature.DELETE_TODO_ITEM)
) {
deleteItem(this.hass!, this._entityId!, ev.target.itemId).finally(() =>
deleteItems(this.hass!, this._entityId!, [ev.target.itemId]).finally(() =>
this._fetchData()
);
}
@ -445,11 +445,11 @@ export class HuiTodoListCard
if (!this.hass) {
return;
}
const deleteActions: Array<Promise<any>> = [];
this._getCheckedItems(this._items).forEach((item: TodoItem) => {
deleteActions.push(deleteItem(this.hass!, this._entityId!, item.uid));
});
await Promise.all(deleteActions).finally(() => this._fetchData());
const checkedItems = this._getCheckedItems(this._items);
const uids = checkedItems.map((item: TodoItem) => item.uid);
deleteItems(this.hass!, this._entityId!, uids).finally(() =>
this._fetchData()
);
}
private get _newItem(): HaTextField {
@ -475,7 +475,7 @@ export class HuiTodoListCard
if (!item) {
return;
}
deleteItem(this.hass!, this._entityId!, item.uid).finally(() =>
deleteItems(this.hass!, this._entityId!, [item.uid]).finally(() =>
this._fetchData()
);
}