11import { Tab , TabList , Tabs } from "@chakra-ui/react" ;
22import { css } from "@emotion/react" ;
33import styled from "@emotion/styled" ;
4- import { FC , useState } from "react" ;
4+ import { FC , useMemo , useState } from "react" ;
55import { useRecoilValue } from "recoil" ;
66
77import useTestcaseCommand from "@/commands/useTestcaseCommand" ;
8+ import useTestcaseRunner from "@/commands/useTestcaseRunner" ;
89import { testcaseFamily , TestcaseID } from "@/states/testcase" ;
910
1011import AnswerEditor from "./AnswerEditor" ;
@@ -18,31 +19,39 @@ interface TestcasePanelProps {
1819
1920const TestcasePanel : FC < TestcasePanelProps > = ( { testcaseId } ) => {
2021 const testcaseCommand = useTestcaseCommand ( ) ;
22+ const runner = useTestcaseRunner ( ) ;
2123 const testcase = useRecoilValue ( testcaseFamily ( testcaseId ) ) ;
2224
2325 const [ selectedTabIndex , setSelectedTabIndex ] = useState ( 0 ) ;
2426
25- const tabs = [
26- {
27- title : "입력" ,
28- content : (
29- < InputEditor value = { testcase . input } onChange = { ( input ) => testcaseCommand . changeValue ( testcaseId , { input } ) } />
30- ) ,
31- } ,
32- {
33- title : "정답" ,
34- content : (
35- < AnswerEditor
36- value = { testcase . answer }
37- onChange = { ( answer ) => testcaseCommand . changeValue ( testcaseId , { answer } ) }
38- />
39- ) ,
40- } ,
41- {
42- title : "출력결과" ,
43- content : < Result testcaseId = { testcaseId } /> ,
44- } ,
45- ] ;
27+ const tabs = useMemo (
28+ ( ) => [
29+ {
30+ title : "입력" ,
31+ content : (
32+ < InputEditor
33+ value = { testcase . input }
34+ onChange = { ( input ) => testcaseCommand . changeValue ( testcaseId , { input } ) }
35+ onKeyDown = { ( ) => runner . makeIdle ( testcaseId ) }
36+ />
37+ ) ,
38+ } ,
39+ {
40+ title : "정답" ,
41+ content : (
42+ < AnswerEditor
43+ value = { testcase . answer }
44+ onChange = { ( answer ) => testcaseCommand . changeValue ( testcaseId , { answer } ) }
45+ />
46+ ) ,
47+ } ,
48+ {
49+ title : "출력결과" ,
50+ content : < Result testcaseId = { testcaseId } /> ,
51+ } ,
52+ ] ,
53+ [ testcaseId , testcase ] ,
54+ ) ;
4655
4756 return (
4857 < StyledTestcasePanel >
0 commit comments