mirror of
https://github.com/sotam0316/brain_dogfood.git
synced 2026-04-25 03:48:38 +09:00
Fix date filtering bug in heatmap/calendar and sync selection state
This commit is contained in:
@@ -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);
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user