mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Auto remove empty items from shopping list (#14487)
This commit is contained in:
parent
75b1b1c9a0
commit
f0f699a37e
@ -39,6 +39,15 @@ export const addItem = (
|
|||||||
name,
|
name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const removeItem = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
item_id: string
|
||||||
|
): Promise<ShoppingListItem> =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "shopping_list/items/remove",
|
||||||
|
item_id,
|
||||||
|
});
|
||||||
|
|
||||||
export const reorderItems = (
|
export const reorderItems = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
itemIds: string[]
|
itemIds: string[]
|
||||||
|
@ -8,32 +8,33 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state, query } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { guard } from "lit/directives/guard";
|
import { guard } from "lit/directives/guard";
|
||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-svg-icon";
|
|
||||||
import "../../../components/ha-checkbox";
|
import "../../../components/ha-checkbox";
|
||||||
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
|
import type { HaTextField } from "../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
addItem,
|
addItem,
|
||||||
clearItems,
|
clearItems,
|
||||||
fetchItems,
|
fetchItems,
|
||||||
|
removeItem,
|
||||||
reorderItems,
|
reorderItems,
|
||||||
ShoppingListItem,
|
ShoppingListItem,
|
||||||
updateItem,
|
updateItem,
|
||||||
} from "../../../data/shopping-list";
|
} from "../../../data/shopping-list";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { HomeAssistant } from "../../../types";
|
|
||||||
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
|
||||||
import { SensorCardConfig, ShoppingListCardConfig } from "./types";
|
|
||||||
import type { HaTextField } from "../../../components/ha-textfield";
|
|
||||||
import {
|
import {
|
||||||
loadSortable,
|
loadSortable,
|
||||||
SortableInstance,
|
SortableInstance,
|
||||||
} from "../../../resources/sortable.ondemand";
|
} from "../../../resources/sortable.ondemand";
|
||||||
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
||||||
|
import { SensorCardConfig, ShoppingListCardConfig } from "./types";
|
||||||
|
|
||||||
@customElement("hui-shopping-list-card")
|
@customElement("hui-shopping-list-card")
|
||||||
class HuiShoppingListCard
|
class HuiShoppingListCard
|
||||||
@ -264,9 +265,14 @@ class HuiShoppingListCard
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _saveEdit(ev): void {
|
private _saveEdit(ev): void {
|
||||||
updateItem(this.hass!, ev.target.itemId, {
|
// If name is not empty, update the item otherwise remove it
|
||||||
name: ev.target.value,
|
if (ev.target.value) {
|
||||||
}).catch(() => this._fetchData());
|
updateItem(this.hass!, ev.target.itemId, {
|
||||||
|
name: ev.target.value,
|
||||||
|
}).catch(() => this._fetchData());
|
||||||
|
} else {
|
||||||
|
removeItem(this.hass!, ev.target.itemId).catch(() => this._fetchData());
|
||||||
|
}
|
||||||
|
|
||||||
ev.target.blur();
|
ev.target.blur();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user