Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/data/shopping-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> =>
Expand Down
15 changes: 7 additions & 8 deletions src/panels/lovelace/cards/hui-shopping-list-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { HomeAssistant } from "../../../types";
import { LovelaceCard, LovelaceCardConfig } from "../types";
import {
fetchItems,
completeItem,
saveEdit,
updateItem,
ShoppingListItem,
clearItems,
addItem,
Expand Down Expand Up @@ -256,15 +255,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();
}
Expand Down