Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import request from '../../Api/request';
import axios from 'axios';

export default function DailyChallenge() {
const location = useLocation();
const navigate = useNavigate();
const accessToken = localStorage.getItem("accessToken");

Expand All @@ -19,9 +18,7 @@ export default function DailyChallenge() {
const [showLevel, setShowLevel] = useState(false);
const [tierSrc, setTierSrc] = useState('https://static.solved.ac/tier_small/0.svg');
const [challengeData, setChallengeData] = useState(null);
const [hasLoadedChallengeData, setHasLoadedChallengeData] = useState(false);
const [participantsCount, setParticipantsCount] = useState(0);
const [hasJoinedToday, setHasJoinedToday] = useState(false);
const [challengeHistory, setChallengeHistory] = useState([]);

const msToHHMMSS = (ms) => {
Expand Down Expand Up @@ -62,24 +59,6 @@ export default function DailyChallenge() {

const isOneHourLeft = timeLeftMs <= 3600 * 1000;

/*
// 금일 챌린지 참여 여부 확인
const checkTodayJoinStatus = async () => {
if (!accessToken) return;

try {
const response = await request.get('/challenge/check-join');
if (response.isSuccess && response.result) {
setHasJoinedToday(true);
// 참여했다면 챌린지 이력도 조회
await loadChallengeHistory();
}
} catch (error) {
console.error('챌린지 참여 여부 확인 실패:', error);
}
};
*/

// 챌린지 이력 조회
const loadChallengeHistory = async () => {
try {
Expand All @@ -99,17 +78,9 @@ export default function DailyChallenge() {

console.log("챌린지 이력 조회 성공:", result);

// 참여 인원 수 세팅
setParticipantsCount(totalCount);

// totalCount가 0보다 크면 참여 이력 있다고 판단
if (totalCount > 0 && joinLogList.length > 0) {
setHasJoinedToday(true);
setChallengeHistory(joinLogList);
} else {
setHasJoinedToday(false);
setChallengeHistory([]);
}
setChallengeHistory(joinLogList);

} catch (error) {
console.error("챌린지 이력 조회 실패:", error);
}
Expand All @@ -128,7 +99,6 @@ export default function DailyChallenge() {
useEffect(() => {
const msToMidnight = getMsToMidnight();

// 자정에 새로고침
const midnightTimer = setTimeout(() => {
window.location.reload();
}, msToMidnight);
Expand All @@ -140,6 +110,7 @@ export default function DailyChallenge() {

// 컴포넌트 마운트 시 참여 여부 확인
useEffect(() => {
loadChallengeData();
loadChallengeHistory();
}, []);

Expand All @@ -160,12 +131,8 @@ export default function DailyChallenge() {

// 챌린지 데이터 로드 (한 번만 호출)
const loadChallengeData = async () => {

// 비로그인이라면 로드하지 않음
if (!accessToken) return null;

// 이미 로드되어 있다면 캐시 반환
if (hasLoadedChallengeData && challengeData) {
if (challengeData) {
return challengeData;
}

Expand All @@ -179,14 +146,9 @@ export default function DailyChallenge() {
levelImageUrl: response.result.levelImageUrl,
algorithmList: response.result.algorithmList || [],
}
// 챌린지 데이터 저장
setChallengeData(data);
setHasLoadedChallengeData(true);

return data;
}


} catch (error) {
console.error('금일 챌린지 문제 조회 실패:', error);
} finally {
Expand All @@ -196,23 +158,20 @@ export default function DailyChallenge() {

// 문제풀기 버튼 클릭
const handleProblemSolve = async () => {
// 로그인 상태 확인
if (!accessToken) {
navigate('/login');
return;
}

const data = await loadChallengeData();

// 데이터가 있으면 백준 링크 열기
if (data) {
const bojLink = `https://www.acmicpc.net/problem/${data.problemNumber}`;
window.open(bojLink, '_blank');
}
};

const handleTagToggle = async () => {
// 로그인 상태 확인
if (!accessToken) {
navigate('/login');
return;
Expand All @@ -221,11 +180,10 @@ export default function DailyChallenge() {
await loadChallengeData();

setShowTags((v) => !v);
setShowLevel(false); // 다른 펼쳐진 요소 접기
setShowLevel(false);
};

const handleTierToggle = async () => {
// 로그인 상태 확인
if (!accessToken) {
navigate('/login');
return;
Expand All @@ -234,7 +192,7 @@ export default function DailyChallenge() {
await loadChallengeData();

setShowLevel((v) => !v);
setShowTags(false); // 다른 펼쳐진 요소 접기
setShowTags(false);
};


Expand Down Expand Up @@ -293,7 +251,6 @@ export default function DailyChallenge() {
</Styled.ProblemInfoContainer>
</Styled.TitleContainer>
<Ranking
disable={!hasJoinedToday}
challengeHistory={challengeHistory}
/>
</Styled.Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import RankingTuple from './DailyChallenge.dailychallenge.tuple';
import rankingData from "./dummyRanking.js";

const DEFAULT_ROWS = [
{ rank: "1", name: "홍길동", speed: "0ms", memory: "0KB", codeLength: "1000B" },
{ rank: "2", name: "홍길동", speed: "0ms", memory: "0KB", codeLength: "2000B" },
{ rank: "3", name: "홍길동", speed: "0ms", memory: "0KB", codeLength: "3000B" },
{ rank: "1", name: "이유경", speed: "0ms", memory: "0KB", codeLength: "1000B" },
{ rank: "2", name: "이육영", speed: "0ms", memory: "0KB", codeLength: "2000B" },
{ rank: "3", name: "이규영", speed: "0ms", memory: "0KB", codeLength: "3000B" },
];

export default function RankingTable({ disable, language, date, challengeHistory = [] }) {
export default function RankingTable({ language, date, challengeHistory = [] }) {

const hasRecordForDate = challengeHistory.some(item => item.date === date);
const isDisabled = !hasRecordForDate;

if (disable) {
if (isDisabled) {
return (
<itemS.Container>
<itemS.Table>
Expand Down Expand Up @@ -92,7 +95,7 @@ export default function RankingTable({ disable, language, date, challengeHistory
key={`${item.name}-${item.rank}-${index}`}
item={item}
language={language}
disable={disable}
disable={false}
/>
))}
</itemS.Table>
Expand Down
Loading