diff --git a/panels/shopping-list/ha-panel-shopping-list.html b/panels/shopping-list/ha-panel-shopping-list.html
index d2c74b4aec..05317ae18a 100644
--- a/panels/shopping-list/ha-panel-shopping-list.html
+++ b/panels/shopping-list/ha-panel-shopping-list.html
@@ -21,38 +21,38 @@
:host {
height: 100%;
}
+ app-toolbar paper-listbox {
+ width: 150px;
+ }
+ app-toolbar paper-item {
+ cursor: pointer;
+ }
.content {
- padding: 24px 0 32px;
+ padding-bottom: 32px;
max-width: 600px;
margin: 0 auto;
}
paper-card {
display: block;
- padding-bottom: 16px;
}
- .list-header { @apply --paper-font-headline; }
- .list-options {
- position: absolute;
- top: 0;
- right: 0;
- color: var(--secondary-text-color);
+ paper-icon-item {
+ border-top: 1px solid var(--divider-color);
}
- .list-header paper-listbox {
- width: 150px;
- }
- .list-header paper-item {
- cursor: pointer;
- }
- paper-item {
- --paper-item-focused: {
- background-color: white;
- }
+ paper-icon-item:first-child {
+ border-top: 0;
}
paper-checkbox {
- padding: 11px 7px;
+ padding: 11px;
}
paper-input {
- width: 100%;
+ --paper-input-container-underline: {
+ display: none;
+ }
+ --paper-input-container-underline-focus: {
+ display: none;
+ }
+ position: relative;
+ top: 1px;
}
.tip {
padding: 24px;
@@ -66,70 +66,63 @@
Shopping List
-
+
+
+
+
+ Clear completed
+
+
-
-
-
- You have no items on your shopping list.
-
-
+
+
+
+
+
+
+
-
+
-
- [[item.name]]
-
-
-
-
+
-
-
-
-
+
Tap the microphone on the top right and say "Add candy to my shopping list"
@@ -146,26 +139,14 @@ class HaPanelShoppingList extends Polymer.Element {
hass: Object,
narrow: Boolean,
showMenu: Boolean,
+ canListen: Boolean,
items: {
type: Array,
value: [],
},
- _editIndex: {
- type: Number,
- value: -1,
- },
- _editValue: {
- type: String,
- value: '',
- },
};
}
- ready() {
- super.ready();
- this.addEventListener('keydown', ev => this._checkEsc(ev));
- }
-
connectedCallback() {
super.connectedCallback();
this._fetchData = this._fetchData.bind(this);
@@ -183,48 +164,39 @@ class HaPanelShoppingList extends Polymer.Element {
_fetchData() {
this.hass.callApi('get', 'shopping_list')
.then(function (items) {
+ items.reverse();
this.items = items;
}.bind(this));
}
- _computeIsEditting(editIndex, index) {
- return editIndex === index;
- }
-
_itemCompleteTapped(ev) {
ev.stopPropagation();
var item = ev.model.item;
this.hass.callApi('post', 'shopping_list/item/' + item.id, {
- complete: item.complete
- }).catch(function () {
- this._fetchData();
- }.bind(this));
+ complete: !item.complete
+ }).catch(() => this._fetchData());
}
- _enableEditting(ev) {
- var item = ev.model.item;
- var index = this.items.indexOf(item);
-
- if (index === this._editIndex) return;
-
- this._editValue = item.name;
- this._editIndex = index;
+ _addItem(ev) {
+ this.hass.callApi('post', 'shopping_list/item', {
+ name: this.$.addBox.value,
+ }).catch(() => this._fetchData());
+ this.$.addBox.value = '';
+ // Presence of 'ev' means tap on "add" button.
+ if (ev) {
+ setTimeout(() => this.$.addBox.focus(), 10);
+ }
}
- _cancelEditting() {
- this._editIndex = -1;
- this._editValue = '';
+ _addKeyPress(ev) {
+ if (ev.keyCode === 13) {
+ this._addItem();
+ }
}
- _finishEditting(ev) {
- ev.stopPropagation();
-
- var index = this._editIndex;
- var name = this._editValue;
- var item = this.items[index];
-
- this._editIndex = -1;
- this._editValue = '';
+ _saveEdit(ev) {
+ const { index, item } = ev.model;
+ const name = ev.target.value;
if (name === item.name) {
return;
@@ -233,21 +205,7 @@ class HaPanelShoppingList extends Polymer.Element {
this.set(['items', index, 'name'], name);
this.hass.callApi('post', 'shopping_list/item/' + item.id, {
name: name
- }).catch(function () {
- this._fetchData();
- }.bind(this));
- }
-
- _editKeyPress(ev) {
- if (ev.keyCode === 13) {
- this._finishEditting(ev);
- }
- }
-
- _checkEsc(ev) {
- if (ev.keyCode === 27) {
- this._cancelEditting();
- }
+ }).catch(() => this._fetchData());
}
_clearCompleted() {
diff --git a/src/components/ha-start-voice-button.html b/src/components/ha-start-voice-button.html
index b31047e8ce..5a81a8a2ab 100644
--- a/src/components/ha-start-voice-button.html
+++ b/src/components/ha-start-voice-button.html
@@ -27,6 +27,7 @@ class HaStartVoiceButton extends window.hassMixins.EventsMixin(Polymer.Element)
canListen: {
type: Boolean,
computed: 'computeCanListen(hass)',
+ notify: true,
},
};
}