-
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
9 changed files
with
277 additions
and
84 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/app/(withAuth)/problems/[problemId]/CheckpointProblem.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,99 @@ | ||
'use client'; | ||
|
||
import { Box, Button, Flex, HStack, VStack } from '@chakra-ui/react'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { SyntaxHighlighter } from '../../../../components/organisms/SyntaxHighlighter'; | ||
import type { TurtleGraphicsHandle } from '../../../../components/organisms/TurtleGraphics'; | ||
import { TurtleGraphics } from '../../../../components/organisms/TurtleGraphics'; | ||
import { generateProgram } from '../../../../problems/problemData'; | ||
import type { ProblemType } from '../../../../types'; | ||
import { getLanguageIdFromSessionStorage } from '../../../lib/SessionStorage'; | ||
|
||
interface CheckpointProblemProps { | ||
problemId: string; | ||
setStep: (step: ProblemType) => void; | ||
} | ||
|
||
export const CheckpointProblem: React.FC<CheckpointProblemProps> = ({ problemId }) => { | ||
const turtleGraphicsRef = useRef<TurtleGraphicsHandle>(null); | ||
const [selectedLanguageId, setSelectedLanguageId] = useState(''); | ||
|
||
// TODO: チェックポイントを取得する処理が実装できたら置き換える | ||
const getCheckPointLines = [2, 4]; | ||
const [problemProgram, setProblemProgram] = useState<string>(''); | ||
const [beforeCheckPointLine, setBeforeCheckPointLine] = useState(1); | ||
const [currentCheckPointLine, setCurrentCheckPointLine] = useState(getCheckPointLines[0]); | ||
|
||
useEffect(() => { | ||
setSelectedLanguageId(getLanguageIdFromSessionStorage()); | ||
}, []); | ||
|
||
useEffect(() => { | ||
setProblemProgram(generateProgram(problemId, selectedLanguageId)); | ||
}, [problemId, selectedLanguageId]); | ||
|
||
const handleClickResetButton = (): void => { | ||
turtleGraphicsRef.current?.init(); | ||
}; | ||
|
||
const handleClickAnswerButton = (): void => { | ||
const isCorrect = turtleGraphicsRef.current?.isCorrect(); | ||
|
||
// TODO: 一旦アラートで表示 | ||
if (isCorrect) { | ||
alert('正解です'); | ||
|
||
if (currentCheckPointLine === getCheckPointLines.at(-1)) return; | ||
|
||
setBeforeCheckPointLine(currentCheckPointLine); | ||
setCurrentCheckPointLine(getCheckPointLines[getCheckPointLines.indexOf(currentCheckPointLine) + 1]); | ||
} else { | ||
alert('不正解です'); | ||
// setStep('step'); | ||
} | ||
}; | ||
|
||
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> | ||
); | ||
}; |
65 changes: 65 additions & 0 deletions
65
src/app/(withAuth)/problems/[problemId]/ExecutionResultProblem.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,65 @@ | ||
'use client'; | ||
|
||
import { Box, Button, Flex, HStack, VStack } from '@chakra-ui/react'; | ||
import { useEffect, useState, useRef } from 'react'; | ||
|
||
import { SyntaxHighlighter } from '../../../../components/organisms/SyntaxHighlighter'; | ||
import type { TurtleGraphicsHandle } from '../../../../components/organisms/TurtleGraphics'; | ||
import { TurtleGraphics } from '../../../../components/organisms/TurtleGraphics'; | ||
import { generateProgram } from '../../../../problems/problemData'; | ||
import type { ProblemType } from '../../../../types'; | ||
import { getLanguageIdFromSessionStorage } from '../../../lib/SessionStorage'; | ||
|
||
interface ExecutionResultProblemProps { | ||
problemId: string; | ||
setStep: (step: ProblemType) => void; | ||
} | ||
|
||
export const ExecutionResultProblem: React.FC<ExecutionResultProblemProps> = ({ problemId, setStep }) => { | ||
const turtleGraphicsRef = useRef<TurtleGraphicsHandle>(null); | ||
const [selectedLanguageId, setSelectedLanguageId] = useState(''); | ||
|
||
useEffect(() => { | ||
setSelectedLanguageId(getLanguageIdFromSessionStorage()); | ||
}, []); | ||
|
||
const problemProgram = generateProgram(problemId, selectedLanguageId); | ||
|
||
const handleClickResetButton = (): void => { | ||
turtleGraphicsRef.current?.init(); | ||
}; | ||
|
||
const handleClickAnswerButton = (): void => { | ||
const isCorrect = turtleGraphicsRef.current?.isCorrect(); | ||
|
||
// TODO: 一旦アラートで表示 | ||
if (isCorrect) { | ||
alert('正解です'); | ||
} else { | ||
alert('不正解です'); | ||
setStep('checkpoint'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Flex gap="6" w="100%"> | ||
<VStack spacing="10"> | ||
<Box>プログラムの実行後の結果を解答してください。</Box> | ||
<Box> | ||
<TurtleGraphics ref={turtleGraphicsRef} isEnableOperation={true} problemProgram={problemProgram} /> | ||
</Box> | ||
</VStack> | ||
<VStack align="end" minW="50%" overflow="hidden"> | ||
<Button colorScheme="gray">解説</Button> | ||
{/* 画面に収まる高さに設定 */} | ||
<Box h="calc(100vh - 370px)" w="100%"> | ||
<SyntaxHighlighter code={problemProgram} 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
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
Oops, something went wrong.