Skip to content

Commit 2522527

Browse files
committed
fix(ui): improve layout and spacing in Typing Speed Tester modal
1 parent 8369178 commit 2522527

1 file changed

Lines changed: 89 additions & 86 deletions

File tree

web-app/js/projects/typing-speed-tester.js

Lines changed: 89 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ function getTypingSpeedTesterHTML() {
33
<style>
44
.typing-tester {
55
display: grid;
6-
gap: 1.5rem;
7-
min-height: 640px;
6+
gap: 1rem;
7+
min-height: auto;
8+
padding: 1rem;
89
}
910
<div class="project-content">
1011
@@ -117,7 +118,7 @@ function getTypingSpeedTesterHTML() {
117118
118119
.typing-tester .hero {
119120
display: grid;
120-
gap: 1.5rem;
121+
gap: 1rem;
121122
justify-items: center;
122123
text-align: center;
123124
max-width: 740px;
@@ -173,21 +174,12 @@ function getTypingSpeedTesterHTML() {
173174
color: var(--on-accent);
174175
border-color: var(--accent-color);
175176
}
176-
if (
177-
!sentenceElement ||
178-
!inputElement ||
179-
!button ||
180-
!newSentenceBtn ||
181-
!result
182-
) {
183-
return;
184-
}
177+
185178
186179
let startTime = null;
187180
let currentSentence = "";
188181
189-
inputElement.disabled = true;
190-
inputElement.setAttribute("aria-disabled", "true");
182+
191183
192184
.typing-tester .hero-footer {
193185
display: flex;
@@ -235,7 +227,7 @@ function getTypingSpeedTesterHTML() {
235227
}
236228
237229
.typing-tester .sentence-card {
238-
min-height: 140px;
230+
min-height: 100px;
239231
border-radius: 22px;
240232
padding: 1.4rem;
241233
background: var(--surface-color);
@@ -315,7 +307,7 @@ function getTypingSpeedTesterHTML() {
315307
align-items: center;
316308
justify-content: center;
317309
border-radius: 999px;
318-
padding: 0.95rem 1.7rem;
310+
padding: 0.7rem 1.2rem;
319311
transition: transform 0.2s ease, box-shadow 0.2s ease;
320312
}
321313
@@ -342,42 +334,44 @@ function getTypingSpeedTesterHTML() {
342334
transform: translateY(-2px) scale(0.995);
343335
box-shadow: 0 8px 20px rgba(34,197,94,0.14);
344336
}
345-
inputElement.addEventListener("input", function () {
337+
346338
347339
if (!startTime || !currentSentence) return;
348340
349341
const typedText = inputElement.value;
350342
const totalTime = Math.max((Date.now() - startTime) / 1000, 0.001);
351343
352-
/* Top stats bar */
353-
.typing-tester .stats-bar {
354-
display: grid;
355-
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
356-
gap: 0.75rem;
357-
align-items: center;
358-
}
344+
.typing-tester .compact-stats-bar {
345+
display: flex;
346+
flex-wrap: wrap;
359347
360-
.typing-tester .stats-bar .stat-item {
361-
background: var(--panel-color);
362-
border: 1px solid var(--border-color);
363-
border-radius: 12px;
364-
padding: 0.65rem 0.9rem;
365-
display: flex;
366-
flex-direction: column;
367-
gap: 0.35rem;
368-
align-items: center;
369-
text-align: center;
370-
}
348+
justify-content: space-evenly;
349+
align-items: center;
371350
372-
.typing-tester .stat-item .badge {
373-
display: block;
374-
color: var(--text-secondary);
375-
text-transform: uppercase;
376-
letter-spacing: 0.18em;
377-
font-size: 0.75rem;
351+
padding: 12px 20px;
352+
margin-bottom: 1rem;
353+
354+
background: var(--panel-color);
355+
border: 1px solid var(--border-color);
356+
border-radius: 14px;
357+
358+
font-size: 15px;
359+
font-weight: 600;
360+
}
361+
.typing-tester .compact-stat {
362+
white-space: nowrap;
363+
padding: 0 18px;
378364
}
379365
380-
.typing-tester .stat-item .stat-value { font-weight: 800; font-size: 1.05rem; color: var(--accent-color); }
366+
.typing-tester .compact-stats-bar span {
367+
white-space: nowrap;
368+
color: var(--text-color);
369+
}
370+
371+
.typing-tester .compact-stats-bar strong {
372+
color: var(--accent-color);
373+
font-weight: 700;
374+
}
381375
382376
.typing-tester .game-top {
383377
display: grid;
@@ -386,7 +380,7 @@ function getTypingSpeedTesterHTML() {
386380
text-align: center;
387381
margin-bottom: 1.25rem;
388382
}
389-
for (let i = 0; i < spans.length; i++) {
383+
390384
spans[i].style.color = "";
391385
}
392386
@@ -400,21 +394,29 @@ function getTypingSpeedTesterHTML() {
400394
justify-content: center;
401395
}
402396
403-
.typing-tester .result-panel {
404-
background: var(--panel-color);
405-
border: 1px solid var(--border-color);
406-
border-radius: 20px;
407-
padding: 1.3rem;
408-
color: var(--text-color);
409-
min-height: 120px;
410-
line-height: 1.75;
411-
white-space: pre-wrap;
412-
}
397+
.typing-tester .result-summary {
398+
line-height: 1.4 !important;
399+
padding: 1.2rem !important;
400+
}
401+
402+
.typing-tester .result-panel {
403+
background: var(--panel-color);
404+
border: 1px solid var(--border-color);
405+
border-radius: 20px;
406+
padding: 1rem 1.2rem;
407+
color: var(--text-color);
408+
409+
min-height: auto;
410+
411+
line-height: 1.3;
412+
413+
white-space: pre-line;
414+
}
413415
414416
.typing-tester .stats-grid {
415417
display: grid;
416-
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
417-
gap: 0.75rem;
418+
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
419+
gap: 0.5rem;
418420
}
419421
if (spans[i]) spans[i].style.color = "#22c55e";
420422
@@ -472,18 +474,18 @@ function getTypingSpeedTesterHTML() {
472474
</div>
473475
</section>
474476
475-
<section class="stage stage-result hidden">
476-
<div class="typing-panel">
477-
<div class="sentence-card result-summary" id="resultSummary">
478-
<h3 id="resultMessage">Results</h3>
479-
<div style="margin-top:0.75rem;" id="resultDetails">Final results will appear here.</div>
480-
</div>
481-
<div style="display:flex; gap:0.75rem; margin-top:0.75rem;">
482-
<button id="restartBtn" class="btn-play btn-primary">Restart Test</button>
483-
<button id="retryBtn" class="btn-play btn-secondary">Retry Same Difficulty</button>
484-
</div>
485-
</div>
486-
</section>
477+
<section class="stage stage-result hidden">
478+
<div class="typing-panel" style="gap: 0.5rem;">
479+
<div class="sentence-card result-summary" id="resultSummary" style="min-height: auto; padding: 1.2rem;">
480+
<div id="resultMessage" style="font-size: 24px; font-weight: 800; margin: 0 0 0.5rem 0; line-height: 1.2;">Results</div>
481+
<div id="resultDetails" style="margin-top: 0;">Final results will appear here.</div>
482+
</div>
483+
<div style="display:flex; gap:0.75rem; margin-top: 0.5rem; justify-content: center;">
484+
<button id="restartBtn" class="btn-play btn-primary">Restart Test</button>
485+
<button id="retryBtn" class="btn-play btn-secondary">Retry Same Difficulty</button>
486+
</div>
487+
</div>
488+
</section>
487489
488490
<section class="stage stage-game hidden">
489491
<div class="game-top">
@@ -496,13 +498,12 @@ function getTypingSpeedTesterHTML() {
496498
</div>
497499
</div>
498500
499-
<div class="game-header stats-bar" role="region" aria-label="Game stats">
500-
<div class="stat-item"><div class="badge">Difficulty</div><div id="headerDifficulty" class="stat-value">Easy</div></div>
501-
<div class="stat-item"><div class="badge">Time</div><div id="timerDisplay" class="stat-value">60s</div></div>
502-
<div class="stat-item"><div class="badge">WPM</div><div id="headerWpm" class="stat-value">0</div></div>
503-
<div class="stat-item"><div class="badge">Accuracy</div><div id="headerAccuracy" class="stat-value">0%</div></div>
504-
<div class="stat-item"><div class="badge">Mistakes</div><div id="headerMistakes" class="stat-value">0</div></div>
505-
</div>
501+
<div class="compact-stats-bar">
502+
<span class="compact-stat">⏱️ Time: <span id="timerDisplay">40s</span></span>
503+
<span class="compact-stat">🚀 Speed: <span id="headerWpm">0</span> WPM</span>
504+
<span class="compact-stat">🎯 Accuracy: <span id="headerAccuracy">0%</span></span>
505+
<span class="compact-stat">❌ Errors: <span id="headerMistakes">0</span></span>
506+
</div>
506507
507508
<div class="typing-panel">
508509
<div id="typingSentence" class="sentence-card">Pick a difficulty and start the test.</div>
@@ -690,15 +691,19 @@ function initTypingSpeedTester() {
690691
if (headerAccuracy) headerAccuracy.textContent = `${finalAccuracy}%`;
691692
if (headerMistakes) headerMistakes.textContent = finalIncorrect;
692693

693-
resultMessage.textContent = hasTimedOut ? 'Time is up!' : 'Test completed!';
694-
resultDetails.innerHTML = `
695-
<strong>Final WPM:</strong> ${finalWpm} <br>
696-
<strong>Accuracy:</strong> ${finalAccuracy}% <br>
697-
<strong>Total characters typed:</strong> ${finalChars} <br>
698-
<strong>Total mistakes:</strong> ${finalIncorrect} <br>
699-
<strong>Sentences completed:</strong> ${sentencesCompleted} <br>
700-
<strong>Difficulty:</strong> ${formatDifficultyLabel(selectedDifficulty)}
701-
`;
694+
// Remove default margins or native headings completely
695+
resultMessage.innerHTML = hasTimedOut ? '⏱️ Time is up!' : '🎉 Test completed!';
696+
697+
resultDetails.innerHTML = `
698+
<div style="display: flex; flex-direction: column; gap: 0.4rem; padding-top: 0.2rem;">
699+
<div><strong>🚀 Final WPM:</strong> ${finalWpm}</div>
700+
<div><strong>🎯 Accuracy:</strong> ${finalAccuracy}%</div>
701+
<div><strong>⌨️ Total characters typed:</strong> ${finalChars}</div>
702+
<div><strong>❌ Total mistakes:</strong> ${finalIncorrect}</div>
703+
<div><strong>📖 Sentences completed:</strong> ${sentencesCompleted}</div>
704+
<div><strong>⚙️ Difficulty:</strong> ${formatDifficultyLabel(selectedDifficulty)}</div>
705+
</div>
706+
`;
702707

703708
gameStage.classList.add('hidden');
704709
resultStage.classList.remove('hidden');
@@ -893,9 +898,7 @@ function initTypingSpeedTester() {
893898
totalWordsTyped += currentStats.words;
894899
sentencesCompleted += 1;
895900
generateSentence();
896-
inputElement.disabled = true;
897-
inputElement.setAttribute("aria-disabled", "true");
898-
inputElement.blur();
901+
899902
}
900903
});
901904

0 commit comments

Comments
 (0)