This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
484 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/routes/_procted+/grade+/$lectureId+/$practiceId+/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { useParams } from "@remix-run/react"; | ||
import { ReactNode, useEffect, useState } from "react"; | ||
import { getPracticeWithPracticeId } from "~/API/practice"; | ||
import { getPracticeScoreBoard } from "~/API/submission"; | ||
import { useAuth } from "~/contexts/AuthContext"; | ||
import styles from "../index.module.css"; | ||
import TableBase from "~/components/Table/TableBase"; | ||
|
||
const PracticeScoreBoard = () => { | ||
const params = useParams(); | ||
const auth = useAuth(); | ||
const [practiceName, setPracticeName] = useState(""); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [data, setData] = useState<any>({}); | ||
const [dataHeaders, setDataHeaders] = useState<ReactNode[]>(["이름", "총점"]); | ||
|
||
useEffect(() => { | ||
async function getPracticeName() { | ||
const response = await getPracticeWithPracticeId( | ||
params.practiceId!, | ||
auth.token | ||
); | ||
if (response.status === 200) { | ||
setPracticeName((response as any).data.name); | ||
} | ||
} | ||
getPracticeName(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
async function getPracticeScore() { | ||
const response = await getPracticeScoreBoard( | ||
auth.token, | ||
params.practiceId! | ||
); | ||
if (response.status === 200) { | ||
response.data.metadata.map((data: any) => { | ||
setDataHeaders((prev) => [ | ||
...prev, | ||
<button | ||
className={styles["white-button"]} | ||
onClick={() => alert("재채점 API호출 예정")} | ||
>{`${data.title} (${data.score})`}</button>, | ||
]); | ||
}); | ||
} | ||
setData( | ||
response.data.users.map((user: any) => { | ||
const map = new Map<string, ReactNode>(); | ||
map.set("userName", user.name); | ||
map.set("totalScore", user.total_score); | ||
user.scores.map((score: any, idx: number) => { | ||
map.set( | ||
`problemNo${idx}`, | ||
<button | ||
className={styles["white-button"]} | ||
onClick={() => alert("문제 재채점 API호출 예정")} | ||
> | ||
{score} | ||
</button> | ||
); | ||
}); | ||
return map; | ||
}) | ||
); | ||
setIsLoading(false); | ||
} | ||
getPracticeScore(); | ||
}, []); | ||
|
||
return isLoading ? ( | ||
<h2>Loading...</h2> | ||
) : ( | ||
<TableBase | ||
gridTemplateColumns={`150px 150px ${"200px ".repeat( | ||
dataHeaders.length | ||
)} `} | ||
dataHeaders={dataHeaders as ReactNode[]} | ||
dataRows={data} | ||
/> | ||
); | ||
}; | ||
|
||
export default PracticeScoreBoard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useEffect, useState } from "react"; | ||
import styles from "./index.module.css"; | ||
import { Outlet, useParams } from "@remix-run/react"; | ||
import { getLectureWithLectureId } from "~/API/lecture"; | ||
import { useAuth } from "~/contexts/AuthContext"; | ||
import { ButtonElement } from "~/components/Aside/ButtonElement"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const ScoreBoardLayout = () => { | ||
const params = useParams(); | ||
const auth = useAuth(); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [practiceList, setPracticeList] = useState([]); | ||
useEffect(() => { | ||
async function getPractices() { | ||
const response = await getLectureWithLectureId( | ||
params.lectureId!, | ||
auth.token | ||
); | ||
if (response.status === 200) { | ||
setPracticeList((response as any).data.practices); | ||
setIsLoading(false); | ||
} | ||
} | ||
getPractices(); | ||
}, []); | ||
return isLoading ? ( | ||
<h1>Loading...</h1> | ||
) : ( | ||
<div className={styles.container}> | ||
<div className={styles.sidebar}> | ||
<Link to={`/grade/${params.lectureId}`}> | ||
<ButtonElement title={"실습 전체 보기"} onButtonClick={() => {}} /> | ||
</Link> | ||
{practiceList.map((practice: any, idx: number) => ( | ||
<Link to={`/grade/${params.lectureId}/${practice.id}`}> | ||
<ButtonElement | ||
title={practice.title} | ||
key={practice.id} | ||
onButtonClick={() => {}} | ||
/> | ||
</Link> | ||
))} | ||
</div> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScoreBoardLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.white-button { | ||
all: unset; | ||
cursor: pointer; | ||
padding: 10px 16px; | ||
border-radius: 8px; | ||
border: 1px solid #d0d5dd; | ||
background: #fff; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 8px; | ||
font-size: 14px; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
gap: 40px; | ||
} | ||
|
||
.sidebar { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.sidebar * { | ||
text-decoration: none; | ||
} |
Oops, something went wrong.