Skip to content

Commit b10ebd4

Browse files
authored
Update fast-search-card.js
1 parent 3dbfe3e commit b10ebd4

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

dist/fast-search-card.js

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11257,14 +11257,10 @@ class FastSearchCard extends HTMLElement {
1125711257

1125811258
if (favoritesHelper && favoritesHelper.state) {
1125911259
try {
11260-
// Versuche JSON zu parsen
1126111260
const parsed = JSON.parse(favoritesHelper.state);
11262-
// Prüfe ob es bereits Multi-User Format ist
1126311261
if (typeof parsed === 'object' && !Array.isArray(parsed)) {
1126411262
allUserFavorites = parsed;
1126511263
} else if (Array.isArray(parsed)) {
11266-
// Legacy: Array-Format zu User-Format migrieren
11267-
console.log('🔄 Migriere Legacy-Format zu Multi-User');
1126811264
allUserFavorites = { [userId]: parsed };
1126911265
}
1127011266
} catch (e) {
@@ -11279,37 +11275,35 @@ class FastSearchCard extends HTMLElement {
1127911275

1128011276
// Toggle: Hinzufügen oder entfernen
1128111277
const isFavorite = userFavorites.includes(entityId);
11282-
let message;
1128311278

1128411279
if (isFavorite) {
1128511280
userFavorites = userFavorites.filter(id => id !== entityId);
11286-
message = 'Favorit entfernt!';
1128711281
console.log(`➖ Entferne ${entityId} von Favoriten`);
1128811282
} else {
1128911283
userFavorites = [...userFavorites, entityId];
11290-
message = 'Favorit hinzugefügt!';
1129111284
console.log(`➕ Füge ${entityId} zu Favoriten hinzu`);
1129211285
}
1129311286

11287+
// ✅ SOFORT visuell aktualisieren (vor dem Speichern)
11288+
this.updateStarButtonState(entityId);
11289+
this.renderResults(); // Suchergebnisse sofort aktualisieren
11290+
1129411291
// User-Favoriten in Gesamt-Struktur zurückschreiben
1129511292
allUserFavorites[userId] = userFavorites;
1129611293
console.log('Neue Gesamt-Struktur:', allUserFavorites);
1129711294

11298-
// Zurück in Helper speichern
11295+
// Zurück in Helper speichern (im Hintergrund)
1129911296
await this._hass.callService('input_text', 'set_value', {
1130011297
entity_id: 'input_text.fast_search_favorites',
1130111298
value: JSON.stringify(allUserFavorites)
1130211299
});
1130311300

11304-
console.log('✅ Benutzerspezifische Favoriten erfolgreich gespeichert');
11305-
alert(message);
11306-
11307-
// Button visuell aktualisieren
11308-
this.updateStarButtonState(entityId);
11301+
console.log('✅ Favoriten gespeichert');
1130911302

1131011303
} catch (error) {
1131111304
console.error('❌ Fehler beim Ändern der Favoriten:', error);
11312-
alert('Fehler: ' + error.message);
11305+
// Bei Fehler: Button-State zurücksetzen
11306+
this.updateStarButtonState(entityId);
1131311307
}
1131411308
}
1131511309

@@ -11334,6 +11328,16 @@ class FastSearchCard extends HTMLElement {
1133411328
const userStars = allUserStars[userId] || [];
1133511329
const isStarred = userStars.includes(entityId);
1133611330

11331+
// ✅ SOFORTIGE Animation für besseres Feedback
11332+
favoriteButton.animate([
11333+
{ transform: 'scale(1)' },
11334+
{ transform: 'scale(1.2)' },
11335+
{ transform: 'scale(1)' }
11336+
], {
11337+
duration: 200,
11338+
easing: 'ease-out'
11339+
});
11340+
1133711341
// CSS-Klasse und SVG fill ändern
1133811342
favoriteButton.classList.toggle('active', isStarred);
1133911343
const svg = favoriteButton.querySelector('svg');
@@ -11348,30 +11352,6 @@ class FastSearchCard extends HTMLElement {
1134811352
}
1134911353
}
1135011354

11351-
debugUserFavorites() {
11352-
const userId = this._hass.user?.id || 'unknown_user';
11353-
const favoritesHelper = this._hass.states['input_text.fast_search_favorites'];
11354-
11355-
console.log('=== FAVORITEN DEBUG ===');
11356-
console.log('👤 Current User ID:', userId);
11357-
console.log('🏠 Helper State:', favoritesHelper?.state);
11358-
11359-
if (favoritesHelper && favoritesHelper.state) {
11360-
try {
11361-
const parsed = JSON.parse(favoritesHelper.state);
11362-
console.log('📊 Parsed Data:', parsed);
11363-
11364-
if (typeof parsed === 'object' && !Array.isArray(parsed)) {
11365-
console.log('👥 All Users:', Object.keys(parsed));
11366-
console.log('⭐ My Favorites:', parsed[userId] || []);
11367-
}
11368-
} catch (e) {
11369-
console.error('❌ Parse Error:', e);
11370-
}
11371-
}
11372-
console.log('=== END DEBUG ===');
11373-
}
11374-
1137511355
// 🌟 NEUE METHODE: Star-Items für Suchergebnisse sammeln
1137611356
getUserStarredItems() {
1137711357
try {

0 commit comments

Comments
 (0)