Skip to content

Commit 4c94843

Browse files
committed
feat: switch recent trips to load more
1 parent ab62af2 commit 4c94843

1 file changed

Lines changed: 44 additions & 49 deletions

File tree

src/pages/index.astro

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,17 @@ const tripTypes: Record<string, string> = {
167167
);
168168
})}
169169
</div>
170-
<nav class="pagination" id="recent-pagination" aria-label="최근 여행 페이지" hidden>
171-
<button type="button" id="recent-prev" aria-label="이전 페이지">‹</button>
172-
<span id="recent-page-info"></span>
173-
<button type="button" id="recent-next" aria-label="다음 페이지">›</button>
174-
</nav>
170+
<div class="load-more" id="recent-load-more" hidden>
171+
<button type="button" id="recent-more">전체 여행 더보기</button>
172+
<span id="recent-count-info"></span>
173+
</div>
175174
</section>
176175
</BaseLayout>
177176

178177
<script>
179178
let activeCountries = [];
180-
let recentPage = 1;
181-
const recentPageSize = 3;
179+
let visibleRecentCount = 3;
180+
const recentBatchSize = 3;
182181

183182
function parseLocalDate(value) {
184183
const [year, month, day] = value.split('-').map(Number);
@@ -247,33 +246,30 @@ const tripTypes: Record<string, string> = {
247246
plansSection.hidden = futureCards.length === 0;
248247
}
249248

250-
function updateRecentPagination() {
249+
function updateRecentList() {
251250
const postsGrid = document.getElementById('posts-grid');
252-
const pagination = document.getElementById('recent-pagination');
253-
const pageInfo = document.getElementById('recent-page-info');
254-
const prevBtn = document.getElementById('recent-prev');
255-
const nextBtn = document.getElementById('recent-next');
256-
if (!postsGrid || !pagination || !pageInfo || !prevBtn || !nextBtn) return;
251+
const loadMore = document.getElementById('recent-load-more');
252+
const countInfo = document.getElementById('recent-count-info');
253+
const moreBtn = document.getElementById('recent-more');
254+
if (!postsGrid || !loadMore || !countInfo || !moreBtn) return;
257255

258256
const cards = Array.from(postsGrid.querySelectorAll('.trip-card'));
259257
const visibleCards = cards.filter(card => card.getAttribute('data-filter-match') !== 'false');
260-
const totalPages = Math.max(1, Math.ceil(visibleCards.length / recentPageSize));
261-
recentPage = Math.min(recentPage, totalPages);
258+
visibleRecentCount = Math.min(Math.max(visibleRecentCount, recentBatchSize), visibleCards.length || recentBatchSize);
262259

263260
cards.forEach(card => {
264261
card.style.display = 'none';
265262
});
266263

267264
visibleCards.forEach((card, index) => {
268-
const start = (recentPage - 1) * recentPageSize;
269-
const end = start + recentPageSize;
270-
card.style.display = index >= start && index < end ? 'block' : 'none';
265+
card.style.display = index < visibleRecentCount ? 'block' : 'none';
271266
});
272267

273-
pagination.hidden = visibleCards.length <= recentPageSize;
274-
pageInfo.textContent = `${recentPage} / ${totalPages}`;
275-
prevBtn.toggleAttribute('disabled', recentPage <= 1);
276-
nextBtn.toggleAttribute('disabled', recentPage >= totalPages);
268+
const shownCount = Math.min(visibleRecentCount, visibleCards.length);
269+
const remainingCount = Math.max(visibleCards.length - shownCount, 0);
270+
loadMore.hidden = remainingCount === 0;
271+
moreBtn.textContent = `전체 여행 더보기 (${remainingCount}개 남음)`;
272+
countInfo.textContent = `${shownCount} / ${visibleCards.length}`;
277273
}
278274

279275
function applyFilters() {
@@ -300,7 +296,7 @@ const tripTypes: Record<string, string> = {
300296
plansSection.hidden = plansGrid.children.length === 0 || visiblePlanCount === 0;
301297
}
302298

303-
updateRecentPagination();
299+
updateRecentList();
304300

305301
// Notify Map Component
306302
window.dispatchEvent(new CustomEvent('map-filter-change', {
@@ -334,7 +330,7 @@ const tripTypes: Record<string, string> = {
334330
activeCountries = [];
335331
document.querySelectorAll('.country-tag').forEach(b => b.classList.remove('active'));
336332
btn.classList.add('active');
337-
recentPage = 1;
333+
visibleRecentCount = recentBatchSize;
338334
applyFilters();
339335
return;
340336
}
@@ -351,7 +347,7 @@ const tripTypes: Record<string, string> = {
351347
if (activeCountries.length === 0) {
352348
document.querySelector('[data-country="all"]')?.classList.add('active');
353349
}
354-
recentPage = 1;
350+
visibleRecentCount = recentBatchSize;
355351
applyFilters();
356352
});
357353
});
@@ -364,19 +360,14 @@ const tripTypes: Record<string, string> = {
364360
// remove active class from all buttons
365361
document.querySelectorAll('.country-tag').forEach(b => b.classList.remove('active'));
366362
document.querySelector('[data-country="all"]')?.classList.add('active');
367-
recentPage = 1;
363+
visibleRecentCount = recentBatchSize;
368364
applyFilters();
369365
});
370366
}
371367

372-
document.getElementById('recent-prev')?.addEventListener('click', () => {
373-
recentPage = Math.max(1, recentPage - 1);
374-
updateRecentPagination();
375-
});
376-
377-
document.getElementById('recent-next')?.addEventListener('click', () => {
378-
recentPage += 1;
379-
updateRecentPagination();
368+
document.getElementById('recent-more')?.addEventListener('click', () => {
369+
visibleRecentCount += recentBatchSize;
370+
updateRecentList();
380371
});
381372
});
382373
</script>
@@ -592,7 +583,7 @@ const tripTypes: Record<string, string> = {
592583
gap: 0.5rem;
593584
}
594585

595-
.pagination {
586+
.load-more {
596587
display: flex;
597588
align-items: center;
598589
justify-content: center;
@@ -602,36 +593,31 @@ const tripTypes: Record<string, string> = {
602593
border-top: 1px solid var(--color-border);
603594
}
604595

605-
.pagination[hidden] {
596+
.load-more[hidden] {
606597
display: none;
607598
}
608599

609-
.pagination button {
610-
width: 36px;
611-
height: 36px;
600+
.load-more button {
601+
min-height: 40px;
602+
padding: 0 1rem;
612603
border: 1px solid var(--color-border);
613604
border-radius: 8px;
614605
background: var(--color-bg-secondary);
615606
color: var(--color-text);
616607
cursor: pointer;
617-
font-size: 1.25rem;
618-
line-height: 1;
608+
font-size: 0.9rem;
609+
font-weight: 700;
619610
transition: all 0.2s;
620611
}
621612

622-
.pagination button:hover:not(:disabled) {
613+
.load-more button:hover {
623614
border-color: var(--color-primary);
624615
color: var(--color-primary);
625616
box-shadow: 0 4px 14px rgba(67, 97, 238, 0.12);
626617
}
627618

628-
.pagination button:disabled {
629-
cursor: not-allowed;
630-
opacity: 0.35;
631-
}
632-
633-
.pagination span {
634-
min-width: 56px;
619+
.load-more span {
620+
min-width: 64px;
635621
text-align: center;
636622
color: var(--color-text-muted);
637623
font-size: 0.875rem;
@@ -780,6 +766,15 @@ const tripTypes: Record<string, string> = {
780766
gap: 0.25rem;
781767
}
782768

769+
.load-more {
770+
flex-direction: column;
771+
gap: 0.5rem;
772+
}
773+
774+
.load-more button {
775+
width: 100%;
776+
}
777+
783778
.country-tag {
784779
padding: 0.25rem 0.5rem;
785780
font-size: 0.75rem;

0 commit comments

Comments
 (0)