Skip to content

Commit

Permalink
Merge pull request #56 from Line4Thon-Nugu/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
sayyyho authored Nov 14, 2024
2 parents e060d62 + 194a7c9 commit c2d0600
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
17 changes: 11 additions & 6 deletions src/apis/nuguTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { instance } from "./instance";
export const getNuguTestStatus = async () => {
try {
const response = await instance.get("/tests/status");
console.log(response);
if (response.data.hasTest) {
// TODO 수행한 인원 및 기타 작업
return true;
}
return false;
return response.data;
} catch (err) {
console.error("테스트 상태 확인 중 오류가 발생했습니다:", err);
throw err;
}
};

export const getNuguTestRanking = async () => {
try {
const response = await instance.get("/test-results/rankings");
return response.data;
} catch (err) {
console.log(err);
}
};
2 changes: 1 addition & 1 deletion src/atoms/nuguTestState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { atom } from "recoil";

export const isMakeTestOwner = atom({
key: "isMakeTestOwner",
default: "",
default: false,
});
20 changes: 19 additions & 1 deletion src/components/nuguTest/NuguTestTrue.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
//소유자가 테스트를 만듦 & 테스트를 진행한 사람이 존재
import * as S from "./styled";

import { useEffect, useState } from "react";

import { NuguTestRanking } from "@components/nuguTestRanking/NuguTestRanking";
export const NuguTestTrue = ({ username, ranking }) => {

import { getNuguTestRanking } from "@apis/nuguTest";

export const NuguTestTrue = ({ username }) => {
const [ranking, setRanking] = useState([]);
useEffect(() => {
const fetchRanking = async () => {
try {
const data = await getNuguTestRanking();
setRanking(data);
} catch (err) {
console.log(err);
}
};
fetchRanking();
}, []);
return (
<S.UserRankWrapper>
<S.UserTextWrapper>
Expand Down
45 changes: 11 additions & 34 deletions src/pages/nuguTest/NuguTest.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//소유자뷰- 누구테스트 홈
import * as S from "./styled";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Layout } from "@components/common/layout/Layout";
import { NavigateBar } from "@components/common/navigateBar/NavigateBar";
Expand All @@ -10,68 +9,46 @@ import { Button } from "@components/common/button/Button";
import { NuguTestTrue } from "@components/nuguTest/NuguTestTrue";
import { isMakeTestOwner } from "@atoms/nuguTestState";
import { useRecoilState } from "recoil";

import { getNuguTestStatus } from "@apis/nuguTest";
import Cookies from "js-cookie";

//토큰 여부로 워딩 다르게 표현
export const NuguTestPage = () => {
const [isMakeTest, setIsMakeTest] = useRecoilState(isMakeTestOwner);
const [participants, setParticipants] = useState(0);
const navigate = useNavigate();
//test

useEffect(() => {
const fetchTestStatus = async () => {
try {
const hasTest = await getNuguTestStatus();
//누구 테스트 사용자-get
setIsMakeTest(hasTest);
const data = await getNuguTestStatus();
setIsMakeTest(data.hasTest);
setParticipants(Number(data.totalParticipants));
} catch (error) {
console.error("실패", error);
}

fetchTestStatus();
};

fetchTestStatus();
}, []);

const moveOnTest = () => {
navigate("/test/make");
};

const array = [
// {
// nickname: "응시자3",
// correctAnswers: 9,
// rank: 1,
// totalParticipants: 3,
// },
// {
// nickname: "응시자1",
// correctAnswers: 7,
// rank: 2,
// totalParticipants: 3,
// },
// {
// nickname: "응시자2",
// correctAnswers: 7,
// rank: 2,
// totalParticipants: 3,
// },
];

return (
<Layout $margin="3rem 0 0 0" $justifyContent="start">
<NavigateBar />
<S.TestContainer>
{isMakeTest ? (
array.length === 0 ? (
participants === 0 ? (
<NuguTestNone isTestOwner={true} />
) : (
<NuguTestTrue username={Cookies.get("nickname")} ranking={array} />
<NuguTestTrue username={Cookies.get("nickname")} />
)
) : (
<>
<NuguTestHome username={Cookies.get("nickname")} isOwner={true} />
<Button disabled={false} onClick={() => moveOnTest()}>
<Button disabled={false} onClick={moveOnTest}>
누구테스트 만들러 가기
</Button>
</>
Expand Down

0 comments on commit c2d0600

Please sign in to comment.