Skip to content

Commit bf4b030

Browse files
committed
add delay in learning
1 parent 9c6817b commit bf4b030

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/app/learning/learning.page.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
</ion-row>
5454
<ion-row>
5555
<ion-col>
56-
<ion-item>
56+
<ion-item [color]="tempColor">
5757
<ion-label>Answer:</ion-label>
5858
<ion-input #answer (keyup.enter)="checkAnswer()" [(ngModel)]="answerText"
59-
placeholder="Your Text"></ion-input>
60-
<ion-button (click)="checkAnswer()" expand="full">Check</ion-button>
61-
<ion-button (click)="skip()" color="danger" expand="full">Skip</ion-button>
59+
placeholder="Your Text" [readonly]="tempReadonly"></ion-input>
60+
<ion-button (click)="checkAnswer()" [disabled]="tempReadonly" expand="full">Check</ion-button>
61+
<ion-button (click)="skip()" [disabled]="tempReadonly" color="danger" expand="full">Skip</ion-button>
6262
</ion-item>
6363
</ion-col>
6464
</ion-row>
@@ -93,13 +93,13 @@
9393
</ion-row>
9494
<ion-row>
9595
<ion-col>
96-
<ion-item>
96+
<ion-item [color]="tempColor">
9797
<ion-label>Answer:</ion-label>
9898
<ion-input #correction (keyup)="enterAnswer()" [(ngModel)]="correctionText"
99-
placeholder="Your Text"></ion-input>
99+
placeholder="Your Text" [readonly]="tempReadonly"></ion-input>
100100

101101

102-
<ion-button (click)="changeWrong()" color="warning" expand="full">I was right!</ion-button>
102+
<ion-button (click)="changeWrong()" [disabled]="tempReadonly" color="warning" expand="full">I was right!</ion-button>
103103
</ion-item>
104104
</ion-col>
105105
</ion-row>

src/app/learning/learning.page.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class LearningPage implements OnInit, ViewWillEnter {
3131
public correctCount: number = 0;
3232
public skippedCount: number = 0;
3333

34+
public tempReadonly: boolean = false;
35+
public tempColor: string = "none";
36+
3437
@ViewChild('answer', {static: false}) answer: IonInput | undefined;
3538
@ViewChild('correction', {static: false}) correction: IonInput | undefined;
3639

@@ -144,11 +147,17 @@ export class LearningPage implements OnInit, ViewWillEnter {
144147
let correct = this.getAnswer().trim();
145148

146149
if (answer == correct) {
147-
this.status = Status.Ask;
148-
this.correctCount++;
149-
this.data[this.index].correct = true;
150-
this.apiService.updateUserStats(this.id, this.data[this.index]._id, "success");
151-
this.nextItem();
150+
this.tempColor = "success";
151+
this.tempReadonly = true;
152+
setTimeout(() => {
153+
this.tempColor = "none";
154+
this.tempReadonly = false;
155+
this.status = Status.Ask;
156+
this.correctCount++;
157+
this.data[this.index].correct = true;
158+
this.apiService.updateUserStats(this.id, this.data[this.index]._id, "success");
159+
this.nextItem();
160+
}, 500);
152161
} else {
153162
this.status = Status.Answer;
154163
}
@@ -161,12 +170,18 @@ export class LearningPage implements OnInit, ViewWillEnter {
161170
let correct = this.getAnswer().trim();
162171

163172
if (answer == correct) {
164-
this.status = Status.Ask;
165-
this.data[this.index].wrong = true;
166-
this.apiService.updateUserStats(this.id, this.data[this.index]._id, "wrong");
167-
this.correctionText = "";
168-
this.nextItem();
169-
this.setFocus();
173+
this.tempColor = "danger";
174+
this.tempReadonly = true;
175+
setTimeout(() => {
176+
this.tempColor = "none";
177+
this.tempReadonly = false;
178+
this.status = Status.Ask;
179+
this.data[this.index].wrong = true;
180+
this.apiService.updateUserStats(this.id, this.data[this.index]._id, "wrong");
181+
this.correctionText = "";
182+
this.nextItem();
183+
this.setFocus();
184+
}, 2000);
170185
}
171186
}
172187

0 commit comments

Comments
 (0)