-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
143 additions
and
11 deletions.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
packages/frontend/src/components/quiz/CommandAccordion/CommandAccordion.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
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
24 changes: 24 additions & 0 deletions
24
packages/frontend/src/components/quiz/QuizGuide/QuizGuide.css.ts
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,24 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
|
||
import color from "../../../design-system/tokens/color"; | ||
import { flexColumn } from "../../../design-system/tokens/utils.css"; | ||
|
||
const containerPadding = 23; | ||
|
||
export const quizContentContainer = style([ | ||
flexColumn, | ||
{ | ||
position: "relative", | ||
width: "50%", | ||
height: "400px", | ||
borderLeft: `1px solid ${color.$semantic.border}`, | ||
padding: containerPadding, | ||
gap: 12, | ||
}, | ||
]); | ||
|
||
export const checkAnswerButton = style({ | ||
position: "absolute", | ||
right: containerPadding, | ||
bottom: containerPadding, | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/frontend/src/components/quiz/QuizGuide/QuizGuide.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,22 @@ | ||
import { Button } from "../../../design-system/components/common"; | ||
import { Quiz } from "../../../types/quiz"; | ||
import CommandAccordion from "../CommandAccordion"; | ||
import QuizContent from "../QuizContent"; | ||
|
||
import * as styles from "./QuizGuide.css"; | ||
|
||
export function QuizGuide({ quiz }: { quiz: Quiz }) { | ||
return ( | ||
<div className={styles.quizContentContainer}> | ||
<QuizContent | ||
category={quiz.category} | ||
title={quiz.title} | ||
description={quiz.description} | ||
/> | ||
<CommandAccordion width="100%" items={quiz.keywords} /> | ||
<Button className={styles.checkAnswerButton} variant="secondaryFill"> | ||
모범 답안 확인하기 | ||
</Button> | ||
</div> | ||
); | ||
} |
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 @@ | ||
export { QuizGuide } from "./QuizGuide"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import axios from "axios"; | ||
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from "next"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import { quizAPI } from "../../apis/quiz"; | ||
import { QuizGuide } from "../../components/quiz/QuizGuide"; | ||
import { Terminal } from "../../components/terminal"; | ||
import { Button } from "../../design-system/components/common"; | ||
import { Categories, Quiz } from "../../types/quiz"; | ||
import { TerminalContentType } from "../../types/terminalType"; | ||
import { isString } from "../../utils/typeGuard"; | ||
|
||
import * as styles from "./quiz.css"; | ||
|
||
export default function QuizPage({ quiz }: { quiz: Quiz }) { | ||
const [contentArray, setContentArray] = useState<TerminalContentType[]>([]); | ||
const { | ||
query: { id }, | ||
} = useRouter(); | ||
|
||
useEffect(() => { | ||
setContentArray([]); | ||
}, [id]); | ||
|
||
const handleTerminal = async (input: string) => { | ||
if (!isString(id)) { | ||
return; | ||
} | ||
|
||
const data = await quizAPI.postCommand({ | ||
id: +id, | ||
command: input, | ||
}); | ||
setContentArray([ | ||
...contentArray, | ||
{ type: "stdin", content: input }, | ||
{ type: "stdout", content: data.message }, | ||
]); | ||
}; | ||
|
||
if (!quiz) return null; | ||
return ( | ||
<main className={styles.mainContainer}> | ||
<div className={styles.topContainer}> | ||
<div style={{ width: "50%", display: "flex" }}>git graph</div> | ||
<QuizGuide quiz={quiz} /> | ||
</div> | ||
<Terminal contentArray={contentArray} onTerminal={handleTerminal} /> | ||
<Button variant="primaryFill">제출 후 채점하기</Button> | ||
</main> | ||
); | ||
} | ||
|
||
export const getStaticProps = (async ({ params }: GetStaticPropsContext) => { | ||
const { data } = await axios.get<Quiz>( | ||
`https://git-challenge.com/api/v1/quizzes/${params?.id}`, | ||
); | ||
|
||
return { | ||
props: { | ||
quiz: data, | ||
}, | ||
}; | ||
}) satisfies GetStaticProps<{ | ||
quiz: Quiz; | ||
}>; | ||
|
||
export const getStaticPaths = (async () => { | ||
const { | ||
data: { categories }, | ||
} = await axios.get<Categories>("https://git-challenge.com/api/v1/quizzes"); | ||
|
||
const paths = categories.flatMap(({ quizzes }) => | ||
quizzes.map(({ id }) => ({ params: { id: String(id) } })), | ||
); | ||
|
||
return { paths, fallback: "blocking" }; | ||
}) satisfies GetStaticPaths; |
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,7 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
|
||
import { border, flex, widthFull } from "../../design-system/tokens/utils.css"; | ||
|
||
export const mainContainer = style([widthFull]); | ||
|
||
export const topContainer = style([flex, border.verticalSide]); |