Skip to content

Commit dffe445

Browse files
authored
Update fast-search-card.js
1 parent 2934979 commit dffe445

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

dist/fast-search-card.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7887,9 +7887,12 @@ class FastSearchCard extends HTMLElement {
78877887
if (labelButton) {
78887888
labelButton.addEventListener('click', (e) => {
78897889
const entityId = e.target.dataset.entityId;
7890-
this.addStarLabel(entityId);
7890+
this.toggleStarLabel(entityId);
78917891
});
7892-
}
7892+
7893+
// Initial Button State setzen
7894+
this.updateStarButtonState(item.id);
7895+
}
78937896

78947897
const iconBackground = detailPanel.querySelector('.icon-background');
78957898
const titleArea = detailPanel.querySelector('.detail-title-area');
@@ -11091,10 +11094,8 @@ class FastSearchCard extends HTMLElement {
1109111094
}
1109211095

1109311096

11094-
11095-
11096-
async addStarLabel(entityId) {
11097-
console.log(`🌟 Versuche Label "star" zu ${entityId} hinzuzufügen...`);
11097+
async toggleStarLabel(entityId) {
11098+
console.log(`🌟 Toggle Label "star" für ${entityId}...`);
1109811099

1109911100
try {
1110011101
// Aktuelle Labels der Entity abrufen
@@ -11103,8 +11104,23 @@ class FastSearchCard extends HTMLElement {
1110311104

1110411105
console.log('Aktuelle Labels:', currentLabels);
1110511106

11106-
// "star" Label hinzufügen (wenn nicht schon vorhanden)
11107-
const updatedLabels = [...new Set([...currentLabels, 'star'])];
11107+
// Prüfen ob "star" bereits vorhanden ist
11108+
const hasStarLabel = currentLabels.includes('star');
11109+
11110+
let updatedLabels;
11111+
let message;
11112+
11113+
if (hasStarLabel) {
11114+
// "star" Label entfernen
11115+
updatedLabels = currentLabels.filter(label => label !== 'star');
11116+
message = 'Star Label entfernt!';
11117+
console.log('Entferne star label');
11118+
} else {
11119+
// "star" Label hinzufügen
11120+
updatedLabels = [...currentLabels, 'star'];
11121+
message = 'Star Label hinzugefügt!';
11122+
console.log('Füge star label hinzu');
11123+
}
1110811124

1110911125
console.log('Neue Labels:', updatedLabels);
1111011126

@@ -11115,14 +11131,30 @@ class FastSearchCard extends HTMLElement {
1111511131
labels: updatedLabels
1111611132
});
1111711133

11118-
console.log('✅ Label erfolgreich hinzugefügt:', result);
11119-
alert('Star Label hinzugefügt!');
11134+
console.log('✅ Label erfolgreich geändert:', result);
11135+
alert(message);
11136+
11137+
// Button visuell aktualisieren
11138+
this.updateStarButtonState(entityId);
1112011139

1112111140
} catch (error) {
11122-
console.error('❌ Fehler beim Hinzufügen des Labels:', error);
11141+
console.error('❌ Fehler beim Ändern des Labels:', error);
1112311142
alert('Fehler: ' + error.message);
1112411143
}
1112511144
}
11145+
11146+
updateStarButtonState(entityId) {
11147+
const labelButton = this.shadowRoot.querySelector('.label-test-button');
11148+
if (!labelButton) return;
11149+
11150+
const entityRegistry = this._hass.entities[entityId];
11151+
const currentLabels = entityRegistry?.labels || [];
11152+
const hasStarLabel = currentLabels.includes('star');
11153+
11154+
// Button Text und Style ändern
11155+
labelButton.textContent = hasStarLabel ? '🌟' : '⭐';
11156+
labelButton.title = hasStarLabel ? 'Star Label entfernen' : 'Star Label hinzufügen';
11157+
}
1112611158

1112711159

1112811160

0 commit comments

Comments
 (0)