diff --git a/src/app/(withAuth)/courses/[courseId]/programs/[programId]/CheckpointProblem.tsx b/src/app/(withAuth)/courses/[courseId]/programs/[programId]/CheckpointProblem.tsx index 78cd19af..705cc8a7 100644 --- a/src/app/(withAuth)/courses/[courseId]/programs/[programId]/CheckpointProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/programs/[programId]/CheckpointProblem.tsx @@ -1,8 +1,9 @@ 'use client'; -import { Box, Button, Flex, HStack, VStack } from '@chakra-ui/react'; +import { Box, Button, Flex, HStack, VStack, useDisclosure } from '@chakra-ui/react'; import { useRef } from 'react'; +import { CustomModal } from '../../../../../../components/molecules/CustomModal'; import { SyntaxHighlighter } from '../../../../../../components/organisms/SyntaxHighlighter'; import type { TurtleGraphicsHandle } from '../../../../../../components/organisms/TurtleGraphics'; import { TurtleGraphics } from '../../../../../../components/organisms/TurtleGraphics'; @@ -12,20 +13,22 @@ import { solveProblem } from '../../../../../lib/solveProblem'; import { Variables } from './Variables'; interface CheckpointProblemProps { + beforeCheckPointLine: number; + checkPointLines: number[]; + currentCheckPointLine: number; + explanation?: Record<'title' | 'body', string>; problemProgram: string; selectedLanguageId: string; - checkPointLines: number[]; - setStep: (step: ProblemType) => void; - beforeCheckPointLine: number; setBeforeCheckPointLine: (line: number) => void; - currentCheckPointLine: number; setCurrentCheckPointLine: (line: number) => void; + setStep: (step: ProblemType) => void; } export const CheckpointProblem: React.FC = ({ beforeCheckPointLine, checkPointLines, currentCheckPointLine, + explanation, problemProgram, selectedLanguageId, setBeforeCheckPointLine, @@ -34,6 +37,7 @@ export const CheckpointProblem: React.FC = ({ }) => { const turtleGraphicsRef = useRef(null); + const { isOpen, onClose, onOpen } = useDisclosure(); const beforeCheckpointResult = solveProblem(problemProgram).histories?.at(beforeCheckPointLine); const handleClickResetButton = (): void => { @@ -90,7 +94,14 @@ export const CheckpointProblem: React.FC = ({ - + {explanation && ( + <> + + + + )} ; + handleComplete: () => void; problemProgram: string; selectedLanguageId: string; setStep: (step: ProblemType) => void; - handleComplete: () => void; } export const ExecutionResultProblem: React.FC = ({ + explanation, handleComplete, problemProgram, selectedLanguageId, setStep, }) => { const turtleGraphicsRef = useRef(null); + const { isOpen, onClose, onOpen } = useDisclosure(); const handleClickResetButton = (): void => { turtleGraphicsRef.current?.init(); @@ -49,7 +53,14 @@ export const ExecutionResultProblem: React.FC = ({ - + {explanation && ( + <> + + + + )} {/* 画面に収まる高さに設定 */} diff --git a/src/app/(withAuth)/courses/[courseId]/programs/[programId]/StepProblem.tsx b/src/app/(withAuth)/courses/[courseId]/programs/[programId]/StepProblem.tsx index 90d068bd..2a56e370 100644 --- a/src/app/(withAuth)/courses/[courseId]/programs/[programId]/StepProblem.tsx +++ b/src/app/(withAuth)/courses/[courseId]/programs/[programId]/StepProblem.tsx @@ -1,8 +1,9 @@ 'use client'; -import { Box, Button, Flex, HStack, VStack } from '@chakra-ui/react'; +import { Box, Button, Flex, HStack, VStack, useDisclosure } from '@chakra-ui/react'; import { useRef } from 'react'; +import { CustomModal } from '../../../../../../components/molecules/CustomModal'; import { SyntaxHighlighter } from '../../../../../../components/organisms/SyntaxHighlighter'; import type { TurtleGraphicsHandle } from '../../../../../../components/organisms/TurtleGraphics'; import { TurtleGraphics } from '../../../../../../components/organisms/TurtleGraphics'; @@ -13,16 +14,18 @@ import { Variables } from './Variables'; interface StepProblemProps { beforeCheckPointLine: number; currentCheckPointLine: number; + explanation?: Record<'title' | 'body', string>; + handleComplete: () => void; problemProgram: string; selectedLanguageId: string; setBeforeCheckPointLine: (line: number) => void; setCurrentCheckPointLine: (line: number) => void; - handleComplete: () => void; } export const StepProblem: React.FC = ({ beforeCheckPointLine, currentCheckPointLine, + explanation, handleComplete, problemProgram, selectedLanguageId, @@ -30,6 +33,7 @@ export const StepProblem: React.FC = ({ setCurrentCheckPointLine, }) => { const turtleGraphicsRef = useRef(null); + const { isOpen, onClose, onOpen } = useDisclosure(); const beforeCheckpointResult = solveProblem(problemProgram).histories?.at(beforeCheckPointLine); @@ -83,7 +87,14 @@ export const StepProblem: React.FC = ({ - + {explanation && ( + <> + + + + )} } }; + const explanation = getExplanation(programId, selectedLanguageId); + const ProblemComponent: React.FC = () => { switch (step) { case 'normal': { return ( beforeCheckPointLine={beforeCheckPointLine} checkPointLines={checkPointLines} currentCheckPointLine={currentCheckPointLine} + explanation={explanation} problemProgram={problemProgram} selectedLanguageId={selectedLanguageId} setBeforeCheckPointLine={setBeforeCheckPointLine} @@ -73,6 +77,7 @@ const ProblemPage: NextPage<{ params: { courseId: string; programId: string } }> void; +} + +export const CustomModal: React.FC = ({ body, isOpen, onClose, title }) => { + return ( + <> + + + + {title} + + {body} + + + + + + + ); +}; diff --git a/src/problems/problemData.ts b/src/problems/problemData.ts index a131a84a..078bc550 100644 --- a/src/problems/problemData.ts +++ b/src/problems/problemData.ts @@ -53,8 +53,8 @@ turtle.moveForward();` || programIdToLanguageIdToProgram[programId][languageId] ); } -export function getExplanation(programId: ProgramId, languageId: LanguageId): string { - return programIdToLanguageIdToExplanation[programId][languageId]; +export function getExplanation(programId: ProgramId, languageId: LanguageId): Record<'title' | 'body', string> { + return programIdToLanguageIdToExplanation[programId]?.[languageId]; } export const programIdToLanguageIdToProgram: Record> = { @@ -92,21 +92,40 @@ public class Curve { }, }; -export const programIdToLanguageIdToExplanation: Record> = { +export const programIdToLanguageIdToExplanation: Record< + ProgramId, + Record> +> = { straight: { - js: ` -JavaScript向けの解説。JavaScript向けの解説。 + js: { + title: 'JavaScript向けstraightの解説のタイトル', + body: ` +JavaScript向けstraightの解説 +解説文がここに入ります。 `.trim(), - java: ` -Java向けの解説。Java向けの解説。 + }, + java: { + title: 'Java向けstraightの解説のタイトル', + body: ` +Java向けstraightの解説 +解説文がここに入ります。 `.trim(), + }, }, curve: { - js: ` -JavaScript向けの解説。JavaScript向けの解説。 + js: { + title: 'JavaScript向けcurveの解説のタイトル', + body: ` +JavaScript向けcurveの解説 +解説文がここに入ります。 `.trim(), - java: ` -Java向けの解説。Java向けの解説。 + }, + java: { + title: 'Java向けcurveの解説のタイトル', + body: ` +Java向けcurveの解説 +解説文がここに入ります。 `.trim(), + }, }, };