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
let correctionText = `Ihre Lösung war ${result.correct ? '' : 'nicht '} korrekt.`;
if ((result.newTriesCount >= 2) && (result.maybeSampleSol != null)) {
correctionText += ` Die korrekte Lösung lautet '<code>${result.maybeSampleSol}</code>'.`;
if ((result.newTriesCount >= 2) && (result.maybeSampleSolution != null)) {
correctionText += ` Die korrekte Lösung lautet '<code>${result.maybeSampleSolution}</code>'.`;
}
canSolve = !(result.correct || result.newTriesCount >= 2);
......@@ -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 {
const initialLoadBtn = document.querySelector<HTMLButtonElement>('#loadFlashcardButton');
......@@ -192,18 +210,12 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void)
// FIXME: activate...?
const readQuestionButton = document.querySelector<HTMLButtonElement>('#readQuestionButton');
if (window.speechSynthesis.getVoices().length > 0) {
readQuestionButton.hidden = false;
readQuestionButton.disabled = false;
readQuestionButton.onclick = () => {
const utterThis = new SpeechSynthesisUtterance(flashcard.front);
utterThis.lang = 'fr';
updateReadQuestionButton(readQuestionButton);
window.speechSynthesis.speak(utterThis);
};
}
window.speechSynthesis.onvoiceschanged = () => {
updateReadQuestionButton(readQuestionButton);
};
window.speechSynthesis.getVoices();
nextFlashcardBtn = document.querySelector<HTMLButtonElement>('#nextFlashcardBtn');
nextFlashcardBtn.onclick = () => loadNextFlashcard(loadFlashcardUrl);
......@@ -219,7 +231,10 @@ function initAll(loadNextFlashcard: (string) => void, checkSolution: () => void)
document.addEventListener('keypress', event => {
if (event.key === 'Enter') {
if (canSolve) {
if (event.ctrlKey) {
readQuestionButton.click();
console.info("Pressed strg + enter!");
} else if (canSolve) {
checkSolutionBtn.click();
} else {
nextFlashcardBtn.click();
......
......@@ -78,5 +78,5 @@ interface CorrectionResult {
operations: EditOperation[]
answersSelection: AnswerSelectionResult
newTriesCount: number
maybeSampleSol: string | null
maybeSampleSolution: string | null
}
......@@ -63,11 +63,21 @@ object Corrector {
val triesToAdd = if (isCorrect) 0 else 1
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),
oldAnswer.copy(bucket = newBucket, dateAnswered = today, correct = isCorrect, wrongTries = newTries)
correctionResult.copy(newTriesCount = newWrongTriesCount, maybeSampleSolution = maybeSampleSolution),
oldAnswer.copy(bucket = newBucket, dateAnswered = today, correct = isCorrect, wrongTries = newWrongTriesCount)
)
}
}
......
......@@ -74,8 +74,7 @@
</div>
</div>
@* TODO: show... *@
<button class="btn btn-large waves-effect @primaryColor" title="Vorlesen" id="readQuestionButton" hidden>
<button class="btn btn-large waves-effect @primaryColor hide" title="Vorlesen" id="readQuestionButton">
<i class="material-icons left">record_voice_over</i> Frage vorlesen
</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