Conversation
Following features: - Add item - Edit item - Complete item - Clear items
|
Not sure I like I also think a |
| class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement) | ||
| implements LovelaceCard { | ||
| public hass?: HomeAssistant; | ||
| protected _config?: Config; |
|
src/data/shopping-list.ts
Outdated
| name, | ||
| }); | ||
|
|
||
| export const clearItems = (hass: HomeAssistant): Promise<void> => |
There was a problem hiding this comment.
clearItems -> clearCompletedItems
| public connectedCallback(): void { | ||
| super.connectedCallback(); | ||
|
|
||
| if (this.hass) { |
There was a problem hiding this comment.
So since you have this check, it is important that in case we get connected to the DOM and then get hass, we recover from that?
| super.connectedCallback(); | ||
|
|
||
| if (this.hass) { | ||
| this.hass.connection |
There was a problem hiding this comment.
Make this this._unsubEvents = this.hass.connection.subscribeEvents(…) and then in disconnected do this:
if (this._unsubEvents) {
this._unsubEvents.then(unsub => unsub());
}That way, if the shopping card disconnects before the subscription is in place, we still unsubscribe.
| <ha-card .header="${this._config.title}"> | ||
| <ha-icon | ||
| id="clear" | ||
| icon="hass:notification-clear-all" |
| ${repeat( | ||
| this._items!, | ||
| (item) => | ||
| !item.complete |
There was a problem hiding this comment.
Just filter before passing it to the render function: this._items.filter(item => !item.complete)
Also add an identification function to repeat as 2nd arg: item => item.id
| ${repeat( | ||
| this._items!, | ||
| (item) => | ||
| item.complete |
There was a problem hiding this comment.
use filter and add identify func.
| } | ||
|
|
||
| private _addItem(ev): void { | ||
| if (this.shadowRoot!.querySelector("#addBox")) { |
There was a problem hiding this comment.
Don't ever write IFs that span whole or most of a function. Convert those to a guard clause:
const addBox = this.shadowRoot!.querySelector("#addBox");
if (!addBox) { return; }
…
src/translations/en.json
Outdated
| "script": { | ||
| "execute": "Execute" | ||
| }, | ||
| "shopping-list": { |
There was a problem hiding this comment.
We should have a Lovelace section in the translation files.
Addressed review comments and scaled this back to just get a simple shopping list card out there and we can discuss/debate how best to add the additional pieces with smaller PRs
|
I don't think we should limit this card to |
The component is 'Shopping List'. And I already made a list-card :) |
Ahh Gotcha. Fair enough. |
In the future I plan to update the shopping list component to support multiple lists and would probably propose a renaming, but for MVP, I think this fits |
| this._hass = hass; | ||
|
|
||
| if (!this._unsubEvents) { | ||
| this.connectedCallback(); |
There was a problem hiding this comment.
This is dangerous, this calls all the super connected callbacks too. Extract the subbing of events into a method and call that here.
|
I've removed the calling of connectedCallback inside the
If I missed something or broke something, we can fix it in another PR. Yay for dev branch. |


Following features: