mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +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 }
|
{ entity_id }
|
||||||
);
|
);
|
||||||
|
|
||||||
export const deleteItem = (
|
export const deleteItems = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_id: string,
|
entity_id: string,
|
||||||
uid: string
|
uids: string[]
|
||||||
): Promise<ServiceCallResponse> =>
|
): Promise<ServiceCallResponse> =>
|
||||||
hass.callService(
|
hass.callService(
|
||||||
"todo",
|
"todo",
|
||||||
"remove_item",
|
"remove_item",
|
||||||
{
|
{
|
||||||
item: uid,
|
item: uids,
|
||||||
},
|
},
|
||||||
{ entity_id }
|
{ entity_id }
|
||||||
);
|
);
|
||||||
|
@ -35,7 +35,7 @@ import {
|
|||||||
TodoItemStatus,
|
TodoItemStatus,
|
||||||
TodoListEntityFeature,
|
TodoListEntityFeature,
|
||||||
createItem,
|
createItem,
|
||||||
deleteItem,
|
deleteItems,
|
||||||
fetchItems,
|
fetchItems,
|
||||||
moveItem,
|
moveItem,
|
||||||
updateItem,
|
updateItem,
|
||||||
@ -433,7 +433,7 @@ export class HuiTodoListCard
|
|||||||
} else if (
|
} else if (
|
||||||
this.todoListSupportsFeature(TodoListEntityFeature.DELETE_TODO_ITEM)
|
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()
|
this._fetchData()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -445,11 +445,11 @@ export class HuiTodoListCard
|
|||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const deleteActions: Array<Promise<any>> = [];
|
const checkedItems = this._getCheckedItems(this._items);
|
||||||
this._getCheckedItems(this._items).forEach((item: TodoItem) => {
|
const uids = checkedItems.map((item: TodoItem) => item.uid);
|
||||||
deleteActions.push(deleteItem(this.hass!, this._entityId!, item.uid));
|
deleteItems(this.hass!, this._entityId!, uids).finally(() =>
|
||||||
});
|
this._fetchData()
|
||||||
await Promise.all(deleteActions).finally(() => this._fetchData());
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _newItem(): HaTextField {
|
private get _newItem(): HaTextField {
|
||||||
@ -475,7 +475,7 @@ export class HuiTodoListCard
|
|||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
deleteItem(this.hass!, this._entityId!, item.uid).finally(() =>
|
deleteItems(this.hass!, this._entityId!, [item.uid]).finally(() =>
|
||||||
this._fetchData()
|
this._fetchData()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user