Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
134 lines (124 loc) · 6.38 KB
/
Copy pathindex.html
File metadata and controls
134 lines (124 loc) · 6.38 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
<!-- Deployment Update Trigger -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodePilot - Learn Coding by Practice</title>
<meta name="description" content="Master coding securely and interactively with CodePilot. Practice problems, track your streak, and earn respect.">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<nav>
<a href="index.html" class="logo">CodePilot</a>
<div class="nav-links">
<a href="problems_v2.html">Practice Problems</a>
<a href="auth_v2.html" class="btn-primary" id="authBtn">Login</a>
</div>
</nav>
<header class="hero">
<h1>Learn Coding by <span style="color: var(--primary);">Practice</span></h1>
<p>Join thousands of developers mastering algorithms, data structures, and top-tier technologies. Start learning free and step up your career.</p>
<div class="mt-2">
<a href="auth_v2.html" class="btn-primary" style="font-size: 1.2rem; padding: 1rem 2rem;">Start Learning Free</a>
</div>
</header>
<section class="section" id="courses">
<h2 class="section-title">Explore Featured Paths</h2>
<div class="grid-3" id="dynamicCourses">
<p class="text-secondary text-center" style="grid-column: span 3;">Loading courses...</p>
</div>
</section>
<section class="section">
<h2 class="section-title">Why CodePilot?</h2>
<div class="grid-3 text-center">
<div>
<h3 style="color: var(--accent); font-size: 2rem; margin-bottom: 1rem;">Gamified</h3>
<p class="text-secondary">Keep your learning streak alive and compete on the global leaderboard.</p>
</div>
<div>
<h3 style="color: var(--primary); font-size: 2rem; margin-bottom: 1rem;">Real Problems</h3>
<p class="text-secondary">Problems curated from top tech interviews and real-world scenarios.</p>
</div>
<div>
<h3 style="color: var(--success); font-size: 2rem; margin-bottom: 1rem;">Instant Feedback</h3>
<p class="text-secondary">Run your code and check it against robust hidden test cases.</p>
</div>
</div>
</section>
<script src="js/app.js?v=3"></script>
<script src="js/coursesData.js?v=3"></script>
<script>
async function fetchCourses() {
const container = document.getElementById('dynamicCourses');
if (!container) return;
const iconMap = {
'C++': '⚡',
'Java': '☕',
'Python': '🐍',
'Web Dev': '🌐',
'Database': '🗄️'
};
function renderCourses(courses) {
if (!Array.isArray(courses) || courses.length === 0) {
container.innerHTML = `<p class="text-secondary text-center" style="grid-column: span 3;">No courses found.</p>`;
return;
}
container.innerHTML = courses.map(c => {
const icon = iconMap[c.category] || '📘';
const modulesCount = (c.notes && c.notes.length) || 0;
return `
<a href="course_v2.html?id=${c._id}" style="text-decoration: none; color: inherit; display: block;">
<div class="card" style="height: 100%; display: flex; flex-direction: column; justify-content: space-between; transition: transform 0.2s, box-shadow 0.2s;">
<div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem;">
<span style="font-size: 1.5rem;">${icon}</span>
<span class="badge easy" style="font-size: 0.75rem; padding: 0.2rem 0.6rem;">${modulesCount} Modules</span>
</div>
<h3 style="color: var(--primary); margin-bottom: 0.5rem;">${c.title}</h3>
<p class="text-secondary" style="font-size: 0.95rem; line-height: 1.5;">${c.description}</p>
</div>
<div style="margin-top: 1.5rem; display: flex; align-items: center; color: var(--accent); font-weight: 600; font-size: 0.9rem;">
<span>Explore Notes & Practice</span>
<span style="margin-left: 0.4rem;">→</span>
</div>
</div>
</a>
`;
}).join('');
}
// Step 1: Instant render from COURSES_DATA or cache (0ms delay)
if (typeof COURSES_DATA !== 'undefined' && Array.isArray(COURSES_DATA) && COURSES_DATA.length > 0) {
renderCourses(COURSES_DATA);
} else {
try {
const cachedData = localStorage.getItem('codepilot_courses_cache');
if (cachedData) {
const parsed = JSON.parse(cachedData);
if (Array.isArray(parsed) && parsed.length > 0) renderCourses(parsed);
}
} catch (e) {
console.error("Cache read error:", e);
}
}
// Step 2: Background revalidation with 2.5s timeout (never blocks UI)
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 2500);
const res = await fetch(`${API_URL}/courses`, { signal: controller.signal });
clearTimeout(timeoutId);
if (res.ok) {
const courses = await res.json();
if (Array.isArray(courses) && courses.length > 0) {
renderCourses(courses);
localStorage.setItem('codepilot_courses_cache', JSON.stringify(courses));
}
}
} catch (e) {
console.log("Background courses sync bypassed. Local courses active.");
}
}
fetchCourses();
</script>
</body>
</html>