Refactor Footer and Header components for improved layout; enhance FlagQuiz with question re-rendering and state management

This commit is contained in:
sHa
2025-08-11 19:34:33 +03:00
parent bf615ff94f
commit 889514ad45
3 changed files with 87 additions and 40 deletions

View File

@@ -4,8 +4,9 @@
<footer>
<div class="footer-flex">
<span class="footer-left">shadoll Logo Gallery</span>
<span class="footer-center">All logos are property of their respective owners.</span>
<div class="footer-bottom">
<span class="footer-left">shadoll Logo Gallery and Quiz game</span>
<a
href="https://github.com/shadoll/sLogos"
target="_blank"
@@ -23,13 +24,12 @@
/></svg>
</a>
</div>
</footer>
<style>
</div>
</footer><style>
footer {
padding: 1.5rem;
background: var(--color-background);
color: var(--color-text-muted);
color: var(--color-text-secondary);
border-top: 1px solid var(--color-border);
font-size: 0.9rem;
margin-top: auto;
@@ -43,19 +43,24 @@
gap: 1em;
}
.footer-left {
flex: 1;
text-align: left;
}
.footer-center {
flex: 2;
text-align: center;
}
.footer-bottom {
display: flex;
align-items: center;
justify-content: space-between;
flex: 1;
gap: 1em;
}
.footer-left {
text-align: left;
}
.footer-github {
flex: 0;
margin-left: 1em;
display: inline-flex;
align-items: center;
}
@@ -63,16 +68,27 @@
@media (max-width: 700px) {
.footer-flex {
flex-direction: column;
align-items: flex-start;
gap: 0.3em;
align-items: center;
gap: 0.5em;
}
.footer-left, .footer-center {
text-align: left;
.footer-center {
text-align: center;
width: 100%;
margin-bottom: 0.3em;
}
.footer-bottom {
width: 100%;
justify-content: space-between;
}
.footer-left {
text-align: left;
}
.footer-github {
margin-left: 0;
margin-top: 0.5em;
margin-left: auto;
}
}
</style>

View File

@@ -399,10 +399,6 @@
color: #6b7280; /* gray */
}
.achievement-block {
margin-left: auto;
}
@media (max-width: 700px) {
.header-row {
grid-template-columns: 1fr auto auto;

View File

@@ -33,6 +33,9 @@
let timerDuration = 2000; // 2 seconds
let timerStartTime = 0;
// Force component re-render key to prevent button state persistence
let questionKey = 0;
// Scoring
let score = { correct: 0, total: 0, skipped: 0 };
let gameStats = { correct: 0, wrong: 0, total: 0, skipped: 0 };
@@ -206,6 +209,26 @@
// Cancel any active auto-advance timer
cancelAutoAdvanceTimer();
// Increment question key to force complete re-render and clear button states
questionKey++;
// Remove focus from any previously focused buttons and ensure clean state
if (typeof document !== 'undefined') {
// Use setTimeout to ensure DOM updates are complete
setTimeout(() => {
const activeElement = document.activeElement;
if (activeElement && activeElement.tagName === 'BUTTON') {
activeElement.blur();
}
// Force removal of any residual button states
const buttons = document.querySelectorAll('.option, .flag-option');
buttons.forEach(button => {
button.blur();
button.classList.remove('selected', 'correct', 'wrong');
});
}, 0);
}
// Randomly choose question type
questionType = Math.random() < 0.5 ? 'flag-to-country' : 'country-to-flag';
@@ -647,7 +670,7 @@
<img src={getFlagImage(currentQuestion.correct)} alt="Flag" class="quiz-flag" />
</div>
<div class="options">
<div class="options" key={questionKey}>
{#each currentQuestion.options as option, index}
<button
class="option"
@@ -684,7 +707,7 @@
</h2>
</div>
<div class="flag-options">
<div class="flag-options" key={questionKey}>
{#each currentQuestion.options as option, index}
<button
class="flag-option"
@@ -1078,6 +1101,12 @@
background: var(--color-bg-hover);
}
/* Prevent residual hover states on new questions */
.option:not(:hover):not(.selected):not(.correct):not(.wrong) {
border-color: var(--color-border);
background: var(--color-bg-primary);
}
.option.selected {
border-color: var(--color-primary);
background: var(--color-primary-light);
@@ -1119,6 +1148,12 @@
background: var(--color-bg-hover);
}
/* Prevent residual hover states on new questions for flag options */
.flag-option:not(:hover):not(.selected):not(.correct):not(.wrong) {
border-color: var(--color-border);
background: var(--color-bg-primary);
}
.flag-option.selected {
border-color: var(--color-primary);
background: var(--color-primary-light);