Anupriya commited on
Commit ·
768d897
1
Parent(s): 4e121c9
generate Ques without vs
Browse filesFiles changed (4)
39 unmodified lines40414239 unmodified lines# System files.DS_StoreThumbs.db39 unmodified lines404142434445464748495051525354555657585960616263646539 unmodified lines# System files.DS_StoreThumbs.db# Visual Studio / .NET.vs/bin/obj/# Angular/Nodenode_modules/dist/.angular/# Python__pycache__/*.pyc.venv/venv/# OS / secrets.DS_StoreThumbs.db.env
24 unmodified lines252627282930316 unmodified lines38394041424344454647484950515253545556575859606115 unmodified lines77787980818283848586878889909192939495969798991001011021037 unmodified lines11111211311411511611712 unmodified lines13013113213313413513648 unmodified lines18518618718818919019119219319419519619719819920020120220314 unmodified lines2182192202212222232242252262272282292302312325 unmodified lines23823924024124224326 unmodified lines270271272273274275276277278279280281282283117 unmodified lines4014024034044054064073 unmodified lines41141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147222 unmodified lines4954964974984995005016 unmodified lines5085095105115125135141 unmodified line5165175185195205215225235245255265274 unmodified lines53253353453553653753853954054154254354454554654754854955055155238 unmodified lines59159259359459559659735 unmodified lines63363463563663763863926 unmodified lines66666766866967067167267367467567667767867959 unmodified lines739740741742743744745136 unmodified lines88288388488588688788888989089189289364 unmodified lines95895996096196296396426 unmodified lines99199299399499599699725 unmodified lines102310241025102610271028102910301031143 unmodified lines11751176117724 unmodified lineswidth: 100%;position: sticky;top: 0;z-index:1;}.logo img {6 unmodified lines.header-title {text-align: center;flex: 1;}.header-title h1 {font-size: 3vw;color: #fff;margin: 0;}.home-btn img {width: 5vw;}.home-btn img:hover {transform: scale(1.1);}/* ==================================================*/15 unmodified lines.btn-generate,.reset-btn {padding: 1vw 2vw;font-size: 1.6rem;border: none;border-radius: 0.5vw;cursor: pointer;background-color: #5c67f2;color: white;font-family: "Open Sans", sans-serif;font-weight: bold;transition: all 0.3s ease;}.btn-generate:hover,.reset-btn:hover {background-color: #0056b3;}.btn-generate:disabled,.reset-btn:disabled {background-color: #cccccc;color: #666666;cursor: not-allowed;}7 unmodified linesleft: 0;width: 100vw;height: 100vh;background-color: rgba(0, 0, 0, 0.5);display: flex;justify-content: center;align-items: center;12 unmodified lines.error-popup-content p {font-size: 1.4vw;color: #dc3545;margin-bottom: 1vw;}48 unmodified lines/* Use the `src` of the hidden image */.app-container::before {content: "";position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-image: attr(data-bg); /* This doesn't work in CSS alone */background-size: cover;background-position: center;z-index: -1; /* Push behind other content */}14 unmodified lines}.full-content {display: flex;padding: 10px;box-sizing: border-box;margin-top: 1vw;}/* Questions Section */.questions-container {max-height: 100%;overflow: hidden;margin: 1vw;5 unmodified linesbackground: #e3f2fd;padding: 1vw 1vw 1vw 2vw;width: 100%;}26 unmodified lines}.btn-submit:disabled {background-color: #ccc;cursor: not-allowed;}.section-title {font-size: 2.5rem;color: #4ca1af;font-family: 'Open Sans', sans-serif;}117 unmodified linestext-align: center;margin: 50px auto;padding: 40px;background: white;border-radius: 15px;width: 66vw;3 unmodified linesjustify-content: center;align-items: center;font-family: 'Pacifico', cursive;position: relative;z-index: 1;}.congratulation-message h2 {color: #4ca1af;margin-bottom: 15px;font-size: 2.5vw;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;text-align: center;}@media (max-width: 768px) {.congratulation-message h2 {font-size: 2vw;}}@media (max-width: 480px) {.congratulation-message h2 {font-size: 3vw;}}.congratulation-message p {color: #333;margin-bottom: 20px;font-size: 1.8vw;}.congratulation-message button {padding: 20px 40px;font-size: 1.7em;background: linear-gradient(to right, #4ca1af, #6ac5cb);color: white;border: none;border-radius: 10px;cursor: pointer;margin-top: 20px;transition: all 0.3s ease;font-family: 'Open Sans', sans-serif;font-weight: bold;}.congratulation-message button:hover {background-color: #081f95;transform: scale(1.03);}.hint-toggle-btn {background-color: #5c67f2;22 unmodified lines}.hint-toggle-btn::before {content: "i";font-weight: bold;font-size: 2rem;color: white;6 unmodified lines.side-menu {position: fixed;top: 0;right: -100%;width: 50%;height: 100%;background-color: #ffffff;1 unmodified linepadding: 20px;box-sizing: border-box;overflow-y: auto;transition: right 0.3s ease;z-index: 999;}.side-menu.active {right: 0;}4 unmodified linesmargin-bottom: 20px;}.side-menu-header h3 {font-size: 1.5rem;color: #4ca1af;}.side-menu-header .close-btn {background-color: #ff5c5c;color: white;border: none;border-radius: 50%;font-size: 1.2rem;width: 30px;height: 30px;cursor: pointer;}.side-menu ul {list-style: none;38 unmodified lines.logo-container {width: 10vw; /* Adjust logo width */}.back-button {35 unmodified lines.side-menu {width: 40%;}.congratulation-message {26 unmodified lines}.congratulation-message p {font-size: 1.4rem;}.congratulation-message button {padding: 15px 30px;font-size: 1.4rem;}}59 unmodified linesleft: 0;width: 100%;height: 100%;/* background: rgba(0, 0, 0, 0.6);*/display: flex;flex-direction: column;justify-content: center;136 unmodified lines/* Button Colors */.btn-generate {background-color: #3f51b5;color: white;}.reset-btn {background-color: #3f51b5;color: white;}64 unmodified linestransform: translateY(-50%);display: flex;justify-content: space-between;/* z-index: 2;*/padding: 0 8px;}26 unmodified linesborder-radius: 6px;white-space: nowrap;box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.2);/* z-index: 5;*/opacity: 1;}25 unmodified lines/*hint button css start here *//* Anchor the i button on the right side of the screen (adjust as you like) */.hint-anchor {position: fixed; /* or absolute relative to a container */top: 30vh; /* vertical position */right: 33px; /* distance from right edge */z-index: 1101;}143 unmodified linestransform: rotate(45deg);}}24 unmodified lines252627282930316 unmodified lines38394041424344454647484950515253545556575859606115 unmodified lines77787980818283848586878889909192939495969798991007 unmodified lines10810911011111211311412 unmodified lines12712812913013113213348 unmodified lines18218318418518618718818919019119219319419519619719819920014 unmodified lines2152162172182192202212222232242252262272282292305 unmodified lines23623723823924024124224326 unmodified lines270271272273274275276277278279280281282283284117 unmodified lines4024034044054064073 unmodified lines41141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347422 unmodified lines4974984995005015025036 unmodified lines5105115125135145155161 unmodified line5185195205215225235245255265275285294 unmodified lines53453553653753853954054154254354454554654754854955055155255355438 unmodified lines59359459559659759835 unmodified lines63463563663763863964026 unmodified lines66766866967067167267367467567667767867968059 unmodified lines740741742743744745746136 unmodified lines88388488588688788888989089189289389464 unmodified lines95996096196296396496526 unmodified lines99299399499599699799825 unmodified lines102410251026102710281029103010311032143 unmodified lines1176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132124 unmodified lineswidth: 100%;position: sticky;top: 0;z-index: 1;}.logo img {6 unmodified lines.header-title {text-align: center;flex: 1;}.header-title h1 {font-size: 3vw;color: #fff;margin: 0;}.home-btn img {width: 5vw;}.home-btn img:hover {transform: scale(1.1);}/* ==================================================*/15 unmodified lines.btn-generate,.reset-btn {padding: 1vw 2vw;font-size: 1.6rem;border: none;border-radius: 0.5vw;cursor: pointer;background-color: #5c67f2;color: white;font-family: "Open Sans", sans-serif;font-weight: bold;transition: all 0.3s ease;}.btn-generate:disabled,.reset-btn:disabled {background-color: #cccccc;color: #666666;cursor: not-allowed;}7 unmodified linesleft: 0;width: 100vw;height: 100vh;background-color: rgba(0, 0, 0, 0.5);display: flex;justify-content: center;align-items: center;12 unmodified lines.error-popup-content p {font-size: 1.4vw;color: #dc3545;margin-bottom: 1vw;}48 unmodified lines/* Use the `src` of the hidden image */.app-container::before {content: "";position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-image: attr(data-bg); /* This doesn't work in CSS alone */background-size: cover;background-position: center;z-index: -1; /* Push behind other content */}14 unmodified lines}.full-content {display: flex;padding: 10px;box-sizing: border-box;margin-top: 1vw;}/* Questions Section */.questions-container {position: relative; /* important for centering inside this box */max-height: 100%;overflow: hidden;margin: 1vw;5 unmodified linesbackground: #e3f2fd;padding: 1vw 1vw 1vw 2vw;width: 100%;box-shadow: 0 .4vw 1vw rgba(0, 0, 0, .1);border: 9px solid #009688;}26 unmodified lines}.btn-submit:disabled {background-color: #ccc;cursor: not-allowed;}.section-title {font-size: 2.5rem;color: #4ca1af;font-family: 'Open Sans', sans-serif;}117 unmodified linestext-align: center;margin: 50px auto;padding: 40px;background: white;border-radius: 15px;width: 66vw;3 unmodified linesjustify-content: center;align-items: center;font-family: 'Pacifico', cursive;position: relative;z-index: 1;box-shadow: 0 .4vw 1vw rgba(0, 0, 0, .1);border: 9px solid #009688;}.congratulation-message h2 {color: #4ca1af;margin-bottom: 15px;font-size: 2.5vw;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;text-align: center;}@media (max-width: 768px) {.congratulation-message h2 {font-size: 2vw;}}@media (max-width: 480px) {.congratulation-message h2 {font-size: 3vw;}}.congratulation-message p {color: #333;margin-bottom: 20px;font-size: 1.8vw;}.congratulation-message button {padding: 20px 40px;font-size: 1.7em;background: #006780;color: white;border: none;border-radius: 10px;cursor: pointer;margin-top: 20px;transition: all 0.3s ease;font-family: 'Open Sans', sans-serif;font-weight: bold;}.congratulation-message button:hover {background-color: #006780;transform: scale(1.03);}.hint-toggle-btn {background-color: #5c67f2;22 unmodified lines}.hint-toggle-btn::before {content: "i";font-weight: bold;font-size: 2rem;color: white;6 unmodified lines.side-menu {position: fixed;top: 0;right: -100%;width: 50%;height: 100%;background-color: #ffffff;1 unmodified linepadding: 20px;box-sizing: border-box;overflow-y: auto;transition: right 0.3s ease;z-index: 999;}.side-menu.active {right: 0;}4 unmodified linesmargin-bottom: 20px;}.side-menu-header h3 {font-size: 1.5rem;color: #4ca1af;}.side-menu-header .close-btn {background-color: #ff5c5c;color: white;border: none;border-radius: 50%;font-size: 1.2rem;width: 30px;height: 30px;cursor: pointer;}.side-menu ul {list-style: none;38 unmodified lines.logo-container {width: 10vw; /* Adjust logo width */}.back-button {35 unmodified lines.side-menu {width: 40%;}.congratulation-message {26 unmodified lines}.congratulation-message p {font-size: 1.4rem;}.congratulation-message button {padding: 15px 30px;font-size: 1.4rem;}}59 unmodified linesleft: 0;width: 100%;height: 100%;/* background: rgba(0, 0, 0, 0.6);*/display: flex;flex-direction: column;justify-content: center;136 unmodified lines/* Button Colors */.btn-generate {background-color: #006780;color: white;}.reset-btn {background-color: #006780;color: white;}64 unmodified linestransform: translateY(-50%);display: flex;justify-content: space-between;/* z-index: 2;*/padding: 0 8px;}26 unmodified linesborder-radius: 6px;white-space: nowrap;box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.2);/* z-index: 5;*/opacity: 1;}25 unmodified lines/*hint button css start here *//* Anchor the i button on the right side of the screen (adjust as you like) */.hint-anchor {position: fixed;top: 15.6vw;right: 3vw;z-index: 1101;}143 unmodified linestransform: rotate(45deg);}}/* Circular countdown */.ring {position: relative;width: 220px;height: 220px;margin: 0 auto 8px;}.ring-svg {width: 220px;height: 220px;display: block;}/* static track */.ring-track {fill: none;stroke: rgba(15, 23, 42, 0.18); /* slate-900 @ 18% */stroke-width: 16;}/* animated arc */.ring-progress {fill: none;stroke: #006780; /* accent */stroke-width: 16;stroke-linecap: round;transform: rotate(-90deg); /* start at 12 o’clock */transform-origin: 50% 50%;transition: stroke-dashoffset 0.1s linear; /* smooth update */}/* big number in the center */.ring-number {position: absolute;inset: 0;display: grid;place-items: center;font-weight: 800;font-size: 56px;color: #0f172a;}.global-countdown-overlay {position: absolute; /* not fixed */inset: 0;display: grid;place-items: center;background: transparent;pointer-events: none;z-index: 20;}/* Keep overlay centered and always on top */:host ::ng-deep .global-countdown-overlay {position: fixed;inset: 0;display: grid;place-items: center;background: transparent;pointer-events: none;z-index: 2000; /* higher to avoid being covered */}/* Frosted card so text never blends with page content */:host ::ng-deep .overlay-card {background: rgba(255,255,255,0.98);backdrop-filter: blur(2px);-webkit-backdrop-filter: blur(2px);border: 1px solid rgba(15,23,42,0.10);border-radius: 16px;padding: 18px 22px;box-shadow: 0 10px 32px rgba(0,0,0,.18);text-align: center;pointer-events: none;}/* Ensure the ring forms a stacking context for the disk/number */:host ::ng-deep .ring {position: relative;width: 220px;height: 220px;margin: 0 auto 8px;}/* Place the SVG above the disk, below the number */:host ::ng-deep .ring-svg {position: relative;z-index: 2;}/* ADD a white center disk behind the number (no HTML changes) */:host ::ng-deep .ring::before {content: "";position: absolute;inset: 0;margin: auto;width: 120px; /* adjust if you scale the ring */height: 120px;border-radius: 50%;background: #ffffff;border: 1px solid rgba(15,23,42,.08);box-shadow: inset 0 0 0 4px rgba(255,255,255,.9), 0 2px 10px rgba(0,0,0,.08);z-index: 1; /* under number, over background */}/* Stronger, crisper number; always readable */:host ::ng-deep .ring-number {position: absolute;inset: 0;display: grid;place-items: center;z-index: 3; /* above everything in the ring */font-weight: 900;font-size: 64px; /* bump if you increased ring size */line-height: 1;color: #0b1220; /* deep slate */text-shadow: 0 0 2px #fff, 0 0 8px rgba(255,255,255,.85), 0 2px 8px rgba(0,0,0,.35);}/* Keep the ring thicker for visibility (optional) */:host ::ng-deep .ring-track,:host ::ng-deep .ring-progress {stroke-width: 18px; /* increase if needed */}/* Caption pill with high contrast */:host ::ng-deep .caption-pill {display: inline-block;margin-top: 10px;padding: 8px 14px;border-radius: 999px;background: #0ea5e9 !important;color: #ffffff !important;font-weight: 700;font-size: 15px;letter-spacing: .2px;filter: drop-shadow(0 3px 10px rgba(14,165,233,.25));}
2 unmodified lines345678928 unmodified lines3839404142434454 unmodified lines991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371 unmodified line1391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771 unmodified line1791801811821831841851861871881891901911922 unmodified lines<div *ngIf="isLoading" class="loading-overlay"><span class="loader"></span></div><div class="header-container"><!-- Logo Section -->28 unmodified lines(focus)="showSuggestions = true"onclick="showSuggestions = true"(blur)="hideSuggestions()" />54 unmodified lines<div class="questions-container" *ngIf="questions.length > 0 && !isAllLevelsCompleted"><div class="quesHintbtn"><h2 class="section-title">📝 Questions</h2><!--<button *ngIf="isFirstAttemptDone && hints.length > 0"class="hint-toggle-btn"[class.blink]="hasNewHints"(click)="toggleHintMenu()"></button>--></div><ul class="questions-list"><li *ngFor="let question of questions" class="question-item"><div class="question-wrapper"><div class="question-text-wrapper"><span class="question-text" *ngFor="let part of question.parts; let i = index">{{ part }}<input *ngIf="i < question.parts.length - 1"[(ngModel)]="userAnswers[question.index]"[readonly]="isValidationInProgress || readonlyAnswers[question.index]"placeholder=""class="answer-input"[ngClass]="{'correct-answer': !isLoading && isChecked && userAnswers[question.index] === questionsWithAnswers[question.index].correctAnswer,'wrong-answer': !isLoading && isChecked && userAnswers[question.index] !== questionsWithAnswers[question.index].correctAnswer}"(input)="onAnswerChange(question.index)" /></span>1 unmodified line</div></li></ul><!-- Show the i button ONLY after first validation and when there are hints --><ng-container *ngIf="isFirstAttemptDone && hints?.length"><div class="hint-anchor" (click)="$event.stopPropagation()"><!-- i button --><button type="button"class="hint-toggle-btn"aria-haspopup="dialog"[attr.aria-expanded]="isHintMenuVisible ? 'true' : 'false'"aria-controls="hintsPanel"(click)="toggleHintMenu()"></button><!-- Popover opening to the LEFT --><section *ngIf="isHintMenuVisible"id="hintsPanel"class="hint-popover"role="dialog"aria-modal="true"aria-label="Hints"(click)="$event.stopPropagation()"><button type="button"class="hint-close"aria-label="Close hints"(click)="closeHints()">×</button><h3 class="hint-title">Hints</h3><ul class="hint-list" role="list"><ng-container *ngFor="let hint of hints; let i = index"><li *ngIf="hint && hint.trim() !== '' && userAnswers[i] !== questionsWithAnswers[i]?.correctAnswer"class="hint-item"><strong>Hint for Question {{ i + 1 }}:</strong> {{ hint }}</li></ng-container>1 unmodified line</section></div><!-- Outside click closes it --><div *ngIf="isHintMenuVisible"class="hint-backdrop"(click)="closeHints()"></div></ng-container></div></div>2 unmodified lines345678928 unmodified lines3839404142434454 unmodified lines991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451 unmodified line1471481491501511521531541551561571581591601611621631641651661671 unmodified line1691701711721731741751762 unmodified lines<div *ngIf="isLoading" class="loading-overlay"><span class="loader"></span></div><div class="header-container"><!-- Logo Section -->28 unmodified lines(focus)="showSuggestions = true"onclick="showSuggestions = true"(blur)="hideSuggestions()" />54 unmodified lines<div class="questions-container" *ngIf="questions.length > 0 && !isAllLevelsCompleted"><div class="quesHintbtn"><h2 class="section-title">📝 Questions</h2></div><ul class="questions-list"><li *ngFor="let question of questions" class="question-item"><div class="question-wrapper"><div class="question-text-wrapper"><span class="question-text" *ngFor="let part of question.parts; let i = index">{{ part }}<span class="answer-slot"><input *ngIf="i < question.parts.length - 1"[(ngModel)]="userAnswers[question.index]"[readonly]="isValidationInProgress || readonlyAnswers[question.index]"placeholder=""class="answer-input"pattern="[A-Za-z]*"(input)="onInput($event, question.index)"[ngClass]="{'correct-answer': !isLoading && isChecked && userAnswers[question.index] === questionsWithAnswers[question.index].correctAnswer,'wrong-answer': !isLoading && isChecked && userAnswers[question.index] !== questionsWithAnswers[question.index].correctAnswer}"(input)="onAnswerChange(question.index)" /><div *ngIf="showGlobalCountdown" class="global-countdown-overlay" role="status" aria-live="assertive"><div class="overlay-card"><div class="ring"><svg class="ring-svg" viewBox="0 0 220 220" aria-hidden="true"><circle class="ring-track" cx="110" cy="110" r="90"></circle><circle class="ring-progress"cx="110" cy="110" r="90"[attr.stroke-dasharray]="ringCircumference"[attr.stroke-dashoffset]="ringDashoffset"></circle></svg><div class="ring-number">{{ globalCountdown }}</div></div><div class="caption-pill">{{ overlayCaption }} {{ globalCountdown }}s</div></div></div></span></span>1 unmodified line</div></li></ul><ng-container *ngIf="isFirstAttemptDone && hints?.length"><div class="hint-anchor" (click)="$event.stopPropagation()"><button type="button" class="hint-toggle-btn" aria-haspopup="dialog" [attr.aria-expanded]="isHintMenuVisible ? 'true' : 'false'" aria-controls="hintsPanel" (click)="toggleHintMenu()"></button><section *ngIf="isHintMenuVisible" id="hintsPanel" class="hint-popover" role="dialog" aria-modal="true" aria-label="Hints" (click)="$event.stopPropagation()"><button type="button" class="hint-close" aria-label="Close hints" (click)="closeHints()">×</button><h3 class="hint-title">Hints</h3><ul class="hint-list" role="list"><ng-container *ngFor="let hint of hints; let i = index"><li *ngIf="hint && hint.trim() !== '' && userAnswers[i] !== questionsWithAnswers[i]?.correctAnswer" class="hint-item"><strong>Hint for Question {{ i + 1 }}:</strong> {{ hint }}</li></ng-container>1 unmodified line</section></div><div *ngIf="isHintMenuVisible" class="hint-backdrop" (click)="closeHints()"></div></ng-container></div></div>
24 unmodified lines2526272829303132333435363738394041424344454647484950511 unmodified line53545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292309 unmodified lines2402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822836 unmodified lines2902912922932942952962972982993003013023033043053063073083093103113123133143153161 unmodified line3183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543557 unmodified lines3633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184191 unmodified line4214224234244254264274284294304314324334344354364374384394404414424434444454464474484494502 unmodified lines4534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995007 unmodified lines5085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605612 unmodified lines5645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046053 unmodified lines60961061161261361461561661761861962062162262362462562624 unmodified linesstyleUrls: ['./generate-questions.component.css']})export class GenerateQuestionsComponent {topic: string = '';hardcodedTopics: string[] = ['Noun', 'Verb', 'Past Tense', 'Adjective', 'Present Continuous'];showSuggestions: boolean = false;//questions: string[] = [];userAnswers: string[] = []; // Array to store user answersfeedback: string[] = []; // Array to store feedback for each answererror: string = '';isChecked: boolean = false; // Flag to disable button after clickingisAnswerModified: boolean = false;questions: { parts: string[]; index: number }[] = [];attemptCounts: { [key: number]: number } = {};correctAnswers: string[] = [];questionsWithAnswers: QuestionWithAnswer[] = []; // Track questions with answerscurrentDifficulty: string = 'basic';difficultyLevels: string[] = ['basic', 'elementary', 'pre-intermediate', 'intermediate', 'upper-intermediate', 'medium', 'hard'];//difficultyLevels: string[] = ['basic', 'hard'];isDropdownDisabled: boolean = false;isValidationInProgress: boolean = false;isTopicLocked: boolean = false;isAllLevelsCompleted: boolean = false; // Tracks if all levels are completedreadonlyAnswers: boolean[] = [];hints: string[] = [];attempts: number[] = [];1 unmodified lineisGenerateDisabled: boolean = true;isResetDisabled: boolean = true;isFirstAttemptDone: boolean = false;hasNewHints: boolean = false; // Track new hints for animationisLoading: boolean = false;isValidationCompleted = false;showLevelTooltip: boolean = false;activateLevelDot: boolean = false;isTyping: boolean = false; // Track if the user is typingvalidated: boolean = false; // Track if validation has been triggeredconstructor(private generateQuestionsService: GenerateQuestionsService, private router: Router, private cdr: ChangeDetectorRef) { }onTopicChange() {if (this.topic.trim().length > 0) {this.isGenerateDisabled = false; // Enable the Generate button when there's input} else {this.isGenerateDisabled = true; // Disable the Generate button if input is empty}if (this.topic.trim().length === 0) {this.showSuggestions = true; // Hide suggestions when the topic is empty} else {this.showSuggestions = false; // Show suggestions when there's text in the input field}}getProgressWidth(): string {const index = this.difficultyLevels.indexOf(this.currentDifficulty);if (index === -1 || this.difficultyLevels.length <= 1) return '0%';const percent = (index / (this.difficultyLevels.length - 1)) * 100;return `${percent}%`;}getProgressGradient(): string {const index = this.difficultyLevels.indexOf(this.currentDifficulty);const gradientColors = ["#4caf50", // Basic (Green)"#8bc34a", // Elementary"#ffc107", // Pre-Intermediate (Yellow)"#ff9800", // Intermediate"#ff5722", // Upper-Intermediate (Orange)"#f44336", // Medium (Red)"#b71c1c" // Hard (Dark Red)];if (index === 0) {return gradientColors[0];}const gradient = gradientColors.slice(0, index + 1).join(', ');return `linear-gradient(to right, ${gradient})`;}generateQuestions() {this.hints = [];this.isQuestionsGenerated = false; // Reset the flag before generatingthis.showLevelTooltip = true;this.activateLevelDot = true;if (this.isAllLevelsCompleted) {this.error = 'Please reset to start over.';return;}this.isTopicLocked = true; // Lock the topic fieldthis.showSuggestions = false; // Hide the dropdown after Generate is clickedthis.readonlyAnswers = []; // Reset readonlyAnswers statethis.isDropdownDisabled = true; // Disable the dropdownconsole.log(`Generating questions for difficulty level: ${this.currentDifficulty}`);this.generateQuestionsService.generateQuestions(this.topic, this.currentDifficulty).subscribe((response) => {console.log('Response from backend:', response);if (response.generations && response.generations.length > 0) {const rawQuestions = response.generations[0].text;console.log('Raw Questions:', rawQuestions);this.isQuestionsGenerated = true; // Set flag to true after questions are generated// Disable the Generate button once questions are generatedthis.isGenerateDisabled = true;// Enable the Reset button when questions are displayedthis.isResetDisabled = false;this.questionsWithAnswers = [];const regex = /(\d+\.\s*.+?_______)\s*(.*?)\s*\(([^)]+)\)\s*$/gm;let match;while ((match = regex.exec(rawQuestions)) !== null) {console.log('Match:', match);const questionText = match[1]?.trim() || ''; // Full question text up to the blankconst afterBlank = match[2]?.trim() || ''; // Text after the blankconst correctAnswer = match[3]?.trim() || ''; // Correct answer inside the parenthesesif (questionText && correctAnswer) {this.questionsWithAnswers.push({question: `${questionText}${afterBlank}`, // Combine parts for the full questioncorrectAnswer,});}}console.log('Extracted Questions with Answers:', this.questionsWithAnswers);this.questions = this.questionsWithAnswers.map((q, index) => {const cleanedQuestion = q.question.replace(/\s*\(.*?\)/g, ''); // Remove parentheses contentconst parts = cleanedQuestion.split(/_______/);if (parts.length === 2) {parts[0] = parts[0].trim(); // Text before the blankparts[1] = parts[1].trim(); // Text after the blank} else if (parts.length === 1) {parts[0] = parts[0].trim();parts.push(''); // Ensure a second part exists}return { parts, index };});this.userAnswers = new Array(this.questions.length).fill('');this.feedback = new Array(this.questions.length).fill('');this.readonlyAnswers = new Array(this.questions.length).fill(false);this.isChecked = false;this.attemptCounts = this.questions.reduce((acc, question, index) => {acc[index] = 0; // Set initial attempt count for each questionreturn acc;}, {} as { [key: number]: number });console.log('Questions without answers:', this.questions);} else {this.error = 'No questions generated. Please try again.';}},(error) => {if (error.status === 400 && error.error.message) {this.error = error.error.message; // Display the message from the backend} else {this.error = 'Failed to fetch questions. Please try again later.';}console.error('Error fetching questions:', error);});}resetTopic() {this.topic = '';this.questions = [];this.questionsWithAnswers = [];this.userAnswers = [];9 unmodified linesthis.isQuestionsGenerated = false;this.isTopicLocked = false;this.validated = false;this.currentDifficulty = 'basic';this.error = '';this.isGenerateDisabled = false;this.isResetDisabled = true;this.showSuggestions = false;this.showLevelTooltip = false;this.activateLevelDot = false;this.showSuggestions = false;this.isDropdownDisabled = false; // ✅ Ensure dropdown is not disabledthis.isTopicLocked = false; // ✅ Ensure the topic can be typed againthis.stopConfetti();}areAllAnswersFilled(): boolean {return this.userAnswers.every(answer => answer?.trim() !== '');}closeErrorPopup() {this.error = ''; // Clear the error messagethis.isGenerateDisabled = true; // Disable Generate buttonthis.isResetDisabled = false; // Enable Reset button}checkAllAnswers() {6 unmodified linesconst requestPayload = this.questions.map((questionObj, index) => ({topic: this.topic,question: questionObj.parts.join('_______'),user_answer: this.userAnswers[index],}));console.log("Checking answers...");console.log("User Answers:", this.userAnswers);console.log("Correct Answers:", this.questionsWithAnswers.map(q => q.correctAnswer));this.generateQuestionsService.validateAllAnswers(requestPayload).subscribe((response) => {console.log('Response from backend for all answers validation:', response);if (response.results && response.results.length > 0) {let allAttemptsCompleted = true;response.results.forEach((result: any, index: number) => {this.attemptCounts[index]++;const validationResponse = result.validation_response;const hint = result.hint ? result.hint.trim() : '';const userAnswer = this.userAnswers[index].trim().toLowerCase();const correctAnswer = this.questionsWithAnswers[index].correctAnswer.trim().toLowerCase();console.log(`Validation Response for Question ${index + 1}: ${validationResponse}`);console.log(`User Answer: ${userAnswer}, Correct Answer: ${correctAnswer}`);1 unmodified lineif (userAnswer === correctAnswer) {console.log(`✅ Correct answer for question ${index + 1}: ${this.userAnswers[index]}`);this.readonlyAnswers[index] = true;this.hints[index] = '';//this.userAnswers[index] = correctAnswer;this.userAnswers[index] = this.questionsWithAnswers[index].correctAnswer;} else {console.log(`❌ Incorrect answer for question ${index + 1}: ${this.userAnswers[index]}`);setTimeout(() => {if (this.attemptCounts[index] === 1) {console.log(`🔄 Resetting incorrect answer for Question ${index + 1}`);this.userAnswers[index] = '';}if (this.attemptCounts[index] >= 2) {if (!this.userAnswers[index] || this.userAnswers[index].trim() === "" || userAnswer !== correctAnswer) {this.userAnswers[index] = this.questionsWithAnswers[index].correctAnswer;console.log(`✔️ Auto-filled correct answer for Question ${index + 1}: ${this.userAnswers[index]}`);}if (this.isLastLevel() && index === this.questions.length - 1) {setTimeout(() => {this.isAllLevelsCompleted = true;console.log('🎉 You have completed all difficulty levels.');this.triggerConfetti();}, 2000);}}}, 2000);this.hints[index] = hint.length > 0 ? hint : null;}this.feedback[index] = validationResponse || 'No feedback provided.';setTimeout(() => {if (userAnswer === correctAnswer) {this.userAnswers[index] = this.userAnswers[index];7 unmodified lines}});this.hasNewHints = this.hints.some(hint => hint && hint.trim() !== "");if (this.hasNewHints) {setTimeout(() => {this.hasNewHints = false;}, 5000);}if (this.areAllCorrectAnswersDisplayed() || allAttemptsCompleted) {this.triggerNextLevelWithDelay();}} else {this.error = 'Failed to validate answers. Please try again.';}this.isValidationInProgress = false;this.isLoading = false;},(error) => {console.error('Error validating answers:', error);this.error = 'Error validating answers. Please try again later.';this.isValidationInProgress = false;this.isLoading = false;});}isLastLevel(): boolean {return this.currentDifficulty === this.difficultyLevels[this.difficultyLevels.length - 1];}triggerNextLevelWithDelay() {setTimeout(() => {this.transitionDifficulty();}, 2000); // Introduce a delay before generating the next level}areAllCorrectAnswersDisplayed(): boolean {return this.userAnswers.every((answer, index) =>(answer ?? '').trim().toLowerCase() ===(this.questionsWithAnswers[index]?.correctAnswer ?? '').trim().toLowerCase());}transitionDifficulty() {1 unmodified lineif (currentIndex < this.difficultyLevels.length - 1) {this.currentDifficulty = this.difficultyLevels[currentIndex + 1];console.log(`Switching to ${this.currentDifficulty} difficulty level.`);this.generateQuestions(); // Fetch new set of questions for the next difficulty level} else {setTimeout(() => {this.questions = []; // Clear the listthis.isAllLevelsCompleted = true;this.isChecked = false;this.isValidationInProgress = false;this.isLoading = false;console.log('🎉 You have completed all difficulty levels.');this.triggerConfetti();}, 3000); // Ensure a small delay before showing the message}}shouldShowHint(index: number): boolean {return this.attemptCounts[index] < 1; // Show hint only on the first attempt}resetAllLevels() {this.isAllLevelsCompleted = false;this.currentDifficulty = 'basic';this.questions = [];this.userAnswers = [];this.feedback = [];2 unmodified linesthis.isValidationInProgress = false;this.isTopicLocked = false;this.hints = [];this.error = '';this.isGenerateDisabled = true;this.isResetDisabled = false;console.log('All levels reset. Starting from basic level.');}onAnswerChange(index: number) {if (!this.isValidationInProgress) {this.isChecked = false;this.validated = false;}const userAnswer = this.userAnswers[index]?.trim();console.log('User Answers:', this.userAnswers);console.log('Are All Answers Filled:', this.areAllAnswersFilled());if (userAnswer) {this.userAnswers[index] = userAnswer;} else {this.userAnswers[index] = '';}this.userAnswers = [...this.userAnswers];}goToHome() {this.router.navigate(['/home']);}private confettiInterval: any;triggerConfetti() {if (this.confettiInterval) {clearInterval(this.confettiInterval);}this.confettiInterval = setInterval(() => {confetti({startVelocity: 30,7 unmodified lines}, 250);}stopConfetti() {this.isAllLevelsCompleted = false; // ✅ Hides congratulatory message// Clear interval if using confetti animationsif (this.confettiInterval) {clearInterval(this.confettiInterval);this.confettiInterval = null;}// Remove canvas or any extra DOM elements related to confetticonst canvas = document.querySelector('canvas.confetti-canvas');if (canvas) {canvas.remove();}const confettiDivs = document.querySelectorAll('.confetti, .ts-confetti');confettiDivs.forEach(el => el.remove());}// Handler for "Start Over" button in congratulation messagestopConfettiAndReset() {this.stopConfetti();this.resetTopic();}isHintMenuVisible: boolean = false; // Track visibility of the hint menu//toggleHintMenu() {// if (this.hints.length > 0) {// this.isHintMenuVisible = !this.isHintMenuVisible; // Toggle only if hints exist// console.log("Hint Menu Toggled:", this.isHintMenuVisible); // Debugging// }//}selectTopic(suggestion: string): void {this.topic = suggestion;this.showSuggestions = false;2 unmodified linesthis.isDropdownDisabled = true;}// Hide suggestions when clicking outsidehideSuggestions(): void {setTimeout(() => {this.showSuggestions = false;}, 200);}/* // Add this property to your componenthasNewHints: boolean = false;*/// Call this function when hints are generatedprocessHints(hints: string[]) {this.hints = hints;// Set `hasNewHints` to true if there are hintsthis.hasNewHints = hints.length > 0;// Optionally, stop the blinking after a delayif (this.hasNewHints) {setTimeout(() => {this.hasNewHints = false; // Stop blinking after 5 seconds}, 5000); // Adjust the delay as needed}}closeHints(): void {this.isHintMenuVisible = false;this.hasNewHints = false; // optional: mark hints as seen}openHints(): void {3 unmodified lines}}/* Keep your existing toggle if you’re calling it from the i button */toggleHintMenu(): void {this.isHintMenuVisible ? this.closeHints() : this.openHints();}///* Close on Esc key *///@HostListener('document:keydown.escape')//onEscClose(): void {// if (this.isHintMenuVisible) this.closeHints();//}}24 unmodified lines2526272829303132333435363738394041424344454647484950515253545556571 unmodified line59606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072089 unmodified lines2182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612626 unmodified lines2692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053061 unmodified line3083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663677 unmodified lines3753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584591 unmodified line4614624634644654664674684694704714724734744754764774784794804814824834844854864872 unmodified lines4904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275287 unmodified lines5365375385395405415425435445455465475485495505515525535545555565575585595605615625635642 unmodified lines5675685695705715725735745755765775785795805815825835845855865875885895905915925933 unmodified lines59759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675724 unmodified linesstyleUrls: ['./generate-questions.component.css']})export class GenerateQuestionsComponent {topic: string = "";hardcodedTopics: string[] = ["Noun","Verb","Past Tense","Adjective","Present Continuous",];showSuggestions: boolean = false;userAnswers: string[] = [];feedback: string[] = [];error: string = "";isChecked: boolean = false;isAnswerModified: boolean = false;questions: { parts: string[]; index: number }[] = [];attemptCounts: { [key: number]: number } = {};correctAnswers: string[] = [];questionsWithAnswers: QuestionWithAnswer[] = [];currentDifficulty: string = "basic";// difficultyLevels: string[] = ['basic', 'elementary', 'pre-intermediate', 'intermediate', 'upper-intermediate', 'advanced', 'hard'];difficultyLevels: string[] = ["basic", "intermediate", "expert"];isDropdownDisabled: boolean = false;isValidationInProgress: boolean = false;isTopicLocked: boolean = false;isAllLevelsCompleted: boolean = false;readonlyAnswers: boolean[] = [];hints: string[] = [];attempts: number[] = [];1 unmodified lineisGenerateDisabled: boolean = true;isResetDisabled: boolean = true;isFirstAttemptDone: boolean = false;hasNewHints: boolean = false;isLoading: boolean = false;isValidationCompleted = false;showLevelTooltip: boolean = false;activateLevelDot: boolean = false;isTyping: boolean = false;validated: boolean = false;constructor(private generateQuestionsService: GenerateQuestionsService,private router: Router,private cdr: ChangeDetectorRef,) { }onTopicChange() {if (this.topic.trim().length > 0) {this.isGenerateDisabled = false;} else {this.isGenerateDisabled = true;}if (this.topic.trim().length === 0) {this.showSuggestions = true;} else {this.showSuggestions = false;}}getProgressWidth(): string {const index = this.difficultyLevels.indexOf(this.currentDifficulty);if (index === -1 || this.difficultyLevels.length <= 1) return "0%";const percent = (index / (this.difficultyLevels.length - 1)) * 100;return `${percent}%`;}generateQuestions() {this.hints = [];this.isQuestionsGenerated = false;this.showLevelTooltip = true;this.activateLevelDot = true;if (this.isAllLevelsCompleted) {this.error = "Please reset to start over.";return;}this.isTopicLocked = true;this.showSuggestions = false;this.readonlyAnswers = [];this.isDropdownDisabled = true;console.log(`Generating questions for difficulty level: ${this.currentDifficulty}`);this.generateQuestionsService.generateQuestions(this.topic, this.currentDifficulty).subscribe((response) => {console.log("Response from backend:", response);if (response.generations && response.generations.length > 0) {const rawQuestions = response.generations[0].text;console.log("Raw Questions:", rawQuestions);this.isQuestionsGenerated = true;this.isGenerateDisabled = true;this.isResetDisabled = false;this.questionsWithAnswers = [];// same regex you already useconst regex = /(\d+\.\s*.+?_______)\s*(.*?)\s*\(([^)]+)\)\s*$/gm;let match;while ((match = regex.exec(rawQuestions)) !== null) {console.log("Match:", match);const questionText = (match[1] ?? "").trim(); // up to _______const afterBlankRaw = (match[2] ?? ""); // text after the blankconst correctAnswer = (match[3] ?? "").trim(); // answer in parentheses// NEW: clean any stray "_" or "-" that sometimes appear right after the blankconst afterBlankClean = afterBlankRaw.replace(/^[_-]+/, "") // drop leading underscores/dashes like "_ moment".replace(/^\s+/, " ") // ensure exactly one leading space if any.replace(/\s{2,}/g, " "); // collapse multiple spacesif (questionText && correctAnswer) {this.questionsWithAnswers.push({question: `${questionText}${afterBlankClean}`,correctAnswer,});}}console.log("Extracted Questions with Answers:", this.questionsWithAnswers);// Build renderable questions (parts before/after the blank)this.questions = this.questionsWithAnswers.map((q, index) => {// NEW: normalize any odd spacing around the markerconst normalized = q.question.replace(/\s*_{3,}\s*/g, "_______");const parts = normalized.split("_______");if (parts.length === 2) {// NEW: remove any stray underscores touching the gapparts[0] = parts[0].replace(/_+$/, "").trim();parts[1] = parts[1].replace(/^_+/, "").trim();}return { parts, index };});this.userAnswers = new Array(this.questions.length).fill("");this.feedback = new Array(this.questions.length).fill("");this.readonlyAnswers = new Array(this.questions.length).fill(false);this.isChecked = false;this.attemptCounts = this.questions.reduce((acc, _q, i) => {acc[i] = 0;return acc;}, {} as { [key: number]: number });console.log("Questions without answers:", this.questions);} else {this.error = "No questions generated. Please try again.";}},(error) => {if (error.status === 400 && error.error.message) {this.error = error.error.message;} else {this.error = "Failed to fetch questions. Please try again later.";}console.error("Error fetching questions:", error);},);}resetTopic() {this.topic = "";this.questions = [];this.questionsWithAnswers = [];this.userAnswers = [];9 unmodified linesthis.isQuestionsGenerated = false;this.isTopicLocked = false;this.validated = false;this.currentDifficulty = "basic";this.error = "";this.isGenerateDisabled = false;this.isResetDisabled = true;this.showSuggestions = false;this.showLevelTooltip = false;this.activateLevelDot = false;this.showSuggestions = false;this.isDropdownDisabled = false;this.isTopicLocked = false;this.stopConfetti();// Stop any active countdownsObject.keys(this.countdownTimers).forEach(k => clearInterval(this.countdownTimers[+k]));this.countdownTimers = {};this.countdowns = [];this.showCountdown = [];this.stopGlobalCountdown();this.stopOverlay()}areAllAnswersFilled(): boolean {return this.userAnswers.every((answer) => answer?.trim() !== "");}closeErrorPopup() {this.error = "";this.isGenerateDisabled = true;this.isResetDisabled = false;}// Hint icon one-time flags (ADD THESE)showHintIcon: boolean = false; // controls rendering of the “i” buttonhasShownHintIcon: boolean = false; // remembers if it was shown once// If you call toggleHintMenu(), also ensure this exists:isHintMenuVisible: boolean = false; // remove if you already have itcheckAllAnswers() {6 unmodified linesconst requestPayload = this.questions.map((questionObj, index) => ({topic: this.topic,question: questionObj.parts.join("_______"),user_answer: this.userAnswers[index],}));console.log("Checking answers...");console.log("User Answers:", this.userAnswers);console.log("Correct Answers:",this.questionsWithAnswers.map((q) => q.correctAnswer),);this.generateQuestionsService.validateAllAnswers(requestPayload).subscribe((response) => {console.log("Response from backend for all answers validation:", response);if (response.results && response.results.length > 0) {let allAttemptsCompleted = true;// Track what happened this validation cyclelet hadFirstAttemptWrong = false; // someone is on first wrong attemptlet hadSecondAttemptWrong = false; // someone is on second wrong attempt (autofill path)response.results.forEach((result: any, index: number) => {this.attemptCounts[index]++;const validationResponse = result.validation_response;const hint = result.hint ? result.hint.trim() : "";const userAnswerRaw = this.userAnswers[index] ?? '';const userAnswer = userAnswerRaw.trim().toLowerCase();const correctAnswerRaw = this.questionsWithAnswers[index].correctAnswer ?? '';const correctAnswer = correctAnswerRaw.trim().toLowerCase();console.log(`Validation Response for Question ${index + 1}: ${validationResponse}`);console.log(`User Answer: ${userAnswer}, Correct Answer: ${correctAnswer}`);1 unmodified lineif (userAnswer === correctAnswer) {console.log(`✅ Correct answer for question ${index + 1}: ${this.userAnswers[index]}`);this.readonlyAnswers[index] = true;this.hints[index] = "";this.userAnswers[index] = this.questionsWithAnswers[index].correctAnswer;} else {console.log(`❌ Incorrect answer for question ${index + 1}: ${this.userAnswers[index]}`);// ====== 1) FIRST WRONG ATTEMPT: show "Try again" countdown, then clear input ======if (this.attemptCounts[index] === 1) {hadFirstAttemptWrong = true;if (!this.globalCountdownActive) {this.startOverlay("Try again in");}setTimeout(() => {console.log(`🔄 Resetting incorrect answer for Question ${index + 1}`);this.userAnswers[index] = ""; // give user a clean slatethis.stopOverlay(); // ensure the HUD disappears}, this.COUNTDOWN_SECS * 1000);}// ====== 2) SECOND WRONG ATTEMPT: show "Showing correct answer" countdown, then autofill ======else if (this.attemptCounts[index] >= 2) {hadSecondAttemptWrong = true;if (!this.globalCountdownActive) {this.startOverlay("Showing correct answer in");}setTimeout(() => {// after countdown, force the correct answerif (!this.userAnswers[index] || this.userAnswers[index].trim() === "" || userAnswer !== correctAnswer) {this.userAnswers[index] = this.questionsWithAnswers[index].correctAnswer;console.log(`✔️ Auto-filled correct answer for Question ${index + 1}: ${this.userAnswers[index]}`);}this.stopOverlay(); // hide the first overlay (showing correct answer)// ====== 3) LAST LEVEL: show a second countdown before congratulations ======if (this.isLastLevel() && index === this.questions.length - 1) {// Give time to read the just-filled correct answerthis.startOverlay("Finishing in");setTimeout(() => {this.stopOverlay();this.isAllLevelsCompleted = true;console.log("🎉 You have completed all difficulty levels.");this.triggerConfetti();}, this.COUNTDOWN_SECS * 1000);}}, this.COUNTDOWN_SECS * 1000);}this.hints[index] = hint.length > 0 ? hint : null;}this.feedback[index] = validationResponse || "No feedback provided.";// minor 2s reflection (kept as-is)setTimeout(() => {if (userAnswer === correctAnswer) {this.userAnswers[index] = this.userAnswers[index];7 unmodified lines}});// Hints auto-hide (unchanged)this.hasNewHints = this.hints.some((h) => h && h.trim() !== "");if (this.hasNewHints) {setTimeout(() => { this.hasNewHints = false; }, 5000);}// --- ONE-TIME “i” icon reveal right after the first validation ---// Show once if there are any hints OR there were wrong attempts this cycle.const hasAnyHint = Array.isArray(this.hints) && this.hints.some(h => !!h && h.trim() !== "");const shouldRevealIconOnce = hasAnyHint || hadFirstAttemptWrong || hadSecondAttemptWrong;if (!this.hasShownHintIcon && shouldRevealIconOnce) {this.showHintIcon = true; // reveal oncethis.hasShownHintIcon = true; // lock it} else {this.showHintIcon = false; // never show again in later validations}// --- END ONE-TIME “i” icon reveal ---if (this.isLastLevel() && this.areAllCorrectAnswersDisplayed()) {// Last level, all correct: show finish counter, then congratulationsthis.stopOverlay(); // ensure no old timer remainsthis.startOverlay("Finishing in");setTimeout(() => {this.stopOverlay();this.isAllLevelsCompleted = true;this.triggerConfetti();}, this.COUNTDOWN_SECS * 1000);} else if (!this.isLastLevel() && (this.areAllCorrectAnswersDisplayed() || allAttemptsCompleted)) {// Not last level: even if all answers were correct on first try,// show the counter before moving to the next levelthis.stopOverlay(); // ensure fresh HUDthis.startOverlay("Moving to next level in");setTimeout(() => {this.stopOverlay();this.triggerNextLevelWithDelay();}, this.COUNTDOWN_SECS * 1000);}} else {this.error = "Failed to validate answers. Please try again.";}this.isValidationInProgress = false;this.isLoading = false;},(error) => {console.error("Error validating answers:", error);this.error = "Error validating answers. Please try again later.";this.isValidationInProgress = false;this.isLoading = false;},);}isLastLevel(): boolean {return (this.currentDifficulty ===this.difficultyLevels[this.difficultyLevels.length - 1]);}triggerNextLevelWithDelay() {setTimeout(() => {this.transitionDifficulty();}, 2000);}areAllCorrectAnswersDisplayed(): boolean {return this.userAnswers.every((answer, index) =>(answer ?? "").trim().toLowerCase() ===(this.questionsWithAnswers[index]?.correctAnswer ?? "").trim().toLowerCase(),);}transitionDifficulty() {1 unmodified lineif (currentIndex < this.difficultyLevels.length - 1) {this.currentDifficulty = this.difficultyLevels[currentIndex + 1];console.log(`Switching to ${this.currentDifficulty} difficulty level.`);this.generateQuestions();} else {setTimeout(() => {this.questions = [];this.isAllLevelsCompleted = true;this.isChecked = false;this.isValidationInProgress = false;this.isLoading = false;console.log("🎉 You have completed all difficulty levels.");this.triggerConfetti();}, 3000);}}shouldShowHint(index: number): boolean {return this.attemptCounts[index] < 1;}resetAllLevels() {this.isAllLevelsCompleted = false;this.currentDifficulty = "basic";this.questions = [];this.userAnswers = [];this.feedback = [];2 unmodified linesthis.isValidationInProgress = false;this.isTopicLocked = false;this.hints = [];this.error = "";this.isGenerateDisabled = true;this.isResetDisabled = false;console.log("All levels reset. Starting from basic level.");}onAnswerChange(index: number) {if (!this.isValidationInProgress) {this.isChecked = false;this.validated = false;}const userAnswer = this.userAnswers[index]?.trim();console.log("User Answers:", this.userAnswers);console.log("Are All Answers Filled:", this.areAllAnswersFilled());if (userAnswer) {this.userAnswers[index] = userAnswer;} else {this.userAnswers[index] = "";}this.userAnswers = [...this.userAnswers];}goToHome() {this.router.navigate(["/home"]);}private confettiInterval: any;triggerConfetti() {if (this.confettiInterval) {clearInterval(this.confettiInterval);}this.confettiInterval = setInterval(() => {confetti({startVelocity: 30,7 unmodified lines}, 250);}stopConfetti() {this.isAllLevelsCompleted = false;if (this.confettiInterval) {clearInterval(this.confettiInterval);this.confettiInterval = null;}const canvas = document.querySelector("canvas.confetti-canvas");if (canvas) {canvas.remove();}const confettiDivs = document.querySelectorAll(".confetti, .ts-confetti");confettiDivs.forEach((el) => el.remove());}stopConfettiAndReset() {this.stopConfetti();this.resetTopic();}selectTopic(suggestion: string): void {this.topic = suggestion;this.showSuggestions = false;2 unmodified linesthis.isDropdownDisabled = true;}hideSuggestions(): void {setTimeout(() => {this.showSuggestions = false;}, 200);}processHints(hints: string[]) {this.hints = hints;this.hasNewHints = hints.length > 0;if (this.hasNewHints) {setTimeout(() => {this.hasNewHints = false;}, 5000);}}closeHints(): void {this.isHintMenuVisible = false;this.hasNewHints = false;}openHints(): void {3 unmodified lines}}toggleHintMenu() {this.isHintMenuVisible = !this.isHintMenuVisible;if (this.isHintMenuVisible) this.showHintIcon = false; // hide after first use}onInput(event: any, index: number) {const value = event.target.value;const filteredValue = value.replace(/[^a-zA-Z]/g, "");this.userAnswers[index] = filteredValue;event.target.value = filteredValue;}//timer implemetation// --- Countdown state (per question) ---countdowns: number[] = []; // current number (5..0) for each questionshowCountdown: boolean[] = []; // whether to show the badgeprivate countdownTimers: { [idx: number]: any } = {}; // interval handlesprivate readonly COUNTDOWN_SECS = 10;// === Global countdown overlay state ===showGlobalCountdown = false; // controls the centered overlayglobalCountdown = 0; // 5..1private globalCountdownActive = false;private globalTimer: any = null;overlayCaption = '';private beginResetCountdown(index: number, seconds: number = this.COUNTDOWN_SECS): void {// avoid duplicate timers for the same questionif (this.countdownTimers[index]) { return; }this.countdowns[index] = seconds;this.showCountdown[index] = true;this.countdownTimers[index] = setInterval(() => {this.countdowns[index] = this.countdowns[index] - 1;if (this.countdowns[index] <= 0) {this.finishCountdown(index);}}, 1000);}/** Stop timer, hide badge, clear the wrong input, and allow retry. */private finishCountdown(index: number): void {const t = this.countdownTimers[index];if (t) {clearInterval(t);delete this.countdownTimers[index];}this.showCountdown[index] = false;this.countdowns[index] = 0;// Clear only the wrong answer and allow the learner to try again.this.userAnswers[index] = '';// Turn off the global "checked" flag so inputs are not stuck red.// (If you track per-question flags, toggle those instead.)this.isChecked = false;}private startGlobalCountdown(): void {if (this.globalCountdownActive) return; // prevent duplicatesthis.globalCountdownActive = true;this.showGlobalCountdown = true;this.globalCountdown = this.COUNTDOWN_SECS;this.globalTimer = setInterval(() => {this.globalCountdown--;if (this.globalCountdown <= 0) {this.stopGlobalCountdown();}}, 1000);}private stopGlobalCountdown(): void {if (this.globalTimer) {clearInterval(this.globalTimer);this.globalTimer = null;}this.showGlobalCountdown = false;this.globalCountdownActive = false;this.globalCountdown = 0;}ngOnDestroy(): void {this.stopGlobalCountdown();}private startOverlay(baseText: string, seconds: number = this.COUNTDOWN_SECS): void {if (this.globalTimer) { clearTimeout(this.globalTimer as any); this.globalTimer = null; }if (this.overlayTicker) { clearInterval(this.overlayTicker); this.overlayTicker = null; }this.globalCountdownActive = true;this.showGlobalCountdown = true;this.overlayCaption = baseText;this.globalCountdown = seconds;this.overlayEndTs = Date.now() + seconds * 1000;this.ringDashoffset = this.ringCircumference;this.overlayTicker = setInterval(() => {const now = Date.now();const remainingMs = Math.max(0, this.overlayEndTs - now);const elapsedMs = seconds * 1000 - remainingMs;this.globalCountdown = Math.ceil(remainingMs / 1000);const progress = Math.min(1, elapsedMs / (seconds * 1000));this.ringDashoffset = this.ringCircumference * (1 - progress);if (remainingMs <= 0) this.stopOverlay();}, 50) as any;this.globalTimer = setTimeout(() => this.stopOverlay(), seconds * 1000) as any;}private stopOverlay(): void {if (this.overlayTicker) { clearInterval(this.overlayTicker); this.overlayTicker = null; }if (this.globalTimer) { clearTimeout(this.globalTimer as any); this.globalTimer = null; }this.showGlobalCountdown = false;this.globalCountdownActive = false;this.overlayCaption = '';this.globalCountdown = 0;this.ringDashoffset = this.ringCircumference;}ringRadius = 90;ringCircumference = 2 * Math.PI * this.ringRadius;ringDashoffset = this.ringCircumference;private overlayTicker: any = null;private overlayEndTs = 0;}
.gitignore+23
src/app/generate-questions/generate-questions.component.css+258-114
src/app/generate-questions/generate-questions.component.html+34-50
src/app/generate-questions/generate-questions.component.ts+403-272