Skip to content

Commit fc6b9ad

Browse files
committed
Persist results/review screens across reloads; hide redundant topic icons
1 parent 5185cb5 commit fc6b9ad

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

app.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,52 @@ window.addEventListener('DOMContentLoaded', function(){
2929

3030
/* ── SCREENS ── */
3131
var LS_SCREEN = 'quizhub_last_screen';
32+
var LS_LAST_ATT = 'quizhub_last_screen_att';
3233
var PERSIST_SCREENS = ['screen-hub','screen-ctfl-home','screen-ctai-version','screen-ctai-home','screen-ctai-home-v2','screen-ctai-blitz-version','screen-genai-home','screen-profile'];
34+
var REVIEW_SCREENS = ['screen-results','screen-blitz-review','screen-glossary-review','screen-blitz-results','screen-glossary-results'];
3335
function showScreen(id){
3436
var ss=document.querySelectorAll('.screen');
3537
for(var s=0;s<ss.length;s++) ss[s].classList.remove('active');
3638
document.getElementById(id).classList.add('active');
3739
window.scrollTo(0,0);
3840
try {
39-
if (PERSIST_SCREENS.indexOf(id) >= 0) localStorage.setItem(LS_SCREEN, id);
40-
else localStorage.removeItem(LS_SCREEN);
41+
if (PERSIST_SCREENS.indexOf(id) >= 0) {
42+
localStorage.setItem(LS_SCREEN, id);
43+
localStorage.removeItem(LS_LAST_ATT);
44+
} else if (REVIEW_SCREENS.indexOf(id) >= 0 && lastAttemptId) {
45+
localStorage.setItem(LS_SCREEN, id);
46+
localStorage.setItem(LS_LAST_ATT, lastAttemptId);
47+
} else {
48+
localStorage.removeItem(LS_SCREEN);
49+
localStorage.removeItem(LS_LAST_ATT);
50+
}
4151
} catch(e){}
4252
}
53+
var LIVE_SCREENS = ['screen-exam','screen-blitz','screen-glossary'];
54+
window.addEventListener('beforeunload', function(e){
55+
for (var i=0;i<LIVE_SCREENS.length;i++){
56+
var el = document.getElementById(LIVE_SCREENS[i]);
57+
if (el && el.classList.contains('active')){
58+
e.preventDefault();
59+
e.returnValue = '';
60+
return '';
61+
}
62+
}
63+
});
4364
window.addEventListener('DOMContentLoaded', function(){
4465
try {
4566
var saved = localStorage.getItem(LS_SCREEN);
46-
if (saved && PERSIST_SCREENS.indexOf(saved) >= 0 && document.getElementById(saved)) {
67+
if (!saved || !document.getElementById(saved)) return;
68+
if (PERSIST_SCREENS.indexOf(saved) >= 0) {
4769
if (saved === 'screen-profile') openProfile();
4870
else showScreen(saved);
71+
} else if (REVIEW_SCREENS.indexOf(saved) >= 0) {
72+
var attId = localStorage.getItem(LS_LAST_ATT);
73+
if (!attId) return;
74+
lastAttemptId = attId;
75+
if (saved === 'screen-results') reopenAttempt(attId);
76+
else if (saved === 'screen-blitz-review' || saved === 'screen-blitz-results') reopenBlitzAttempt(attId);
77+
else if (saved === 'screen-glossary-review' || saved === 'screen-glossary-results') reopenGlossaryAttempt(attId);
4978
}
5079
} catch(e){}
5180
});
@@ -550,7 +579,6 @@ function showResults(){
550579
document.getElementById('stat-unanswered').textContent=unanswered;
551580
document.getElementById('review-filter').value='all';
552581
applyFilter();
553-
showScreen('screen-results');
554582
if (!_skipSaveAttempt) {
555583
saveAttempt({
556584
type: 'exam',
@@ -564,6 +592,7 @@ function showResults(){
564592
});
565593
}
566594
_skipSaveAttempt = false;
595+
showScreen('screen-results');
567596
}
568597

569598
/* ── REVIEW ── */
@@ -1121,13 +1150,13 @@ function glossShowResults() {
11211150
gIconEl.setAttribute('data-topic', gTopic);
11221151
}
11231152
document.getElementById('gloss-results-title-text').textContent = gFam + ' Glossary Practice';
1124-
showScreen('screen-glossary-results');
11251153
saveAttempt({
11261154
type: 'glossary',
11271155
pool: glossCurrentPool,
11281156
correct: glossTotalCorrect, total: glossTotalAttempts, pct: pct,
11291157
details: glossDetails.slice()
11301158
});
1159+
showScreen('screen-glossary-results');
11311160
}
11321161

11331162

@@ -1226,14 +1255,14 @@ function blitzShowResults(){
12261255
bIconEl.setAttribute('data-topic', bTopic);
12271256
}
12281257
document.getElementById('blitz-results-title-text').textContent = bFam + ' Lightning Round';
1229-
showScreen('screen-blitz-results');
12301258
saveAttempt({
12311259
type: 'blitz',
12321260
pool: blitzCurrentPool,
12331261
ctaiVersion: (blitzCurrentPool==='ctai' ? blitzCurrentCtaiVersion : undefined),
12341262
correct: blitzCorrect, total: 10, pct: pct, passed: pct>=65,
12351263
details: blitzDetails.slice()
12361264
});
1265+
showScreen('screen-blitz-results');
12371266
}
12381267

12391268
/* ── PROFILE & PERSISTENCE ── */
@@ -1374,6 +1403,7 @@ function reopenAttempt(id){
13741403
questions = (att.mode === 'ctai' ? ctaiPool : att.mode === 'ctfl' ? CTFL_PACKS : PACKS)[String(att.pack)];
13751404
if (!questions) return;
13761405
userAnswers = att.userAnswers;
1406+
lastAttemptId = id;
13771407
_skipSaveAttempt = true;
13781408
showResults();
13791409
}
@@ -1398,6 +1428,7 @@ function poolLabel(pool){
13981428
function reopenBlitzAttempt(id){
13991429
var att = findAttempt(id);
14001430
if (!att || att.type !== 'blitz' || !att.details) return;
1431+
lastAttemptId = id;
14011432

14021433
var rvFam = poolLabel(att.pool);
14031434
if (att.pool === 'ctai') rvFam += ' v' + (att.ctaiVersion === 2 ? '2.0' : '1.0');
@@ -1432,6 +1463,7 @@ var _glossReviewMaxRound = 5;
14321463
function reopenGlossaryAttempt(id){
14331464
var att = findAttempt(id);
14341465
if (!att || att.type !== 'glossary' || !att.details) return;
1466+
lastAttemptId = id;
14351467

14361468
document.getElementById('gloss-review-title').textContent =
14371469
poolLabel(att.pool) + ' Glossary Practice — review';

styles.css

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,7 @@ body{font-family:'Nunito Sans',sans-serif;background:var(--bg);color:var(--text1
161161
.attempt-item[data-topic="ctfl"].clickable:hover{border-color:var(--topic-ctfl);}
162162
.attempt-item[data-topic="ctai"].clickable:hover{border-color:var(--topic-ctai);}
163163
.attempt-item[data-topic="genai"].clickable:hover{border-color:var(--topic-genai);}
164-
.attempt-topic-icon{
165-
flex-shrink:0;
166-
width:36px;height:36px;border-radius:8px;
167-
display:flex;align-items:center;justify-content:center;
168-
background:var(--surface2);
169-
}
170-
.attempt-topic-icon svg{width:20px;height:20px;}
171-
.attempt-topic-icon[data-topic="ctfl"]{color:var(--topic-ctfl);}
172-
.attempt-topic-icon[data-topic="ctai"]{color:var(--topic-ctai-deep);}
173-
.attempt-topic-icon[data-topic="genai"]{color:var(--topic-genai-deep);}
164+
.attempt-topic-icon{display:none;}
174165
.attempt-meta{flex:1;min-width:0;}
175166
.attempt-type{
176167
font-family:'Nunito',sans-serif;font-size:14px;font-weight:800;
@@ -1062,10 +1053,7 @@ body{font-family:'Nunito Sans',sans-serif;background:var(--bg);color:var(--text1
10621053
line-height:1.2;
10631054
display:flex;align-items:center;justify-content:center;gap:12px;
10641055
}
1065-
.results-topic-icon{
1066-
display:inline-flex;align-items:center;justify-content:center;
1067-
width:32px;height:32px;flex-shrink:0;
1068-
}
1056+
.results-topic-icon{display:none;}
10691057
.results-topic-icon svg{width:100%;height:100%;}
10701058
.results-topic-icon[data-topic="ctfl"]{color:var(--topic-ctfl);}
10711059
.results-topic-icon[data-topic="ctai"]{color:var(--topic-ctai-deep);}

0 commit comments

Comments
 (0)