Skip to content

Commit a548643

Browse files
authored
Merge pull request #98 from DMU-DebugVisual/inseong
시각화 복잡도 패널 추가 및 알림 요청 개선, 403 자동 로그아웃 처리
2 parents ce1086c + 87d4340 commit a548643

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/api/globalFetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ window.fetch = async (...args) => {
88
// 3. 백업해둔 원래 fetch 함수를 호출하여 실제 API 요청을 보냅니다.
99
const response = await originalFetch(...args);
1010

11-
// 4. 응답을 받은 후, 만약 401 에러(토큰 만료)가 발생했다면
12-
if (response.status === 401) {
11+
// 4. 응답을 받은 후, 인증 실패(401/403)가 발생했다면
12+
if (response.status === 401 || response.status === 403) {
1313
// 이전에 localStorage에 저장된 토큰이 있을 때만 로그아웃 처리
1414
if (localStorage.getItem('token')) {
1515
localStorage.removeItem('token');

src/components/header/Header.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react";
1+
import React, { useState, useEffect, useCallback } from "react";
22
import { NavLink, Link, useNavigate, useLocation } from "react-router-dom";
33
import { FaMoon, FaSun, FaUserCircle, FaBell } from "react-icons/fa";
44
import "./Header.css";
@@ -18,7 +18,7 @@ const Header = ({ isDark, setIsDark, isLoggedIn, nickname, onLoginModalOpen }) =
1818
const navigate = useNavigate();
1919
const location = useLocation();
2020

21-
const fetchNotifications = async () => {
21+
const fetchNotifications = useCallback(async () => {
2222
if (!isLoggedIn) return;
2323
try {
2424
const token = localStorage.getItem('token');
@@ -44,19 +44,16 @@ const Header = ({ isDark, setIsDark, isLoggedIn, nickname, onLoginModalOpen }) =
4444
} catch (error) {
4545
console.error("Error fetching notifications:", error);
4646
}
47-
};
47+
}, [isLoggedIn]);
4848

4949
useEffect(() => {
5050
if (isLoggedIn) {
5151
fetchNotifications();
52-
53-
const intervalId = setInterval(() => {
54-
fetchNotifications();
55-
}, 10000);
56-
57-
return () => clearInterval(intervalId);
52+
} else {
53+
setNotifications([]);
54+
setUnreadCount(0);
5855
}
59-
}, [isLoggedIn]);
56+
}, [isLoggedIn, fetchNotifications]);
6057

6158
const toggleNotificationMenu = () => {
6259
setIsNotificationMenuOpen(!isNotificationMenuOpen);

src/components/ide/VisualizationModal.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ const InfoPanel = ({ data, currentStep, totalSteps, theme }) => {
324324
);
325325

326326
const currentEvent = data?.events?.[currentStep];
327+
const analysis = data?.analysis ?? null;
328+
const complexityItems = [
329+
{ label: '시간 복잡도', value: analysis?.timeComplexity || '-' },
330+
{ label: '공간 복잡도', value: analysis?.spaceComplexity || '-' }
331+
];
332+
const hasComplexityData = complexityItems.some(item => item.value && item.value !== '-');
327333

328334
return (
329335
<div style={{
@@ -378,6 +384,26 @@ const InfoPanel = ({ data, currentStep, totalSteps, theme }) => {
378384
))}
379385
</div>
380386
</InfoCard>
387+
388+
{hasComplexityData && (
389+
<InfoCard title="알고리즘 복잡도" icon="🧠">
390+
<div style={{ display: 'flex', flexDirection: 'column', gap: '6px' }}>
391+
{complexityItems.map((item, index) => (
392+
<div key={index} style={{
393+
display: 'flex',
394+
justifyContent: 'space-between',
395+
padding: '6px 8px',
396+
background: theme.colors.cardSecondary,
397+
borderRadius: '6px',
398+
fontSize: '12px'
399+
}}>
400+
<span style={{ color: theme.colors.textLight }}>{item.label}:</span>
401+
<span style={{ fontWeight: '600', color: theme.colors.text }}>{item.value}</span>
402+
</div>
403+
))}
404+
</div>
405+
</InfoCard>
406+
)}
381407
</div>
382408
);
383409
};

0 commit comments

Comments
 (0)