73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import { t, i18n } from '../../i18n.js';
|
|
import '../listing-card.js';
|
|
import '../search-box.js';
|
|
|
|
class PageHome extends HTMLElement {
|
|
connectedCallback() {
|
|
this.render();
|
|
this.unsubscribe = i18n.subscribe(() => this.render());
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
if (this.unsubscribe) this.unsubscribe();
|
|
}
|
|
|
|
render() {
|
|
this.innerHTML = /* html */`
|
|
<section class="search-section">
|
|
<search-box></search-box>
|
|
</section>
|
|
|
|
<section class="recent-listings">
|
|
<h2>${t('home.recentListings')}</h2>
|
|
<div class="listings-grid">
|
|
${this.renderPlaceholderListings()}
|
|
</div>
|
|
</section>
|
|
`;
|
|
}
|
|
|
|
renderPlaceholderListings() {
|
|
const placeholders = Array(10).fill(null);
|
|
return placeholders.map((_, i) => /* html */`
|
|
<listing-card
|
|
listing-id="${i + 1}"
|
|
title="${t('home.placeholderTitle')}"
|
|
location="${t('home.placeholderLocation')}"
|
|
></listing-card>
|
|
`).join('');
|
|
}
|
|
}
|
|
|
|
customElements.define('page-home', PageHome);
|
|
|
|
const style = document.createElement('style');
|
|
style.textContent = /* css */`
|
|
/* Search Section */
|
|
page-home .search-section {
|
|
padding: var(--space-xl) 0;
|
|
}
|
|
|
|
/* Listings */
|
|
page-home section {
|
|
margin-bottom: var(--space-xl);
|
|
}
|
|
|
|
page-home section h2 {
|
|
margin-bottom: var(--space-lg);
|
|
}
|
|
|
|
page-home .listings-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, 1fr);
|
|
gap: var(--space-md);
|
|
}
|
|
|
|
@media (min-width: 768px) {
|
|
page-home .listings-grid {
|
|
grid-template-columns: repeat(5, 1fr);
|
|
}
|
|
}
|
|
`;
|
|
document.head.appendChild(style);
|