Fix date filtering bug in heatmap/calendar and sync selection state

This commit is contained in:
leeyj
2026-04-16 11:27:25 +09:00
parent 175a30325b
commit df8ae62b0e
8 changed files with 75 additions and 4 deletions
+5
View File
@@ -34,6 +34,11 @@ export const CalendarManager = {
this.render();
},
setSelectedDate(date) {
this.selectedDate = date;
this.render();
},
bindEvents() {
const header = document.getElementById('calendarHeader');
if (header) {
+26 -2
View File
@@ -8,9 +8,13 @@ export const HeatmapManager = {
container: null,
data: [], // [{date: 'YYYY-MM-DD', count: N}, ...]
currentRange: 365, // 기본 365일
selectedDate: null,
onDateSelect: null,
init(containerId) {
init(containerId, onDateSelect) {
this.container = document.getElementById(containerId);
this.onDateSelect = onDateSelect;
if (!this.container) {
console.warn('[Heatmap] Container not found:', containerId);
return;
@@ -23,6 +27,11 @@ export const HeatmapManager = {
}
},
setSelectedDate(date) {
this.selectedDate = date;
this.render();
},
/**
* 데이터를 서버에서 가져와 렌더링합니다.
*/
@@ -95,13 +104,14 @@ export const HeatmapManager = {
const level = this.calculateLevel(count);
const isOutOfRange = currentDate < startDate || currentDate > today;
const isSelected = this.selectedDate === dateStr;
const tooltip = I18nManager.t('tooltip_heatmap_stat')
.replace('{date}', dateStr)
.replace('{count}', count);
html += `
<div class="heatmap-cell ${isOutOfRange ? 'out' : `lvl-${level}`}"
<div class="heatmap-cell ${isOutOfRange ? 'out' : `lvl-${level}`} ${isSelected ? 'selected' : ''}"
data-date="${dateStr}"
data-count="${count}"
title="${tooltip}">
@@ -144,5 +154,19 @@ export const HeatmapManager = {
this.refresh();
};
}
// 날짜 셀 클릭 이벤트 추가
this.container.querySelectorAll('.heatmap-cell[data-date]').forEach(cell => {
cell.onclick = (e) => {
const date = cell.dataset.date;
if (this.selectedDate === date) {
this.selectedDate = null; // 해제
} else {
this.selectedDate = date; // 선택
}
this.render(); // 다시 그려서 선택 효과 표시
if (this.onDateSelect) this.onDateSelect(this.selectedDate);
};
});
}
};