mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-02 14:07:55 +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",
|
type: "shopping_list/items",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const saveEdit = (
|
export const updateItem = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
itemId: number,
|
itemId: number,
|
||||||
name: string
|
item: {
|
||||||
|
name?: string;
|
||||||
|
complete?: boolean;
|
||||||
|
}
|
||||||
): Promise<ShoppingListItem> =>
|
): Promise<ShoppingListItem> =>
|
||||||
hass.callWS({
|
hass.callWS({
|
||||||
type: "shopping_list/items/update",
|
type: "shopping_list/items/update",
|
||||||
item_id: itemId,
|
item_id: itemId,
|
||||||
name,
|
...item,
|
||||||
});
|
|
||||||
|
|
||||||
export const completeItem = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
itemId: number,
|
|
||||||
complete: boolean
|
|
||||||
): Promise<void> =>
|
|
||||||
hass.callWS({
|
|
||||||
type: "shopping_list/items/update",
|
|
||||||
item_id: itemId,
|
|
||||||
complete,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const clearItems = (hass: HomeAssistant): Promise<void> =>
|
export const clearItems = (hass: HomeAssistant): Promise<void> =>
|
||||||
|
@ -13,8 +13,7 @@ import { LovelaceCard } from "../types";
|
|||||||
import { LovelaceCardConfig } from "../../../data/lovelace";
|
import { LovelaceCardConfig } from "../../../data/lovelace";
|
||||||
import {
|
import {
|
||||||
fetchItems,
|
fetchItems,
|
||||||
completeItem,
|
updateItem,
|
||||||
saveEdit,
|
|
||||||
ShoppingListItem,
|
ShoppingListItem,
|
||||||
clearItems,
|
clearItems,
|
||||||
addItem,
|
addItem,
|
||||||
@ -257,15 +256,15 @@ class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _completeItem(ev): void {
|
private _completeItem(ev): void {
|
||||||
completeItem(this.hass!, ev.target.itemId, ev.target.checked).catch(() =>
|
updateItem(this.hass!, ev.target.itemId, {
|
||||||
this._fetchData()
|
complete: ev.target.checked,
|
||||||
);
|
}).catch(() => this._fetchData());
|
||||||
}
|
}
|
||||||
|
|
||||||
private _saveEdit(ev): void {
|
private _saveEdit(ev): void {
|
||||||
saveEdit(this.hass!, ev.target.itemId, ev.target.value).catch(() =>
|
updateItem(this.hass!, ev.target.itemId, {
|
||||||
this._fetchData()
|
name: ev.target.value,
|
||||||
);
|
}).catch(() => this._fetchData());
|
||||||
|
|
||||||
ev.target.blur();
|
ev.target.blur();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user