mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Combine edit and complete shopping-list calls (#2135)
This commit is contained in:
parent
49be2ad013
commit
afe9056725
@ -11,26 +11,18 @@ export const fetchItems = (hass: HomeAssistant): Promise<ShoppingListItem[]> =>
|
||||
type: "shopping_list/items",
|
||||
});
|
||||
|
||||
export const saveEdit = (
|
||||
export const updateItem = (
|
||||
hass: HomeAssistant,
|
||||
itemId: number,
|
||||
name: string
|
||||
item: {
|
||||
name?: string;
|
||||
complete?: boolean;
|
||||
}
|
||||
): Promise<ShoppingListItem> =>
|
||||
hass.callWS({
|
||||
type: "shopping_list/items/update",
|
||||
item_id: itemId,
|
||||
name,
|
||||
});
|
||||
|
||||
export const completeItem = (
|
||||
hass: HomeAssistant,
|
||||
itemId: number,
|
||||
complete: boolean
|
||||
): Promise<void> =>
|
||||
hass.callWS({
|
||||
type: "shopping_list/items/update",
|
||||
item_id: itemId,
|
||||
complete,
|
||||
...item,
|
||||
});
|
||||
|
||||
export const clearItems = (hass: HomeAssistant): Promise<void> =>
|
||||
|
@ -13,8 +13,7 @@ import { LovelaceCard } from "../types";
|
||||
import { LovelaceCardConfig } from "../../../data/lovelace";
|
||||
import {
|
||||
fetchItems,
|
||||
completeItem,
|
||||
saveEdit,
|
||||
updateItem,
|
||||
ShoppingListItem,
|
||||
clearItems,
|
||||
addItem,
|
||||
@ -257,15 +256,15 @@ class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
|
||||
}
|
||||
|
||||
private _completeItem(ev): void {
|
||||
completeItem(this.hass!, ev.target.itemId, ev.target.checked).catch(() =>
|
||||
this._fetchData()
|
||||
);
|
||||
updateItem(this.hass!, ev.target.itemId, {
|
||||
complete: ev.target.checked,
|
||||
}).catch(() => this._fetchData());
|
||||
}
|
||||
|
||||
private _saveEdit(ev): void {
|
||||
saveEdit(this.hass!, ev.target.itemId, ev.target.value).catch(() =>
|
||||
this._fetchData()
|
||||
);
|
||||
updateItem(this.hass!, ev.target.itemId, {
|
||||
name: ev.target.value,
|
||||
}).catch(() => this._fetchData());
|
||||
|
||||
ev.target.blur();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user