Skip to content

Commit d5d8a5c

Browse files
committed
feat: 상세페이지 데이터 사용량 10초 polling 추가
1 parent f1b30f4 commit d5d8a5c

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/page/Detail/DetailPage.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,28 @@ export default function Detail() {
189189
// eslint-disable-next-line react-hooks/exhaustive-deps
190190
}, [lineId, currentDate]);
191191

192+
// 데이터 사용량 polling (현재 달일 때만 30초 간격)
193+
useEffect(() => {
194+
const isCurrentMonth =
195+
currentDate.getFullYear() === today.getFullYear() &&
196+
currentDate.getMonth() === today.getMonth();
197+
198+
if (!lineId || !isCurrentMonth) return;
199+
200+
const interval = setInterval(async () => {
201+
try {
202+
const yearMonth = formatYearMonth(currentDate);
203+
const dataRes = await userService.getDataUsage(lineId, yearMonth);
204+
setDataUsage(dataRes.data);
205+
} catch {
206+
// polling 실패는 무시
207+
}
208+
}, 10000);
209+
210+
return () => clearInterval(interval);
211+
// eslint-disable-next-line react-hooks/exhaustive-deps
212+
}, [lineId, currentDate]);
213+
192214
const fetchMonthData = async (newDate: Date) => {
193215
const yearMonth = formatYearMonth(newDate);
194216

0 commit comments

Comments
 (0)