Skip to content

Commit 77a81e5

Browse files
authored
Update fast-search-card.js
1 parent 46461cf commit 77a81e5

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

dist/fast-search-card.js

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,34 +4343,24 @@ class FastSearchCard extends HTMLElement {
43434343
handleCategorySelect(selectedButton) {
43444344
const category = selectedButton.dataset.category;
43454345

4346-
// NEU: Wenn gleiche Kategorie → Menü schließen
4346+
// Wenn gleiche Kategorie → Menü schließen
43474347
if (category === this.activeCategory) {
43484348
this.hideCategoryButtons();
43494349
return;
43504350
}
43514351

4352-
this.shadowRoot.querySelectorAll('.category-button').forEach(btn => btn.classList.remove('active'));
4353-
selectedButton.classList.add('active');
4354-
selectedButton.animate([{ transform: 'scale(1)' }, { transform: 'scale(1.1)' }, { transform: 'scale(1)' }], { duration: 300, easing: 'cubic-bezier(0.16, 1, 0.3, 1)' });
4355-
this.activeCategory = category;
4352+
// Animation für visuelles Feedback
4353+
selectedButton.animate([
4354+
{ transform: 'scale(1)' },
4355+
{ transform: 'scale(1.1)' },
4356+
{ transform: 'scale(1)' }
4357+
], { duration: 300, easing: 'cubic-bezier(0.16, 1, 0.3, 1)' });
43564358

4357-
// Reset subcategory mode für Custom
4358-
if (category === 'custom') {
4359-
this.subcategoryMode = 'categories'; // Start with categories for custom
4360-
} else {
4361-
this.subcategoryMode = 'categories'; // Standard mode for others
4362-
}
4359+
// Zentrale Navigation verwenden
4360+
this.switchToCategory(category);
43634361

4364-
this.updateCategoryIcon();
4365-
this.updatePlaceholder();
4366-
this.updateSubcategoryToggleIcon();
4367-
this.updateSubcategoryChips();
4362+
// Menü schließen
43684363
this.hideCategoryButtons();
4369-
// Hinzufügen:
4370-
this.updateTypeButtonVisibility();
4371-
this.updateFilterButtonStates();
4372-
// this.expandPanel(); // ENTFERNT
4373-
// this.showCurrentCategoryItems(); // ENTFERNT
43744364
}
43754365

43764366
handleSubcategorySelect(selectedChip) {
@@ -4570,6 +4560,43 @@ class FastSearchCard extends HTMLElement {
45704560
searchInput.placeholder = placeholders[this.activeCategory] || placeholders.devices;
45714561
}
45724562

4563+
switchToCategory(newCategory) {
4564+
console.log(`🔄 Switching to category: ${newCategory}`);
4565+
4566+
// 1. Interne Variable setzen
4567+
this.activeCategory = newCategory;
4568+
4569+
// 2. Subcategory Mode zurücksetzen
4570+
if (newCategory === 'custom') {
4571+
this.subcategoryMode = 'categories';
4572+
} else {
4573+
this.subcategoryMode = 'categories';
4574+
}
4575+
4576+
// 3. Subcategory zurücksetzen
4577+
this.activeSubcategory = 'all';
4578+
4579+
// 4. UI-Komponenten aktualisieren
4580+
this.updateCategoryIcon();
4581+
this.updatePlaceholder();
4582+
this.updateCategoryButtonStates(); // ← NEU
4583+
this.updateSubcategoryChips();
4584+
this.updateTypeButtonVisibility();
4585+
this.updateFilterButtonStates();
4586+
4587+
// 5. Items laden und anzeigen
4588+
this.showCurrentCategoryItems();
4589+
4590+
console.log(`✅ Category switched to: ${newCategory}`);
4591+
}
4592+
4593+
updateCategoryButtonStates() {
4594+
this.shadowRoot.querySelectorAll('.category-button').forEach(btn => {
4595+
const isActive = btn.dataset.category === this.activeCategory;
4596+
btn.classList.toggle('active', isActive);
4597+
});
4598+
}
4599+
45734600
async updateItems() {
45744601
if (!this._hass) return;
45754602

@@ -12000,14 +12027,12 @@ class FastSearchCard extends HTMLElement {
1200012027
// 1. Bestimme Ziel-Kategorie
1200112028
const targetCategory = this.getTargetCategoryForDomain(actionDomain);
1200212029

12003-
// 2. Wechsle Kategorie und verlasse Detailansicht
12004-
this.activeCategory = targetCategory;
12030+
// Detail-View schließen
1200512031
this.isDetailView = false;
1200612032
this.currentDetailItem = null;
1200712033

12008-
// 3. ❗ ENTSCHEIDENDE ÄNDERUNG: Rufe die korrekte Funktion auf,
12009-
// um die Items für die neue Kategorie zu filtern und zu rendern.
12010-
this.showCurrentCategoryItems();
12034+
// Zentrale Navigation verwenden
12035+
this.switchToCategory(targetCategory);
1201112036

1201212037
// 4. Warte zuverlässig mit requestAnimationFrame, bis das Element da ist
1201312038
const waitForElementAndClick = (selector, targetId, retries = 30) => {

0 commit comments

Comments
 (0)