-
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.
Merge branch 'main' into chore/rename-problem
# Conflicts: # src/app/(withAuth)/programs/[programId]/CheckpointProblem.tsx # src/app/(withAuth)/programs/[programId]/ExecutionResultProblem.tsx # src/app/(withAuth)/programs/[programId]/StepProblem.tsx # src/app/(withAuth)/programs/[programId]/page.tsx
- Loading branch information
Showing
5 changed files
with
189 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use client'; | ||
|
||
import { Box, Button, Flex, HStack, VStack } from '@chakra-ui/react'; | ||
import { useRef } from 'react'; | ||
|
||
import { SyntaxHighlighter } from '../../../../components/organisms/SyntaxHighlighter'; | ||
import type { TurtleGraphicsHandle } from '../../../../components/organisms/TurtleGraphics'; | ||
import { TurtleGraphics } from '../../../../components/organisms/TurtleGraphics'; | ||
|
||
interface StepProblemProps { | ||
beforeCheckPointLine: number; | ||
currentCheckPointLine: number; | ||
problemProgram: string; | ||
selectedLanguageId: string; | ||
setBeforeCheckPointLine: (line: number) => void; | ||
setCurrentCheckPointLine: (line: number) => void; | ||
} | ||
|
||
export const StepProblem: React.FC<StepProblemProps> = ({ | ||
beforeCheckPointLine, | ||
currentCheckPointLine, | ||
problemProgram, | ||
selectedLanguageId, | ||
setBeforeCheckPointLine, | ||
setCurrentCheckPointLine, | ||
}) => { | ||
const turtleGraphicsRef = useRef<TurtleGraphicsHandle>(null); | ||
|
||
const handleClickResetButton = (): void => { | ||
turtleGraphicsRef.current?.init(); | ||
}; | ||
|
||
const handleClickAnswerButton = (): void => { | ||
const isCorrect = turtleGraphicsRef.current?.isCorrect(); | ||
|
||
// TODO: 一旦アラートで表示 | ||
if (isCorrect) { | ||
const problemProgramLines = problemProgram.split('\n').length; | ||
|
||
if (currentCheckPointLine === problemProgramLines) { | ||
alert('正解です。この問題は終了です'); | ||
} else { | ||
alert('正解です。次の行に進みます'); | ||
setBeforeCheckPointLine(currentCheckPointLine); | ||
setCurrentCheckPointLine(currentCheckPointLine + 1); | ||
} | ||
} else { | ||
alert('不正解です。もう一度回答してください'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Flex gap="6" w="100%"> | ||
<VStack spacing="10"> | ||
<Box>茶色にハイライトされている行における盤面を作成してください。</Box> | ||
<Box>青色のハイライト時点の実行結果</Box> | ||
<Box> | ||
<TurtleGraphics | ||
ref={turtleGraphicsRef} | ||
beforeCheckPointLine={beforeCheckPointLine} | ||
currentCheckPointLine={currentCheckPointLine} | ||
isEnableOperation={false} | ||
problemProgram={problemProgram} | ||
/> | ||
</Box> | ||
<Box>茶色のハイライト時点の実行結果</Box> | ||
<Box> | ||
<TurtleGraphics | ||
ref={turtleGraphicsRef} | ||
beforeCheckPointLine={beforeCheckPointLine} | ||
currentCheckPointLine={currentCheckPointLine} | ||
isEnableOperation={true} | ||
problemProgram={problemProgram} | ||
/> | ||
</Box> | ||
</VStack> | ||
<VStack align="end" minW="50%" overflow="hidden"> | ||
<Button colorScheme="gray">解説</Button> | ||
<Box h="840px" w="100%"> | ||
<SyntaxHighlighter | ||
beforeCheckPointLine={beforeCheckPointLine} | ||
code={problemProgram} | ||
currentCheckPointLine={currentCheckPointLine} | ||
programmingLanguageId={selectedLanguageId} | ||
/> | ||
</Box> | ||
<HStack> | ||
<Button onClick={() => handleClickResetButton()}>リセット</Button> | ||
<Button onClick={() => handleClickAnswerButton()}>解答</Button> | ||
</HStack> | ||
</VStack> | ||
</Flex> | ||
); | ||
}; |
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