-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
799 lines (703 loc) · 28 KB
/
index.html
File metadata and controls
799 lines (703 loc) · 28 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8" />
<title>LearnHub – AI-Augmented Learning Partner</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="LearnHub is an AI-augmented learning hub with concise, AI-ready summaries for technical courses, YouTube videos, books, and mock interviews."
/>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
<style>
html {
scroll-behavior: smooth;
}
body {
padding-top: 72px;
}
section {
padding-top: 4rem;
padding-bottom: 4rem;
scroll-margin-top: 80px;
}
.hero-title {
font-size: clamp(2.25rem, 3vw, 3rem);
font-weight: 700;
}
.hero-subtitle {
font-size: 0.98rem;
max-width: 680px;
}
.navbar-brand span {
font-weight: 600;
}
.badge-pill {
border-radius: 999px;
font-weight: 500;
letter-spacing: 0.01em;
}
.resources-search {
max-width: 360px;
}
.resources-table-wrapper {
max-height: 520px;
overflow: auto;
}
.resources-table-wrapper table {
margin-bottom: 0;
}
.text-xs {
font-size: 0.75rem;
}
.shadow-soft {
box-shadow:
0 18px 45px rgba(15, 23, 42, 0.25),
0 4px 12px rgba(15, 23, 42, 0.12);
}
.navbar-blur {
backdrop-filter: blur(10px);
background-color: rgba(248, 249, 250, 0.85);
}
[data-bs-theme="dark"] .navbar-blur {
background-color: rgba(15, 23, 42, 0.9);
border-bottom-color: rgba(148, 163, 184, 0.3);
}
[data-bs-theme="dark"] .bg-light {
background-color: #020617 !important;
}
[data-bs-theme="dark"] .card-header {
background-color: rgba(15, 23, 42, 0.9);
}
[data-bs-theme="dark"] .table > :not(caption) > * > * {
background-color: inherit !important;
}
[data-bs-theme="dark"] .table-light {
--bs-table-bg: #101018;
color: var(--bs-body-color);
}
[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
--bs-table-accent-bg: rgba(255, 255, 255, 0.03);
color: inherit;
}
.hero-search-wrapper {
max-width: 640px;
margin: 0 auto 1.5rem auto;
}
.hero-search .form-control {
padding-top: 0.9rem;
padding-bottom: 0.9rem;
font-size: 1.05rem;
}
.hero-search .input-group-text {
padding-left: 1rem;
padding-right: 1rem;
font-size: 1.1rem;
}
@media (max-width: 576px) {
.hero-search-wrapper {
max-width: 100%;
}
}
</style>
</head>
<body>
<!-- Header / Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom fixed-top shadow-sm navbar-blur">
<div class="container">
<a class="navbar-brand d-flex align-items-center gap-2" href="#">
<span class="fs-5">LearnHub</span>
<span class="badge text-bg-primary badge-pill text-xs">AI-augmented</span>
</a>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarMain"
aria-controls="navbarMain"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarMain">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0 align-items-lg-center">
<li class="nav-item">
<a class="nav-link" href="#ai-study-plan">AI Study Plan</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#resources">Resources</a>
</li>
</ul>
<button
id="theme-toggle"
type="button"
class="btn btn-outline-secondary btn-sm ms-lg-3 mt-2 mt-lg-0"
>
🌙 Dark
</button>
</div>
</div>
</nav>
<main>
<!-- Intro -->
<section id="intro">
<div class="container">
<div class="row align-items-center gy-4">
<div class="col-lg-7">
<h1 class="hero-title mb-3">
LearnHub – Your AI-Augmented Learning Partner
</h1>
<p class="hero-subtitle text-muted mb-3">
LearnHub is a curated collection of high-signal summaries for courses, YouTube videos, books, and mock interviews. It is designed to help busy engineers, students, and career switchers learn faster, review smarter, and plug AI directly into their study workflow. If you don’t know which tutorial to read, let AI tell you (study plan).
</p>
<div class="hero-search-wrapper mb-4">
<form id="hero-search-form" class="hero-search-form">
<div class="input-group input-group-lg hero-search">
<span class="input-group-text">🔍</span>
<input
type="search"
id="hero-resource-search"
class="form-control"
placeholder="Search anything you want to learn…"
autocomplete="off"
/>
</div>
<p class="small text-muted mt-2 mb-0">
This search instantly filters the LearnHub library below.
</p>
</form>
</div>
<ul class="text-muted mb-4">
<li>Use concise summaries instead of rewatching hours of content.</li>
<li>Let your favourite AI assistant turn them into plans, drills, and mindmaps.</li>
<li>Work in your preferred natural language and programming language.</li>
</ul>
<div class="d-flex flex-wrap gap-2">
<a
href="#ai-study-plan"
class="btn btn-primary"
>
Start with AI Study Plan
</a>
</div>
</div>
<div class="col-lg-5">
<div class="border rounded-4 p-3 p-md-4 bg-light">
<h2 class="h5 mb-3">Who is this for?</h2>
<ul class="mb-3 small text-muted">
<li>Backend and full-stack developers preparing for interviews.</li>
<li>Engineers taking online courses and wanting better retention.</li>
<li>Self-taught learners who prefer structured, AI-friendly notes.</li>
</ul>
<div class="d-flex flex-wrap gap-2">
<span class="summary-count-badge badge text-bg-secondary badge-pill">+. . . summaries</span>
<span class="badge text-bg-secondary badge-pill">AI-ready prompts</span>
<span class="badge text-bg-secondary badge-pill">Multi-language</span>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Resources -->
<section id="resources" class="bg-light">
<div class="container">
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3 mb-4">
<div>
<h2 class="mb-2">Resources <small>(<span class="summary-count-badge">...</span>)</small></h2>
<p class="text-muted mb-0">
Browse LearnHub summaries by type and title. Use the search box
to instantly filter by title (server-side).
</p>
</div>
<div class="resources-search">
<label for="resource-search" class="form-label mb-1 small text-muted">
Instant search (title only)
</label>
<input
type="text"
id="resource-search"
class="form-control form-control-sm"
placeholder="Search by title..."
autocomplete="off"
/>
</div>
</div>
<div class="resources-table-wrapper table-responsive">
<table class="table table-sm table-striped table-hover align-middle" id="resources-table">
<thead class="table-dark">
<tr>
<th scope="col" style="width: 60px;">#</th>
<th scope="col" style="width: 120px;">Type</th>
<th scope="col">Title</th>
<th scope="col" style="width: 160px;">Langs</th>
</tr>
</thead>
<tbody>
<!-- Filled by JavaScript -->
</tbody>
</table>
</div>
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mt-3 gap-2">
<div class="d-flex align-items-center gap-2">
<label for="per-page" class="small text-muted mb-0">Rows per page</label>
<select id="per-page" class="form-select form-select-sm" style="width: auto;">
<option value="10" selected>10</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
</div>
<div class="d-flex align-items-center gap-2">
<button
id="page-prev"
type="button"
class="btn btn-outline-secondary btn-sm"
>
◀ Prev
</button>
<span id="pagination-info" class="small text-muted">Loading...</span>
<button
id="page-next"
type="button"
class="btn btn-outline-secondary btn-sm"
>
Next ▶
</button>
</div>
</div>
<hr class="my-4">
<div class="row gy-4">
<div class="col-lg-6">
<h3 class="h6 mb-2">How the resources work</h3>
<p class="small text-muted mb-2">
Each resource is a concise, AI-ready summary of a longer piece of content:
a YouTube video, a playlist, a course, a book, or a mock interview.
</p>
<ul class="small text-muted mb-2">
<li>Click a title to open the summary on GitHub.</li>
<li>Inside each summary, you will find AI prompts tailored to that resource.</li>
<li>You can ask your AI assistant to quiz you, create flashcards, generate code drills, and more.</li>
</ul>
<p class="small text-muted mb-0">
You can return to the same resource as many times as you like. LearnHub is designed for repeated review and deeper passes.
</p>
</div>
<div class="col-lg-6">
<h3 class="h6 mb-2">Tips for using LearnHub efficiently</h3>
<ul class="small text-muted mb-2">
<li>Start with a small set of core topics (e.g. networking, databases, system design).</li>
<li>Alternate between new content and review sessions using the same summaries.</li>
<li>Use the AI Study Plan prompt when you feel lost or overwhelmed.</li>
<li>Use the AI Search prompt when you want to discover related resources quickly.</li>
</ul>
<p class="small text-muted mb-0">
Over time, you can build your own mental map of the LearnHub library and reuse it for different goals
(interviews, promotions, switching stacks, etc.).
</p>
</div>
</div>
</div>
</section>
<!-- AI Study Plan -->
<section id="ai-study-plan">
<div class="container">
<div class="row gy-4 align-items-start">
<div class="col-lg-7">
<div class="card shadow-sm border-0 h-100">
<div class="card-header border-0 pb-1">
<div class="d-flex flex-wrap align-items-center justify-content-between gap-2">
<div>
<h2 class="h5 mb-1">AI Study Plan</h2>
<p class="text-muted small mb-0">
Use your favourite AI assistant to build a personalised study plan from LearnHub resources.
</p>
</div>
<span class="badge text-bg-primary badge-pill text-xs">
Step 1: Starter prompt
</span>
</div>
</div>
<div class="card-body">
<p class="small text-muted">
Use this starter prompt in any capable AI assistant to build a personalised study plan from LearnHub resources. Replace placeholders with your details.
</p>
<a href="https://alisol.ir/?ai=learnhub_starter" class="btn btn-primary">Start AI Study Plan (English)</a>
</div>
</div>
</div>
<div class="col-lg-5">
<div class="card shadow-sm border-0">
<div class="card-header border-0 pb-1">
<h3 class="h6 mb-1">Language shortcuts for AI Study Plan</h3>
<p class="small text-muted mb-0">
Click to start in your language.
</p>
</div>
<div class="card-body small text-muted">
<div class="d-flex flex-wrap gap-2 small">
<a href="https://alisol.ir/?ai=learnhub_starter|NL" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">NL</a>
<a href="https://alisol.ir/?ai=learnhub_starter|DE" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">DE</a>
<a href="https://alisol.ir/?ai=learnhub_starter|FR" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">FR</a>
<a href="https://alisol.ir/?ai=learnhub_starter|ES" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">ES</a>
<a href="https://alisol.ir/?ai=learnhub_starter|IT" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">IT</a>
<a href="https://alisol.ir/?ai=learnhub_starter|SV" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">SV</a>
<a href="https://alisol.ir/?ai=learnhub_starter|DA" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">DA</a>
<a href="https://alisol.ir/?ai=learnhub_starter|NO" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">NO</a>
<a href="https://alisol.ir/?ai=learnhub_starter|PL" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">PL</a>
<a href="https://alisol.ir/?ai=learnhub_starter|PT" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">PT</a>
<a href="https://alisol.ir/?ai=learnhub_starter|RO" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">RO</a>
<a href="https://alisol.ir/?ai=learnhub_starter|RU" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">RU</a>
<a href="https://alisol.ir/?ai=learnhub_starter|HI" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">HI</a>
<a href="https://alisol.ir/?ai=learnhub_starter|AR" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">AR</a>
<a href="https://alisol.ir/?ai=learnhub_starter|FA" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">FA</a>
<a href="https://alisol.ir/?ai=learnhub_starter|TR" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none">TR</a>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<footer class="border-top py-3">
<div class="container d-flex flex-column flex-md-row justify-content-between align-items-center gap-2">
<div class="small text-muted">
Built by <a href="https://alisol.ir" target="_blank" rel="noopener">Ali Sol</a>. Summaries hosted on <a href="https://github.com/alisolphp/LearnHub/" target="_blank" rel="noopener">GitHub</a>.
</div>
<div class="small text-muted">
<a href="#intro" class="text-decoration-none">Back to top ↑</a>
</div>
</div>
</footer>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"
></script>
<script>
(function () {
var toggleButton = document.getElementById("theme-toggle");
var storedTheme = localStorage.getItem("learnhub-theme");
function setTheme(theme) {
document.documentElement.setAttribute("data-bs-theme", theme);
localStorage.setItem("learnhub-theme", theme);
if (toggleButton) {
toggleButton.textContent = theme === "dark" ? "🌙 Dark" : "☀️ Light";
}
}
if (!storedTheme) {
var prefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
setTheme(prefersDark ? "dark" : "light");
} else {
setTheme(storedTheme);
}
if (!toggleButton) return;
toggleButton.addEventListener("click", function () {
var current = document.documentElement.getAttribute("data-bs-theme") || "dark";
var next = current === "dark" ? "light" : "dark";
setTheme(next);
});
})();
(function () {
var copyStarterBtn = document.getElementById("copy-starter");
var copyStarterStatus = document.getElementById("copy-starter-status");
var starterTextarea = document.getElementById("starter-prompt");
if (!copyStarterBtn || !copyStarterStatus || !starterTextarea) return;
copyStarterBtn.addEventListener("click", function () {
var text = starterTextarea.value || "";
if (!navigator.clipboard) {
starterTextarea.select();
var ok = false;
try {
ok = document.execCommand("copy");
} catch (e) {
ok = false;
}
copyStarterStatus.textContent = ok ? "Copied." : "Copy failed.";
return;
}
navigator.clipboard
.writeText(text)
.then(function () {
copyStarterStatus.textContent = "Copied.";
})
.catch(function () {
copyStarterStatus.textContent = "Copy failed.";
});
setTimeout(function () {
copyStarterStatus.textContent = "";
}, 2000);
});
})();
(function () {
var copySearchBtn = document.getElementById("copy-search");
var copySearchStatus = document.getElementById("copy-search-status");
var searchTextarea = document.getElementById("search-prompt");
if (!copySearchBtn || !copySearchStatus || !searchTextarea) return;
copySearchBtn.addEventListener("click", function () {
var text = searchTextarea.value || "";
if (!navigator.clipboard) {
searchTextarea.select();
var ok = false;
try {
ok = document.execCommand("copy");
} catch (e) {
ok = false;
}
copySearchStatus.textContent = ok ? "Copied." : "Copy failed.";
return;
}
navigator.clipboard
.writeText(text)
.then(function () {
copySearchStatus.textContent = "Copied.";
})
.catch(function () {
copySearchStatus.textContent = "Copy failed.";
});
setTimeout(function () {
copySearchStatus.textContent = "";
}, 2000);
});
})();
// Summary count badge
(function () {
var badges = document.querySelectorAll(".summary-count-badge");
if (!badges.length) return;
fetch("https://alisol.ir/Projects/LearnHub/api/v1/summaries/count/")
.then(function (res) {
if (!res.ok) {
throw new Error("Request failed");
}
return res.json();
})
.then(function (json) {
var approx =
json &&
json.data &&
json.data.total &&
typeof json.data.total.approximate === "number"
? json.data.total.approximate
: null;
if (approx !== null) {
badges.forEach(function (badge) {
badge.textContent = "+" + approx + " summaries";
});
}
})
.catch(function () {
badges.forEach(function (badge) {
badge.textContent = "LearnHub summaries";
});
});
})();
</script>
<script>
// Resources table with server-side pagination + search
(function () {
var tableBody = document.querySelector("#resources-table tbody");
var searchInput = document.getElementById("resource-search");
var perPageSelect = document.getElementById("per-page");
var pagePrevBtn = document.getElementById("page-prev");
var pageNextBtn = document.getElementById("page-next");
var paginationInfo = document.getElementById("pagination-info");
if (!tableBody || !searchInput || !perPageSelect || !pagePrevBtn || !pageNextBtn || !paginationInfo) {
return;
}
var currentPage = 1;
var perPage = parseInt(perPageSelect.value, 10) || 10;
var totalItems = 0;
var currentSearch = "";
var isLoading = false;
var hasLoadedOnce = false;
var needsReload = false;
var searchDebounceTimer = null;
var heroSearchInput = document.getElementById("hero-resource-search");
var heroSearchForm = document.getElementById("hero-search-form");
var resourcesSection = document.getElementById("resources");
function transformResourceUrl(url) {
return "https://github.com/alisolphp/LearnHub/blob/main/" + url;
}
function renderRows(items) {
if (!items || !items.length) {
tableBody.innerHTML =
'<tr><td colspan="4" class="text-center py-4 text-muted">No resources found.</td></tr>';
return;
}
var rows = items
.map(function (item, index) {
var absoluteIndex = (currentPage - 1) * perPage + index + 1;
var langs = item.langs || {};
var langKeys = Object.keys(langs).sort();
var firstLangUrl = null;
if (langKeys.length > 0) {
var enKey = langKeys.indexOf("EN") !== -1 ? "EN" : langKeys[0];
firstLangUrl = transformResourceUrl(langs[enKey]);
}
var titleLink = firstLangUrl || "#";
var langLinks = langKeys
.map(function (code) {
var url = transformResourceUrl(langs[code]);
return (
'<a href="' +
url +
'" target="_blank" rel="noopener" class="badge text-bg-secondary text-decoration-none me-1 mb-1">' +
code +
"</a>"
);
})
.join("");
return (
"<tr>" +
'<td class="text-muted small">' +
absoluteIndex +
"</td>" +
"<td>" +
(item.type || "") +
"</td>" +
'<td><a href="' +
titleLink +
'" target="_blank" rel="noopener">' +
(item.title || "") +
"</a></td>" +
"<td>" +
langLinks +
"</td>" +
"</tr>"
);
})
.join("");
tableBody.innerHTML = rows;
}
function updatePaginationInfo() {
if (!paginationInfo) return;
if (!totalItems) {
paginationInfo.textContent = "0 items";
pagePrevBtn.disabled = true;
pageNextBtn.disabled = true;
return;
}
var startItem = (currentPage - 1) * perPage + 1;
var endItem = Math.min(currentPage * perPage, totalItems);
var totalPages = Math.ceil(totalItems / perPage);
paginationInfo.textContent =
"Showing " + startItem + "–" + endItem + " of " + totalItems + " (page " + currentPage + " of " + totalPages + ")";
pagePrevBtn.disabled = currentPage <= 1;
pageNextBtn.disabled = currentPage >= totalPages;
}
function loadResources() {
if (isLoading) {
needsReload = true;
return;
}
isLoading = true;
needsReload = false;
if (!hasLoadedOnce) {
tableBody.innerHTML =
'<tr><td colspan="4" class="text-center py-4 text-muted">Loading resources...</td></tr>';
}
var params = new URLSearchParams();
params.set("page", String(currentPage));
params.set("per_page", String(perPage));
if (currentSearch) {
params.set("search", currentSearch);
}
fetch("https://alisol.ir/Projects/LearnHub/api/v1/summaries/list/?" + params.toString())
.then(function (res) {
if (!res.ok) {
throw new Error("Request failed");
}
return res.json();
})
.then(function (json) {
var data = json && json.data ? json.data : {};
var items = Array.isArray(data.items) ? data.items : [];
totalItems = typeof data.total === "number" ? data.total : items.length;
renderRows(items);
updatePaginationInfo();
})
.catch(function () {
tableBody.innerHTML =
'<tr><td colspan="4" class="text-center py-4 text-danger">Failed to load resources.</td></tr>';
paginationInfo.textContent = "";
})
.finally(function () {
isLoading = false;
hasLoadedOnce = true;
if (needsReload) {
loadResources();
}
});
}
function applySearch(value) {
var normalized = String(value || "").trim();
currentSearch = normalized;
currentPage = 1;
if (searchInput && searchInput.value !== normalized) {
searchInput.value = normalized;
}
if (heroSearchInput && heroSearchInput.value !== normalized) {
heroSearchInput.value = normalized;
}
if (searchDebounceTimer) {
clearTimeout(searchDebounceTimer);
}
searchDebounceTimer = setTimeout(function () {
loadResources();
}, 500);
}
searchInput.addEventListener("input", function (event) {
applySearch(event.target.value);
});
searchInput.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
if (searchDebounceTimer) {
clearTimeout(searchDebounceTimer);
}
applySearch(searchInput.value);
}
});
if (heroSearchInput) {
heroSearchInput.addEventListener("input", function (event) {
applySearch(event.target.value);
});
}
if (heroSearchForm && heroSearchInput) {
heroSearchForm.addEventListener("submit", function (event) {
event.preventDefault();
applySearch(heroSearchInput.value);
if (resourcesSection) {
resourcesSection.scrollIntoView({ behavior: "smooth" });
}
});
}
perPageSelect.addEventListener("change", function (event) {
var value = parseInt(event.target.value, 10);
if (!value || value <= 0) return;
perPage = value;
currentPage = 1;
loadResources();
});
pagePrevBtn.addEventListener("click", function () {
if (currentPage <= 1) return;
currentPage -= 1;
loadResources();
});
pageNextBtn.addEventListener("click", function () {
var totalPages = totalItems > 0 ? Math.ceil(totalItems / perPage) : 1;
if (currentPage >= totalPages) return;
currentPage += 1;
loadResources();
});
loadResources();
})();
</script>
</body>
</html>