refactor: fix memory leak in auth-modal, consolidate escapeHTML helper across 11 components

This commit is contained in:
2026-02-05 15:07:18 +01:00
parent cd437f20e1
commit 08a650ea80
13 changed files with 44 additions and 131 deletions

View File

@@ -3,6 +3,7 @@ import { directus } from '../../services/directus.js'
import { auth } from '../../services/auth.js'
import { listingsService } from '../../services/listings.js'
import { getXmrRates, formatPrice as formatCurrencyPrice } from '../../services/currency.js'
import { escapeHTML } from '../../utils/helpers.js'
import '../chat-widget.js'
import '../location-map.js'
import '../listing-card.js'
@@ -167,7 +168,7 @@ class PageListing extends HTMLElement {
<div class="listing-gallery">
<div class="listing-image-main" id="main-image">
${firstImage
? `<img src="${firstImage}" alt="${this.escapeHtml(this.listing.title)}" id="main-img">`
? `<img src="${firstImage}" alt="${escapeHTML(this.listing.title)}" id="main-img">`
: this.getPlaceholderSvg()}
</div>
${images.length > 1 ? `
@@ -183,8 +184,8 @@ class PageListing extends HTMLElement {
<!-- Header -->
<header class="listing-header">
${categoryName ? `<a href="#/search?category=${this.listing.category?.slug}" class="badge badge-primary">${this.escapeHtml(categoryName)}</a>` : ''}
<h1>${this.escapeHtml(this.listing.title)}</h1>
${categoryName ? `<a href="#/search?category=${this.listing.category?.slug}" class="badge badge-primary">${escapeHTML(categoryName)}</a>` : ''}
<h1>${escapeHTML(this.listing.title)}</h1>
<div class="listing-price-wrapper">
<p class="listing-price">${priceInfo.primary}</p>
${priceInfo.secondary ? `<p class="listing-price-secondary">${priceInfo.secondary}</p>` : ''}
@@ -214,9 +215,9 @@ class PageListing extends HTMLElement {
<section class="listing-location-section location-mobile">
<h2>${t('listing.location')}</h2>
<location-map
name="${this.escapeHtml(this.listing.location.name || '')}"
postal-code="${this.escapeHtml(this.listing.location.postal_code || '')}"
country="${this.escapeHtml(this.listing.location.country || '')}"
name="${escapeHTML(this.listing.location.name || '')}"
postal-code="${escapeHTML(this.listing.location.postal_code || '')}"
country="${escapeHTML(this.listing.location.country || '')}"
></location-map>
</section>
` : ''}
@@ -241,9 +242,9 @@ class PageListing extends HTMLElement {
<section class="listing-location-section">
<h2>${t('listing.location')}</h2>
<location-map
name="${this.escapeHtml(this.listing.location.name || '')}"
postal-code="${this.escapeHtml(this.listing.location.postal_code || '')}"
country="${this.escapeHtml(this.listing.location.country || '')}"
name="${escapeHTML(this.listing.location.name || '')}"
postal-code="${escapeHTML(this.listing.location.postal_code || '')}"
country="${escapeHTML(this.listing.location.country || '')}"
></location-map>
</section>
` : ''}
@@ -341,10 +342,10 @@ class PageListing extends HTMLElement {
return /* html */`
<listing-card
listing-id="${listing.id}"
title="${this.escapeHtml(listing.title || '')}"
title="${escapeHTML(listing.title || '')}"
price="${listing.price || ''}"
currency="${listing.currency || 'EUR'}"
location="${this.escapeHtml(locationName)}"
location="${escapeHTML(locationName)}"
image="${imageUrl}"
owner-id="${listing.user_created || ''}"
></listing-card>
@@ -560,13 +561,6 @@ class PageListing extends HTMLElement {
.replace(/>/g, '&gt;')
.replace(/\n/g, '<br>')
}
escapeHtml(text) {
if (!text) return ''
const div = document.createElement('div')
div.textContent = text
return div.innerHTML
}
}
customElements.define('page-listing', PageListing)