Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions client/private/Advanced/Advance.js
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
function transferProblem(elem) {
const parent = elem.parentElement;
const title = parent.querySelector('h3').textContent;
const description = parent.querySelector('p').textContent;
localStorage.setItem('problemTitle', title);
localStorage.setItem('problemDescription', description);
window.location.href = window.location.origin + "/private/CoderPage/coder.html";
}
// Mobile menu toggle functionality
2 changes: 1 addition & 1 deletion client/private/Arena/modules/ArenaCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ArenaCore {

async loadArenaStats() {
try {
const response = await fetch('/api/arena/stats');
const response = await fetch('/api/arena/system-stats');
if (response.ok) {
const { stats } = await response.json();
this.uiManager.updateArenaStats(stats);
Expand Down
6 changes: 3 additions & 3 deletions client/private/Arena/modules/ArenaUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class ArenaUIManager {
}

updateArenaStats(stats) {
document.getElementById('onlineUsers').textContent = stats.onlineUsers;
document.getElementById('activeMatches').textContent = stats.activeMatches;
document.getElementById('totalMatches').textContent = stats.totalMatches;
document.getElementById('onlineUsers').textContent = stats.onlinePlayersCount || 0;
document.getElementById('activeMatches').textContent = stats.activeMatchesCount || 0;
document.getElementById('totalMatches').textContent = stats.totalMatchesCount || 0;
}

updatePlayerStats(stats) {
Expand Down
38 changes: 26 additions & 12 deletions client/private/CoderPage/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

// Mobile menu toggle functionality
const menuToggle = document.getElementById('menu-toggle');
const closeBtn = document.getElementById('close-btn');
const sidebar = document.getElementById('sidebar');

const outputBox = document.getElementById('output-box');
Expand Down Expand Up @@ -181,7 +180,7 @@

// Utility function to get URL parameters
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');

Check warning on line 183 in client/private/CoderPage/coder.js

View workflow job for this annotation

GitHub Actions / quality-check

Unnecessary escape character: \[
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
const results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
Expand Down Expand Up @@ -262,6 +261,7 @@
}, 500); // Small delay to ensure DOM is ready
}

// eslint-disable-next-line no-unused-vars
async function runCode(btn) {
btn.textContent = 'Running...';
btn.disabled = true;
Expand Down Expand Up @@ -328,6 +328,7 @@
}

// Submit solution function
// eslint-disable-next-line no-unused-vars
async function submitSolution(btn) {
if (!currentProblem) {
alert('No problem loaded. Please try refreshing the page.');
Expand Down Expand Up @@ -365,18 +366,29 @@
if (data.success) {
displaySubmissionResults(data.submission);

// AI assistance for failed test cases (Easy problems only)
if (aiAssistanceInstance && currentProblem && currentProblem.difficulty === 'easy' &&
data.submission.status !== 'accepted' && data.submission.testResults) {
// Handle successful test completion - disable AI assistance if all tests pass
if (data.submission.status === 'accepted') {
console.log('🎉 All tests passed! Disabling AI assistance...');

// Analyze failed test cases with AI
aiAssistanceInstance.analyzeTestCaseFailure({
status: data.submission.status,
testCasesPassed: data.submission.testCasesPassed,
totalTestCases: data.submission.totalTestCases,
testResults: data.submission.testResults.filter(test => !test.passed),
feedback: data.submission.feedback
});
// Disable AI assistance since the problem is solved correctly
if (aiAssistanceInstance) {
aiAssistanceInstance.disableForSuccess();
console.log('✅ AI assistance disabled - problem solved successfully!');
}
} else {
// AI assistance for failed test cases (Easy problems only)
if (aiAssistanceInstance && currentProblem && currentProblem.difficulty === 'easy' &&
data.submission.testResults) {

// Analyze failed test cases with AI
aiAssistanceInstance.analyzeTestCaseFailure({
status: data.submission.status,
testCasesPassed: data.submission.testCasesPassed,
totalTestCases: data.submission.totalTestCases,
testResults: data.submission.testResults.filter(test => !test.passed),
feedback: data.submission.feedback
});
}
}

// Handle different solve scenarios
Expand Down Expand Up @@ -836,6 +848,8 @@
outputBox.className = isAccepted ? 'output-success' : 'output-error';
}

// Language change function
// eslint-disable-next-line no-unused-vars
function changeLang(list) {
const selectedLang = list.value;

Expand Down
15 changes: 1 addition & 14 deletions client/private/Easy/beginer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Mobile menu toggle functionality
const menuToggle = document.getElementById('menu-toggle');
const closeBtn = document.getElementById('close-btn');
const sidebar = document.getElementById('sidebar');

menuToggle.addEventListener('click', (e) => {
Expand All @@ -9,11 +8,6 @@ menuToggle.addEventListener('click', (e) => {
document.body.classList.toggle('no-scroll');
});

closeBtn.addEventListener('click', () => {
sidebar.classList.remove('active');
document.body.classList.remove('no-scroll');
});

// Close sidebar when clicking anywhere except the sidebar itself
document.addEventListener('click', (e) => {
// Check if the click is outside the sidebar and the menu toggle button
Expand All @@ -28,11 +22,4 @@ sidebar.addEventListener('click', (e) => {
e.stopPropagation();
});

function transferProblem(elem) {
const parent = elem.parentElement;
const title = parent.querySelector('h3').textContent;
const description = parent.querySelector('p').textContent;
localStorage.setItem('problemTitle', title);
localStorage.setItem('problemDescription', description);
window.location.href = window.location.origin + "/private/CoderPage/coder.html";
}
// Mobile menu toggle functionality
11 changes: 9 additions & 2 deletions client/private/HomePage/codigo.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<link rel="stylesheet" href="codigo.css">
<link rel="shortcut icon" href="assets/web-development.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">

<!-- Clerk auth library -->
<script async crossorigin="anonymous"
data-clerk-publishable-key="pk_test_aGFybWxlc3Mtd2VldmlsLTE1LmNsZXJrLmFjY291bnRzLmRldiQ"
src="https://harmless-weevil-15.clerk.accounts.dev/npm/@clerk/clerk-js@5/dist/clerk.browser.js"
type="text/javascript"></script>
</head>

<body class="dark-theme">
Expand All @@ -29,7 +35,7 @@
<option value="dark-theme" selected>Dark theme</option>
<option value="light-theme">Light theme</option>
</select>
<a href="../LandingPage/index.html" class="logout-btn">Logout</a>
<button onclick="authManager.logout()" class="logout-btn">Logout</button>
</li>
</ul>
</nav>
Expand Down Expand Up @@ -75,7 +81,7 @@ <h2><span class="profile-icon-svg"><svg width="30px" height="30px" viewBox="0 0
<h2 id="stats">📊 Quick stats</h2>
<ul>
<li>⭐ Current Rank: #<span id="dashboard_currRank">001</span></li>
<li>🏆 Contests Won: <span id="dashboard_contestCount">777</span></li>
<li>🏆 Arena Matches Won: <span id="dashboard_contestCount">0</span></li>
<li>🔥 Streak: <span id="dashboard_streakCount">04</span> Days</li>
<li>🎯 Next Contest: Code Sprint in 2h 30m</li>
</ul>
Expand Down Expand Up @@ -460,6 +466,7 @@ <h2 class="heading">Contact</h2>
});
})();
</script>
<script src="../common/auth.js"></script>
<script src="script.js"></script>
</body>

Expand Down
67 changes: 35 additions & 32 deletions client/private/HomePage/script.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
// @author Rouvik Maji
// @author Rouvik Maji & Archisman Pal
async function updateUserDetails()
{
const username = document.getElementById("dashboard_username");
const currRank = document.getElementById("dashboard_currRank");
const contestCount = document.getElementById("dashboard_contestCount");
const streakCount = document.getElementById("dashboard_streakCount");

// New detailed stats elements
const totalProblems = document.getElementById("dashboard_totalProblems");
const easyCount = document.getElementById("dashboard_easyCount");
const mediumCount = document.getElementById("dashboard_mediumCount");
const hardCount = document.getElementById("dashboard_hardCount");
// DOM elements are accessed in updateStatsDisplay function

try {
// Check if stats were updated from localStorage first
Expand All @@ -29,18 +20,40 @@
}
}

// Otherwise fetch from server
const res = await fetch(window.location.origin + '/api/userdata');
const data = await res.json();
// Fetch user basic data
const userResponse = await fetch('/api/userdata');

updateStatsDisplay(data);
// Fetch detailed user stats
const statsResponse = await fetch('/api/user/stats');

if (userResponse.ok && statsResponse.ok) {
const userData = await userResponse.json();
const statsData = await statsResponse.json();

// Combine the data - use rankPosition for display instead of rank points
const combinedData = {
name: userData.name || 'User',
rank: statsData.stats.rankPosition || 0, // Use actual leaderboard position
arenaWins: statsData.stats.arena?.wins || 0, // Arena matches won
streak_count: statsData.stats.streak_count || 0,
problemsSolved: statsData.stats.problemsSolved || 0,
easyCount: statsData.stats.easyCount || 0,
mediumCount: statsData.stats.mediumCount || 0,
hardCount: statsData.stats.hardCount || 0,
realWorldCount: statsData.stats.realWorldCount || 0
};

updateStatsDisplay(combinedData);
} else {
throw new Error('Failed to fetch user data or stats');
}
} catch (error) {
console.error('Failed to update user details:', error);
// Set default values if fetch fails
updateStatsDisplay({
name: 'User',
rank: 0,
contests_count: 0,
arenaWins: 0, // Default arena wins to 0
streak_count: 0,
problemsSolved: 0,
easyCount: 0,
Expand All @@ -63,7 +76,7 @@

username.textContent = data.name || 'User';
currRank.textContent = data.rank || '0';
contestCount.textContent = data.contests_count || '0';
contestCount.textContent = data.arenaWins || '0'; // Display arena wins instead of contests
streakCount.textContent = data.streak_count || '0';

// Update detailed problem stats
Expand All @@ -74,7 +87,7 @@
}

// Show brief notification when stats are updated
function showStatsUpdateNotification(stats) {

Check warning on line 90 in client/private/HomePage/script.js

View workflow job for this annotation

GitHub Actions / quality-check

'stats' is defined but never used
const notification = document.createElement('div');
notification.className = 'stats-update-notification';
notification.innerHTML = `
Expand Down Expand Up @@ -150,10 +163,10 @@
}

// Arena Data Loading Functions
async function loadArenaData() {

Check warning on line 166 in client/private/HomePage/script.js

View workflow job for this annotation

GitHub Actions / quality-check

'loadArenaData' is defined but never used
try {
// Load Arena stats
const statsResponse = await fetch('/api/arena/stats');
// Load Arena system stats (online users, active matches, total matches)
const statsResponse = await fetch('/api/arena/system-stats');
if (statsResponse.ok) {
const { stats } = await statsResponse.json();
updateArenaStats(stats);
Expand All @@ -171,9 +184,9 @@
}

function updateArenaStats(stats) {
document.getElementById('arenaOnlineUsers').textContent = stats.onlineUsers || 0;
document.getElementById('arenaActiveMatches').textContent = stats.activeMatches || 0;
document.getElementById('arenaTotalMatches').textContent = stats.totalMatches || 0;
document.getElementById('arenaOnlineUsers').textContent = stats.onlinePlayersCount || 0;
document.getElementById('arenaActiveMatches').textContent = stats.activeMatchesCount || 0;
document.getElementById('arenaTotalMatches').textContent = stats.totalMatchesCount || 0;
}

function updateArenaLeaderboard(leaderboard) {
Expand All @@ -198,8 +211,6 @@
</div>
`).join('');
}

// Add Arena data loading to the existing initialization
document.addEventListener('DOMContentLoaded', function() {
// 1. Navigation Toggle
const nav = document.querySelector('.codingPageNav');
Expand Down Expand Up @@ -382,12 +393,4 @@
});

updateUserDetails(); // update the user details once all listeners have been added
// Load Arena data when the page loads
loadArenaData();

// Refresh Arena data every 30 seconds
setInterval(loadArenaData, 30000);
});

// Make loadArenaData globally available for the refresh button
window.loadArenaData = loadArenaData;
15 changes: 1 addition & 14 deletions client/private/Intermediate/interemdiate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Mobile menu toggle functionality
const menuToggle = document.getElementById('menu-toggle');
const closeBtn = document.getElementById('close-btn');
const sidebar = document.getElementById('sidebar');

menuToggle.addEventListener('click', (e) => {
Expand All @@ -9,11 +8,6 @@ menuToggle.addEventListener('click', (e) => {
document.body.classList.toggle('no-scroll');
});

closeBtn.addEventListener('click', () => {
sidebar.classList.remove('active');
document.body.classList.remove('no-scroll');
});

// Close sidebar when clicking anywhere except the sidebar itself
document.addEventListener('click', (e) => {
// Check if the click is outside the sidebar and the menu toggle button
Expand All @@ -28,11 +22,4 @@ sidebar.addEventListener('click', (e) => {
e.stopPropagation();
});

function transferProblem(elem) {
const parent = elem.parentElement;
const title = parent.querySelector('h3').textContent;
const description = parent.querySelector('p').textContent;
localStorage.setItem('problemTitle', title);
localStorage.setItem('problemDescription', description);
window.location.href = window.location.origin + "/private/CoderPage/coder.html";
}
// Mobile menu toggle functionality
12 changes: 9 additions & 3 deletions client/private/Leaderboard/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<link rel="stylesheet" href="leaderboard.css">
<link rel="shortcut icon" href="../HomePage/assets/web-development.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">

<!-- Clerk auth library -->
<script async crossorigin="anonymous"
data-clerk-publishable-key="pk_test_aGFybWxlc3Mtd2VldmlsLTE1LmNsZXJrLmFjY291bnRzLmRldiQ"
src="https://harmless-weevil-15.clerk.accounts.dev/npm/@clerk/clerk-js@5/dist/clerk.browser.js"
type="text/javascript"></script>
</head>

<body class="dark-theme">
Expand All @@ -20,17 +26,17 @@
<nav class="codingPageNav" aria-label="Main navigation">
<button class="nav-close inside-logo-sidebar" onclick="hideNav()" aria-label="Close Navigation"></button>
<ul>
<li><a href="../HomePage/codigo.html" class="nav-link">Home</a></li>
<li><a href="#home" class="nav-link current" onclick="showSection('home')">Home</a></li>
<li><a href="#practice" class="nav-link" onclick="showSection('practice')">Practice</a></li>
<li><a href="#stats" class="nav-link" onclick="showSection('stats')">Stats</a></li>
<li><a href="../Arena/arena.html" class="nav-link">Arena</a></li>
<li><a href="#help" class="nav-link" onclick="showSection('help')">Ask AI</a></li>
<li><a href="#contact" class="nav-link" onclick="showSection('contact')">Contact Us</a></li>
<li class="nav-actions">
<select name="theme-toggle" id="theme-toggle">
<option value="dark-theme" selected>Dark theme</option>
<option value="light-theme">Light theme</option>
</select>
<a href="../../public/LandingPage/index.html" class="logout-btn">Logout</a>
<button onclick="authManager.logout()" class="logout-btn">Logout</button>
</li>
</ul>
</nav>
Expand Down
12 changes: 9 additions & 3 deletions client/private/Leaderboard/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
}

let currentFilter = 'all';

Check warning on line 45 in client/private/Leaderboard/leaderboard.js

View workflow job for this annotation

GitHub Actions / quality-check

'currentFilter' is assigned a value but never used

function setupFilterButtons() {
const filterButtons = document.querySelectorAll('.filter-btn');
Expand Down Expand Up @@ -115,8 +115,11 @@
return;
}

// The backend now properly sorts and assigns rankPosition, so we can trust the order
leaderboard.forEach((user, index) => {
const row = createLeaderboardRow(user, index + 1);
// Use the rankPosition from backend (which handles ties properly)
const position = user.rankPosition || (index + 1);
const row = createLeaderboardRow(user, position);
tableBody.appendChild(row);
});
}
Expand All @@ -131,11 +134,14 @@
// Format last solve date
const lastSolve = user.lastSolvedDate ? formatDate(user.lastSolvedDate) : 'Never';

// Use the rankPosition from the backend if available, otherwise use the frontend position
const displayPosition = user.rankPosition || position;

// Add special styling for top 3
const rankClass = position <= 3 ? `rank-${position} top-3` : '';
const rankClass = displayPosition <= 3 ? `rank-${displayPosition} top-3` : '';

row.innerHTML = `
<div class="rank-position ${rankClass}">${position}</div>
<div class="rank-position ${rankClass}">${displayPosition}</div>
<div class="user-info">
<div class="user-avatar">${initials}</div>
<div class="user-name">${user.name || 'Anonymous'}</div>
Expand Down
Loading
Loading