mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Delete To-do items in a batched single request (#18662)
This commit is contained in:
parent
a909c6d905
commit
244868348b
@ -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 }
|
||||
);
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user