Skip to content

Commit

Permalink
refactor: 변수명 변경 (simulations -> simulationInputs)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2820 committed Nov 21, 2023
1 parent 27edd85 commit 2d60ace
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions frontend/src/hooks/simulation/useSimulations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import evaluator from '@/modules/evaluator';
import type { SimulationInput, SimulationResult } from './types';

export const useSimulations = () => {
const [simulations, setSimulations] = useState<SimulationInput[]>([
const [simulationInputs, setSimulationInputs] = useState<SimulationInput[]>([
{ id: 1, input: '' },
{ id: 2, input: '' },
{ id: 3, input: '' },
Expand Down Expand Up @@ -49,7 +49,9 @@ export const useSimulations = () => {
}, []);

function runSimulation(code: string) {
const tasks = simulations.map(({ id, input }) => evaluator.createEvalMessage(id, code, input));
const tasks = simulationInputs.map(({ id, input }) =>
evaluator.createEvalMessage(id, code, input),
);

const isRequestSuccess = evaluator.evaluate(tasks);

Expand All @@ -61,26 +63,26 @@ export const useSimulations = () => {
return simulResults
.map((simul, index) => ({
...simul,
input: simulations[index].input,
input: simulationInputs[index].input,
}))
.map(toEvaluatingState);
});
}

function changeInput(targetId: number, newParam: string) {
const changedSimulation = simulations.find(({ id }) => id === targetId);
const changedSimulation = simulationInputs.find(({ id }) => id === targetId);
if (changedSimulation) {
changedSimulation.input = newParam;
}
setSimulations([...simulations]);
setSimulationInputs([...simulationInputs]);
}

function cancelSimulation() {
evaluator.cancelEvaluation();
}

return {
simulations,
simulationInputs,
simulationResults,
isSimulating,
runSimulation,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/ContestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CANCEL_SIMULATION = '실행 취소';
export default function ContestPage() {
const CONTEST_NAME = 'Test'; // api로 받을 정보
const {
simulations,
simulationInputs,
simulationResults,
isSimulating,
runSimulation,
Expand Down Expand Up @@ -70,7 +70,7 @@ export default function ContestPage() {
<div className={colListStyle}>
<Editor code={code} onChangeCode={handleChangeCode}></Editor>
<SimulationInputList
inputList={simulations}
inputList={simulationInputs}
onChangeInput={handleChangeInput}
></SimulationInputList>
<SimulationResultList resultList={simulationResults}></SimulationResultList>
Expand Down

0 comments on commit 2d60ace

Please sign in to comment.