-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.html
More file actions
199 lines (179 loc) · 9.56 KB
/
app.html
File metadata and controls
199 lines (179 loc) · 9.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>peerBench QA</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
</head>
<body>
<div class="container">
<header class="py-3 d-flex justify-content-between align-items-center">
<h1 class="text-center">peerBench QA Questions</h1>
<div id="userInfo" class="text-end">
<span id="welcomeUser" class="me-2"></span>
<a href="index.html" class="btn btn-sm btn-outline-secondary me-2">Home</a>
<button id="logoutBtn" class="btn btn-sm btn-outline-danger">Logout</button>
</div>
</header>
<main>
<div id="loading" class="text-center py-5">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p>Loading questions...</p>
</div>
<div id="question-container" class="card my-4" style="display: none;">
<div class="card-body">
<div class="question-header d-flex justify-content-between">
<span id="question-number" class="badge bg-primary">Question 1/20</span>
<span id="question-set" class="badge bg-secondary"></span>
</div>
<h4 id="question-text" class="card-title my-3"></h4>
<div id="options-container" class="my-3">
<!-- Options will be dynamically added here -->
</div>
<!-- Debug info section -->
<div id="debug-info" class="mt-4 pt-2 border-top" style="display: none;">
<div class="small text-muted">
<p class="mb-1"><strong>Debug Information:</strong></p>
<p class="mb-0" id="debug-question-id"></p>
<p class="mb-0" id="debug-question-set"></p>
<p class="mb-0" id="debug-question-hash"></p>
<p class="mb-0" id="debug-src-question-hash"></p>
<p class="mb-0" id="debug-src-question-uid"></p>
<p class="mb-0" id="debug-src-file-content-hash"></p>
</div>
</div>
</div>
</div>
<div id="feedback-container" class="card my-4" style="display: none;">
<div class="card-body">
<div id="result-feedback" class="alert mb-3"></div>
<div id="correct-answer-display"></div>
<div class="mt-3">
<button id="flag-answer-btn" class="btn btn-warning">Flag Question/Answer</button>
<button id="continue-btn" class="btn btn-primary float-end">Next Question</button>
</div>
</div>
</div>
<div id="flag-form-container" class="card my-4" style="display: none;">
<div class="card-body">
<h4>Flag this question</h4>
<div class="form-check my-2">
<input class="form-check-input" type="radio" name="flag-reason" id="incorrect-answer" value="incorrect-answer">
<label class="form-check-label" for="incorrect-answer">
Answer is wrong
</label>
</div>
<div class="form-check my-2">
<input class="form-check-input" type="radio" name="flag-reason" id="confusing-question" value="confusing-question">
<label class="form-check-label" for="confusing-question">
Nonsense question
</label>
</div>
<div class="form-group mt-3">
<label for="flag-details">Additional details (optional):</label>
<textarea class="form-control" id="flag-details" rows="3"></textarea>
</div>
<div class="mt-3">
<button id="submit-flag-btn" class="btn btn-warning">Submit Flag</button>
<button id="cancel-flag-btn" class="btn btn-secondary">Cancel</button>
</div>
</div>
</div>
<div id="completion-container" class="card my-4 text-center" style="display: none;">
<div class="card-body">
<h3>You've completed all available questions!</h3>
<p>Thank you for practicing with our USMLE question bank.</p>
<button id="restart-btn" class="btn btn-primary">Load More Questions</button>
</div>
</div>
</main>
<footer class="text-center py-3 mt-5">
<p>peerBench QA App</p>
</footer>
</div>
<script>
// Initialize Supabase client
const supabaseUrl = 'https://jrfpjposoiuqdadqjfww.supabase.co';
const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyZnBqcG9zb2l1cWRhZHFqZnd3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDUwNzU3NzgsImV4cCI6MjA2MDY1MTc3OH0.iAvSNpaJwqgKBwCaNuIt5wjGe1cLckNMK2Mo3bz2WXQ';
// Store values in the global window object for app.js to use
window.supabaseUrl = supabaseUrl;
window.supabaseAnonKey = supabaseAnonKey;
window.supabaseClient = supabase.createClient(supabaseUrl, supabaseAnonKey);
// DOM Elements for user info
const welcomeUser = document.getElementById('welcomeUser');
const logoutBtn = document.getElementById('logoutBtn');
// Check if user is logged in and display info
async function checkSession() {
const { data, error } = await supabaseClient.auth.getSession();
if (data && data.session) {
// Get user info
const { data: userData } = await supabaseClient.auth.getUser();
if (userData && userData.user) {
// Store user ID
const userId = userData.user.id;
localStorage.setItem('userId', userId);
// Get email if available
const userEmail = userData.user.email || "";
// Try to get named value from user_fingerprints table
let displayName = "";
// First check localStorage for named value
const storedName = localStorage.getItem('userName');
if (storedName) {
displayName = storedName;
} else {
// Try to fetch named from user_fingerprints table
try {
const { data: fingerprintData, error: fingerprintError } = await supabaseClient
.from('user_fingerprints')
.select('named')
.eq('user_id', userId)
.single();
if (!fingerprintError && fingerprintData && fingerprintData.named) {
displayName = fingerprintData.named;
// Store for future use
localStorage.setItem('userName', displayName);
}
} catch (e) {
console.error("Error fetching user fingerprint data:", e);
}
}
// Update welcome message with user ID, email and name if available
let welcomeMessage = `ID: <span style="font-size: 0.8rem;">${userId}</span>`;
if (userEmail) {
welcomeMessage += ` | Email: ${userEmail}`;
}
if (displayName) {
welcomeMessage += ` | Name: ${displayName}`;
}
welcomeUser.innerHTML = welcomeMessage;
}
}
}
// Handle logout
if (logoutBtn) {
logoutBtn.addEventListener('click', async () => {
const { error } = await supabaseClient.auth.signOut();
if (!error) {
// Clear local storage and redirect to home
localStorage.removeItem('userId');
localStorage.removeItem('userName');
window.location.href = 'index.html';
}
});
}
// Run on page load
document.addEventListener('DOMContentLoaded', () => {
checkSession();
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-sha256@0.9.0/src/sha256.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fingerprintjs2@2.1.4/dist/fingerprint2.min.js"></script>
<script src="app.js"></script>
</body>
</html>