mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
cannot fix issue with elapsed timer on admin dashboard. fixing issues with QR code editing.
Grey = cant click Red = current Green = complete blue = skipped?
This commit is contained in:
1 parent
7d6b73ffb4
commit
0afa6817a8
12 files changed
+1529
-211
No files matched your search
@@ -41,14 +41,23 @@ export async function GET(request, context) {
|
||||
return Response.json({ error: "Clue not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Get timestamp parameter to determine if this is a refresh call
|
||||
const timestamp = request.nextUrl?.searchParams?.get("t");
|
||||
const isRefresh = timestamp && !isNaN(parseInt(timestamp));
|
||||
|
||||
// Check if this team has found this clue before
|
||||
const found = await queryOne(
|
||||
"SELECT * FROM team_clues WHERE team_id = ? AND clue_id = ?",
|
||||
[token.teamId, clueId]
|
||||
);
|
||||
|
||||
// If not found yet, mark it as found now
|
||||
if (!found) {
|
||||
// Only mark as "foundNow" if:
|
||||
// 1. The clue was not found before
|
||||
// 2. This is not a refresh request (or we can't determine)
|
||||
// 3. The user is not an admin (admins don't need "foundNow" animations)
|
||||
let foundNow = false;
|
||||
|
||||
if (!found && (!isRefresh || token.role !== "admin")) {
|
||||
try {
|
||||
// First ensure the team_clues table exists
|
||||
await queryOne(`
|
||||
@@ -67,25 +76,41 @@ export async function GET(request, context) {
|
||||
"INSERT INTO team_clues (team_id, clue_id) VALUES (?, ?)",
|
||||
[token.teamId, clueId]
|
||||
);
|
||||
|
||||
// Set foundNow flag for non-admin users only
|
||||
foundNow = token.role !== "admin";
|
||||
|
||||
console.log(
|
||||
`Clue ${clueId} marked as found for team ${token.teamId}, foundNow=${foundNow}`
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Error marking clue as found:", err);
|
||||
// Continue even if there's an error recording the find
|
||||
}
|
||||
}
|
||||
|
||||
// Add different cache headers for admins vs regular users
|
||||
const cacheHeaders =
|
||||
token.role === "admin"
|
||||
? {
|
||||
"Cache-Control": "private, max-age=10", // Allow 10 seconds of caching for admins
|
||||
Pragma: "no-cache",
|
||||
Expires: "0",
|
||||
}
|
||||
: {
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
Expires: "0",
|
||||
};
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
...clue,
|
||||
found: !!found,
|
||||
foundNow: !found,
|
||||
found: true, // Always return as found since the user is viewing it
|
||||
foundNow, // Only true during initial discovery for non-admins
|
||||
isAdmin: token.role === "admin", // Add flag so client knows user is admin
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
Expires: "0",
|
||||
},
|
||||
}
|
||||
{ headers: cacheHeaders }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching clue:", error);
|
||||
|
||||
Reference in new issue
Block a user