Commit e052eecd authored by Björn Eyselein's avatar Björn Eyselein
Browse files

update read button

parent b1cf2956
...@@ -68,8 +68,8 @@ function onCorrectionSuccess(result: CorrectionResult, cardType: CardType): void ...@@ -68,8 +68,8 @@ function onCorrectionSuccess(result: CorrectionResult, cardType: CardType): void
let correctionText = `Ihre Lösung war ${result.correct ? '' : 'nicht '} korrekt.`; let correctionText = `Ihre Lösung war ${result.correct ? '' : 'nicht '} korrekt.`;
if ((result.newTriesCount >= 2) && (result.maybeSampleSol != null)) { if ((result.newTriesCount >= 2) && (result.maybeSampleSolution != null)) {
correctionText += ` Die korrekte Lösung lautet '<code>${result.maybeSampleSol}</code>'.`; correctionText += ` Die korrekte Lösung lautet '<code>${result.maybeSampleSolution}</code>'.`;
} }
canSolve = !(result.correct || result.newTriesCount >= 2); canSolve = !(result.correct || result.newTriesCount >= 2);
...@@ -176,6 +176,24 @@ function checkSolution(): void { ...@@ -176,6 +176,24 @@ function checkSolution(): void {
}); });
} }
function updateReadQuestionButton(readQuestionButton) {
const numOfFoundVoices: number = window.speechSynthesis.getVoices().length;
if (numOfFoundVoices > 0) {
console.info("Found " + numOfFoundVoices + " voices!");
readQuestionButton.classList.remove('hide');
readQuestionButton.disabled = false;
readQuestionButton.onclick = () => {
const utterThis = new SpeechSynthesisUtterance(flashcard.front);
utterThis.lang = 'fr';
window.speechSynthesis.speak(utterThis);
};
} else {
console.warn("Could not find any voices for Speech synthesis!");
}
}
function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void): void { function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void): void {
const initialLoadBtn = document.querySelector<HTMLButtonElement>('#loadFlashcardButton'); const initialLoadBtn = document.querySelector<HTMLButtonElement>('#loadFlashcardButton');
...@@ -192,18 +210,12 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void) ...@@ -192,18 +210,12 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void)
// FIXME: activate...? // FIXME: activate...?
const readQuestionButton = document.querySelector<HTMLButtonElement>('#readQuestionButton'); const readQuestionButton = document.querySelector<HTMLButtonElement>('#readQuestionButton');
if (window.speechSynthesis.getVoices().length > 0) { updateReadQuestionButton(readQuestionButton);
readQuestionButton.hidden = false;
readQuestionButton.disabled = false;
readQuestionButton.onclick = () => {
const utterThis = new SpeechSynthesisUtterance(flashcard.front);
utterThis.lang = 'fr';
window.speechSynthesis.speak(utterThis); window.speechSynthesis.onvoiceschanged = () => {
updateReadQuestionButton(readQuestionButton);
}; };
} window.speechSynthesis.getVoices();
nextFlashcardBtn = document.querySelector<HTMLButtonElement>('#nextFlashcardBtn'); nextFlashcardBtn = document.querySelector<HTMLButtonElement>('#nextFlashcardBtn');
nextFlashcardBtn.onclick = () => loadNextFlashcard(loadFlashcardUrl); nextFlashcardBtn.onclick = () => loadNextFlashcard(loadFlashcardUrl);
...@@ -219,7 +231,10 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void) ...@@ -219,7 +231,10 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void)
document.addEventListener('keypress', event => { document.addEventListener('keypress', event => {
if (event.key === 'Enter') { if (event.key === 'Enter') {
if (canSolve) { if (event.ctrlKey) {
readQuestionButton.click();
console.info("Pressed strg + enter!");
} else if (canSolve) {
checkSolutionBtn.click(); checkSolutionBtn.click();
} else { } else {
nextFlashcardBtn.click(); nextFlashcardBtn.click();
......
...@@ -78,5 +78,5 @@ interface CorrectionResult { ...@@ -78,5 +78,5 @@ interface CorrectionResult {
operations: EditOperation[] operations: EditOperation[]
answersSelection: AnswerSelectionResult answersSelection: AnswerSelectionResult
newTriesCount: number newTriesCount: number
maybeSampleSol: string | null maybeSampleSolution: string | null
} }
...@@ -63,11 +63,21 @@ object Corrector { ...@@ -63,11 +63,21 @@ object Corrector {
val triesToAdd = if (isCorrect) 0 else 1 val triesToAdd = if (isCorrect) 0 else 1
val oldTries = if (oldAnswer.isActive) oldAnswer.wrongTries else 0 val oldTries = if (oldAnswer.isActive) oldAnswer.wrongTries else 0
val newTries = oldTries + triesToAdd val newWrongTriesCount = oldTries + triesToAdd
val maybeSampleSolution = if (newWrongTriesCount < 2) {
None
} else if (solution.frontToBack) {
Some(flashcard.back)
} else {
Some(flashcard.front)
}
println(maybeSampleSolution)
( (
correctionResult.copy(newTriesCount = newTries, maybeSampleSolution = None), correctionResult.copy(newTriesCount = newWrongTriesCount, maybeSampleSolution = maybeSampleSolution),
oldAnswer.copy(bucket = newBucket, dateAnswered = today, correct = isCorrect, wrongTries = newTries) oldAnswer.copy(bucket = newBucket, dateAnswered = today, correct = isCorrect, wrongTries = newWrongTriesCount)
) )
} }
} }
......
...@@ -74,8 +74,7 @@ ...@@ -74,8 +74,7 @@
</div> </div>
</div> </div>
@* TODO: show... *@ <button class="btn btn-large waves-effect @primaryColor hide" title="Vorlesen" id="readQuestionButton">
<button class="btn btn-large waves-effect @primaryColor" title="Vorlesen" id="readQuestionButton" hidden>
<i class="material-icons left">record_voice_over</i> Frage vorlesen <i class="material-icons left">record_voice_over</i> Frage vorlesen
</button> </button>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment