import { ObservableWritingFormState , ObservableWritingResult , Observer , } from '@ulangi/ulangi-observable' ; export class WritingFormDelegate { private observer : Observer ; private writingFormState : ObservableWritingFormState ; private writingResult : ObservableWritingResult ; public constructor ( observer , writingFormState , writingResult ) { this . observer = observer ; this . writingFormState = writingFormState ; this . writingResult = writingResult ; } public recordWhetherHintUsed ( ) { const vocabularyId = this . writingFormState . currentQuestion . testingVocabulary . vocabularyId ; if ( this . writingFormState . isCurrentAnswerCorrect && this . writingFormState . numOfHintsUsedForCurrentQuestion === 0 ) { this . writingResult . vocabularyIdsWithNoHintsUsed . push ( vocabularyId ) ; } else { this . writingResult . vocabularyIdsWithHintsUsed . push ( vocabularyId ) ; } } public showHint ( ) { this . writingFormState . numOfHintsUsedForCurrentQuestion ++ ; const numberOfCharactersToShow = Array ( this . writingFormState . numOfHintsUsedForCurrentQuestion ) . fill ( null ) . map ( ( _ , index ) : number => index + 1 ) . reduce ( ( sum , current ) : number => sum + current ) ; const vocabularyTerm = this . writingFormState . currentQuestion . testingVocabulary . vocabularyTerm ; this . writingFormState . currentHint = vocabularyTerm . substring ( 0 , numberOfCharactersToShow ) ; if ( this . writingFormState . currentHint !== vocabularyTerm ) { this . writingFormState . currentHint = this . writingFormState . currentHint + '...' ; } } public skip ( ) { this . writingResult . skippedVocabularyIds . push ( this . writingFormState . currentQuestion . testingVocabulary . vocabularyId ) ; } public fadeOut ( callback ) { this . writingFormState . shouldRunFadeOutAnimation = true ; this . observer . when ( ( ) : boolean => this . writingFormState . shouldRunFadeOutAnimation === false , callback ) ; } }