-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
188 lines (172 loc) · 8.07 KB
/
index.html
File metadata and controls
188 lines (172 loc) · 8.07 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
<!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-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
<style>
body {
background-color: #f8f9fa;
padding-top: 50px;
}
.container {
max-width: 1200px;
}
.welcome-card {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-bottom: 30px;
}
.navbar {
margin-bottom: 30px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<a class="navbar-brand" href="#">peerBench QA</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link active" href="index.html">Home</a>
</li>
</ul>
<div class="d-flex">
<div id="userSection" style="display: none;">
<span id="welcomeUser" class="me-2"></span>
<button id="logoutBtn" class="btn btn-outline-danger">Logout</button>
</div>
<div id="guestSection">
<a href="login.html" class="btn btn-outline-primary">Login / Sign Up</a>
</div>
</div>
</div>
</div>
</nav>
<div class="container mt-5 pt-5">
<div class="welcome-card">
<h1>Welcome </h1>
<p>You can use this platform as a guest or <a href="login.html">create an account</a> to track your progress and access more features.</p>
</div>
<div class="row">
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Practice Questions</h5>
<p class="card-text">Access thousands of high-quality practice questions with detailed explanations.</p>
<a href="app.html" class="btn btn-primary">Start Practicing</a>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Upload New Test Data</h5>
<p class="card-text">Upload your own question sets in JSON or JSONL format following the medQA schema.</p>
<a href="upload.html" class="btn btn-primary">Upload Data</a>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Data and Options</h5>
<p class="card-text">View database statistics, stored configurations, and manage application settings.</p>
<a href="dataOptions.html" class="btn btn-primary">View Data</a>
</div>
</div>
</div>
</div>
</div>
<script>
// Initialize Supabase client
const supabaseUrl = 'https://jrfpjposoiuqdadqjfww.supabase.co';
const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyZnBqcG9zb2l1cWRhZHFqZnd3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDUwNzU3NzgsImV4cCI6MjA2MDY1MTc3OH0.iAvSNpaJwqgKBwCaNuIt5wjGe1cLckNMK2Mo3bz2WXQ';
const supabaseClient = supabase.createClient(supabaseUrl, supabaseAnonKey);
// DOM Elements
const userSection = document.getElementById('userSection');
const guestSection = document.getElementById('guestSection');
const welcomeUser = document.getElementById('welcomeUser');
const logoutBtn = document.getElementById('logoutBtn');
// Check if user is logged in
async function checkSession() {
const { data, error } = await supabaseClient.auth.getSession();
if (data && data.session) {
// User is logged in, show user section
userSection.style.display = 'block';
guestSection.style.display = 'none';
// 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;
}
} else {
// User is not logged in, show guest section
userSection.style.display = 'none';
guestSection.style.display = 'block';
}
}
// Handle logout
if (logoutBtn) {
logoutBtn.addEventListener('click', async () => {
const { error } = await supabaseClient.auth.signOut();
if (!error) {
// Clear local storage and reload page
localStorage.removeItem('userId');
localStorage.removeItem('userName');
window.location.reload();
}
});
}
// Run on page load
document.addEventListener('DOMContentLoaded', () => {
checkSession();
});
</script>
</body>
</html>