Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit330d528

Browse files
committed
Give two attempts to predict output
1 parentce5184e commit330d528

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

‎frontend/src/OutputPrediction.js‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
importReact,{Component}from"react";
22
import{FontAwesomeIcon}from"@fortawesome/react-fontawesome";
33
import{faCircle,faDotCircle}from"@fortawesome/free-solid-svg-icons";
4-
import{bookSetState,scrollToNextStep}from"./book/store";
4+
import{bookSetState,scrollToNextStep,bookStatePush}from"./book/store";
55
import{showCodeResult,terminalRef}from"./App";
66
importConfettifrom"react-dom-confetti";
77
import{animateScroll}from"react-scroll";
8+
import_from"lodash";
89

910
constRadioButton=({onChange, label, status})=>(
1011
<divclassName={"prediction-choice prediction-"+status}
@@ -24,17 +25,16 @@ const RadioGroup = (
2425
onChange,
2526
value,
2627
correctAnswer,
28+
wrongAnswers,
2729
submitted
2830
})=>(
2931
<div>
3032
{choices.map((label,i)=>{
3133
letstatus="";
32-
if(submitted){
33-
if(correctAnswer===label){
34-
status="correct";
35-
}elseif(value===label){
36-
status="wrong";
37-
}
34+
if(_.includes(wrongAnswers,label)){
35+
status="wrong";
36+
}elseif(submitted&&correctAnswer===label){
37+
status="correct";
3838
}elseif(value===label){
3939
status="selected";
4040
}
@@ -65,6 +65,7 @@ export class OutputPrediction extends Component {
6565
state,
6666
userChoice,
6767
answer,
68+
wrongAnswers,
6869
height
6970
}=this.props.prediction;
7071
constconfettiActive=state==="showingResult"&&answer===userChoice;
@@ -93,16 +94,28 @@ export class OutputPrediction extends Component {
9394
</div>
9495
<RadioGroup
9596
choices={choices}
96-
onChange={value=>state==="waiting"&&bookSetState("prediction.userChoice",value)}
97+
onChange={value=>
98+
state==="waiting"&&
99+
!_.includes(wrongAnswers,value)&&
100+
bookSetState("prediction.userChoice",value)
101+
}
97102
value={userChoice}
98103
correctAnswer={answer}
104+
wrongAnswers={wrongAnswers}
99105
submitted={state==="showingResult"||state==="fading"}
100106
/>
101107
<divstyle={{opacity:state==="waiting" ?1 :0}}>
102108
<button
103109
className="btn btn-primary"
104110
disabled={!userChoice}
105111
onClick={()=>{
112+
if(userChoice!==answer){
113+
bookStatePush("prediction.wrongAnswers",userChoice);
114+
if(wrongAnswers.length===0){
115+
bookSetState("prediction.userChoice",null);
116+
return;
117+
}
118+
}
106119
bookSetState("server",codeResult.state);
107120
scrollToNextStep();
108121
bookSetState("prediction.state","showingResult");

‎frontend/src/book/store.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ const initialState = {
3636
prediction:{
3737
choices:null,
3838
answer:"",
39+
wrongAnswers:[],
3940
userChoice:"",
4041
state:"hidden",
4142
codeResult:{},
4243
},
4344
};
4445

4546

46-
const{reducer, makeAction, setState, localState}=redact('book',initialState,{dispatched:true});
47+
const{reducer, makeAction, setState, localState, statePush}=redact('book',initialState,{dispatched:true});
4748

48-
export{reducerasbookReducer,setStateasbookSetState,localStateasbookState};
49+
export{reducerasbookReducer,setStateasbookSetState,localStateasbookState,statePushasbookStatePush};
4950

5051
exportconststepIndex=(state=localState)=>state.server.pages_progress[state.page_index];
5152

@@ -125,6 +126,7 @@ export const ranCode = makeAction(
125126
prediction:{
126127
...value.prediction,
127128
userChoice:"",
129+
wrongAnswers:[],
128130
state:value.prediction.choices ?"waiting" :"hidden",
129131
codeResult:value,
130132
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp