-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
960 lines (851 loc) · 53.1 KB
/
Copy pathmain.html
File metadata and controls
960 lines (851 loc) · 53.1 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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Site Hub Admin | Command Center</title>
<link rel="icon" type="image/png" href="assets/flaticon.png">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap"
rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: { sans: ['Outfit', 'sans-serif'] },
colors: {
dark: { 800: '#1e1e2e', 900: '#11111b', 700: '#313244' },
accent: { 500: '#cba6f7', 600: '#b4befe' }
}
}
}
}
</script>
<style>
body {
background-color: #11111b;
background-image: radial-gradient(circle at 50% 0%, #313244 0%, #11111b 70%);
color: #cdd6f4;
overflow-x: hidden;
}
/* Glass Effect */
.glass-panel {
background: rgba(30, 30, 46, 0.7);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-link {
transition: all 0.2s ease;
border-left: 3px solid transparent;
}
.sidebar-link.active {
background: rgba(203, 166, 247, 0.1);
border-left-color: #cba6f7;
color: #cba6f7;
}
.glass-input {
background: rgba(17, 17, 27, 0.6);
border: 1px solid rgba(255, 255, 255, 0.1);
color: white;
transition: all 0.3s;
}
.glass-input:focus {
outline: none;
border-color: #cba6f7;
box-shadow: 0 0 0 2px rgba(203, 166, 247, 0.2);
}
/* Table Styles */
.custom-table th { background: rgba(0, 0, 0, 0.3); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.custom-table tr:hover { background: rgba(255, 255, 255, 0.03); }
.custom-table td { border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #45475a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #585b70; }
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
</style>
</head>
<body class="flex h-screen overflow-hidden text-sm md:text-base">
<div id="toast-container" class="fixed bottom-6 right-6 z-[100] flex flex-col gap-3"></div>
<div id="loginSection" class="fixed inset-0 z-50 flex items-center justify-center bg-[#11111b] bg-opacity-95">
<div class="glass-panel p-8 rounded-2xl w-full max-w-md shadow-2xl relative overflow-hidden">
<div class="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500"></div>
<h1 class="text-3xl font-bold text-white mb-2 text-center"><i class="fas fa-fingerprint text-purple-400"></i> Admin Access</h1>
<p class="text-gray-400 text-center mb-8">Authenticate to access Site Hub core.</p>
<form id="loginForm" class="space-y-4">
<div>
<label class="block text-xs font-semibold text-gray-400 mb-1 uppercase">Email Address</label>
<input type="email" id="loginEmail" required class="w-full glass-input rounded-lg p-3">
</div>
<div>
<label class="block text-xs font-semibold text-gray-400 mb-1 uppercase">Password</label>
<input type="password" id="loginPassword" required class="w-full glass-input rounded-lg p-3">
</div>
<button type="submit" class="w-full bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 rounded-lg transition shadow-lg shadow-purple-900/20">
Initialize Session
</button>
</form>
</div>
</div>
<div id="adminLayout" class="hidden w-full h-full flex">
<aside class="w-64 bg-[#181825] flex-shrink-0 flex flex-col border-r border-white/5 hidden md:flex">
<div class="p-6">
<h1 class="text-2xl font-bold text-white tracking-tight">Site<span class="text-purple-400">Hub</span></h1>
<p class="text-xs text-gray-500 mt-1">Admin Dashboard v2.0</p>
</div>
<nav class="flex-1 px-4 space-y-2">
<button onclick="switchTab('dashboard')" id="nav-dashboard" class="sidebar-link active w-full flex items-center gap-3 px-4 py-3 rounded-lg text-gray-300 hover:bg-white/5 hover:text-white">
<i class="fas fa-chart-pie w-5 text-center"></i> Dashboard
</button>
<button onclick="switchTab('resources')" id="nav-resources" class="sidebar-link w-full flex items-center gap-3 px-4 py-3 rounded-lg text-gray-300 hover:bg-white/5 hover:text-white">
<i class="fas fa-database w-5 text-center"></i> Resources
</button>
<button onclick="switchTab('inbox')" id="nav-inbox" class="sidebar-link w-full flex items-center gap-3 px-4 py-3 rounded-lg text-gray-300 hover:bg-white/5 hover:text-white">
<i class="fas fa-inbox w-5 text-center"></i> Inbox
<span id="badgeInbox" class="ml-auto bg-red-500/20 text-red-300 text-xs px-2 py-0.5 rounded-full hidden">0</span>
</button>
<button onclick="switchTab('settings')" id="nav-settings" class="sidebar-link w-full flex items-center gap-3 px-4 py-3 rounded-lg text-gray-300 hover:bg-white/5 hover:text-white">
<i class="fas fa-sliders-h w-5 text-center"></i> Settings
</button>
</nav>
<div class="p-4 border-t border-white/5">
<div class="flex items-center gap-3 mb-4 px-2">
<div class="w-8 h-8 rounded-full bg-purple-600/30 flex items-center justify-center text-purple-300">
<i class="fas fa-user-shield"></i>
</div>
<div class="overflow-hidden">
<p class="text-sm font-medium text-white truncate" id="adminEmailDisplay">Admin</p>
<p class="text-xs text-green-400">Online</p>
</div>
</div>
<button id="logoutButton" class="w-full bg-red-500/10 hover:bg-red-500/20 text-red-400 py-2 rounded-lg text-sm transition border border-red-500/20">
<i class="fas fa-sign-out-alt mr-2"></i> Terminate
</button>
</div>
</aside>
<main class="flex-1 flex flex-col h-full relative">
<header class="md:hidden h-16 bg-[#181825] border-b border-white/5 flex items-center justify-between px-4">
<span class="font-bold text-lg">SiteHub Admin</span>
<button onclick="document.querySelector('aside').classList.toggle('hidden'); document.querySelector('aside').classList.toggle('absolute'); document.querySelector('aside').classList.toggle('z-50'); document.querySelector('aside').classList.toggle('h-full');" class="text-gray-300"><i class="fas fa-bars text-xl"></i></button>
</header>
<div class="flex-1 overflow-y-auto p-4 md:p-8 relative">
<div id="tab-dashboard" class="tab-content active space-y-6">
<h2 class="text-2xl font-bold text-white">Overview</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="glass-panel p-5 rounded-xl border-l-4 border-blue-500">
<p class="text-gray-400 text-xs uppercase font-bold tracking-wider mb-1">Total Resources</p>
<div class="flex justify-between items-end">
<h3 class="text-3xl font-bold text-white" id="statTotalResources">0</h3>
<i class="fas fa-link text-blue-500/20 text-4xl"></i>
</div>
</div>
<div class="glass-panel p-5 rounded-xl border-l-4 border-green-500">
<p class="text-gray-400 text-xs uppercase font-bold tracking-wider mb-1">Total Engagements</p>
<div class="flex justify-between items-end">
<h3 class="text-3xl font-bold text-white" id="statTotalVotes">0</h3>
<i class="fas fa-heart text-green-500/20 text-4xl"></i>
</div>
</div>
<div class="glass-panel p-5 rounded-xl border-l-4 border-amber-500">
<p class="text-gray-400 text-xs uppercase font-bold tracking-wider mb-1">Pending Suggestions</p>
<div class="flex justify-between items-end">
<h3 class="text-3xl font-bold text-white" id="statPendingSuggestions">0</h3>
<i class="fas fa-lightbulb text-amber-500/20 text-4xl"></i>
</div>
</div>
<div class="glass-panel p-5 rounded-xl border-l-4 border-red-500">
<p class="text-gray-400 text-xs uppercase font-bold tracking-wider mb-1">Active Reports</p>
<div class="flex justify-between items-end">
<h3 class="text-3xl font-bold text-white" id="statActiveReports">0</h3>
<i class="fas fa-flag text-red-500/20 text-4xl"></i>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="glass-panel rounded-xl p-6">
<h3 class="font-semibold text-white mb-4 flex items-center gap-2"><i class="fas fa-chart-pie text-purple-400"></i> Category Distribution</h3>
<div class="h-64 relative"><canvas id="categoryChart"></canvas></div>
</div>
<div class="glass-panel rounded-xl p-6">
<h3 class="font-semibold text-white mb-4 flex items-center gap-2"><i class="fas fa-chart-bar text-blue-400"></i> Vote Metrics</h3>
<div class="h-64 relative"><canvas id="votesChart"></canvas></div>
</div>
</div>
</div>
<div id="tab-resources" class="tab-content space-y-6">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<h2 class="text-2xl font-bold text-white">Resource Database</h2>
<button onclick="document.getElementById('addResourceModal').classList.remove('hidden')"
class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-lg font-medium transition shadow-lg shadow-purple-900/20 flex items-center gap-2">
<i class="fas fa-plus"></i> Add New
</button>
</div>
<div class="glass-panel rounded-xl overflow-hidden flex flex-col h-[calc(100vh-200px)]">
<div class="p-4 border-b border-white/5 flex flex-col md:flex-row gap-3">
<div class="relative flex-1">
<i class="fas fa-search absolute left-3 top-3 text-gray-500"></i>
<input type="text" id="searchResources" placeholder="Search by name, URL, or tags..." class="w-full glass-input rounded-lg py-2 pl-10 pr-4 text-sm">
</div>
<select id="filterResources" class="glass-input rounded-lg px-4 py-2 text-sm w-full md:w-48">
<option value="all">All Categories</option>
<option value="entertainment">Entertainment</option>
<option value="academics">Academics</option>
<option value="productivity">Productivity</option>
<option value="design">Design</option>
<option value="utilities">Utilities</option>
</select>
</div>
<div class="overflow-auto flex-1">
<table class="w-full text-left custom-table">
<thead class="sticky top-0 z-10 text-gray-400 bg-[#1e1e2e]">
<tr>
<th class="p-4">Name / URL</th>
<th class="p-4">Category</th>
<th class="p-4">Engagement</th>
<th class="p-4 text-right">Actions</th>
</tr>
</thead>
<tbody id="resourcesTableBody" class="text-gray-300 text-sm">
</tbody>
</table>
</div>
</div>
</div>
<div id="tab-inbox" class="tab-content space-y-6">
<h2 class="text-2xl font-bold text-white">Inbox & Alerts</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="glass-panel rounded-xl p-6 min-h-[500px]">
<h3 class="text-lg font-bold text-red-400 mb-4 flex items-center gap-2">
<i class="fas fa-exclamation-triangle"></i> Reports
<span id="countReports" class="bg-red-500/10 text-red-400 text-xs px-2 py-0.5 rounded-full ml-auto">0</span>
</h3>
<div id="reportsList" class="space-y-3">
<div class="text-center text-gray-500 py-10">No active reports.</div>
</div>
</div>
<div class="glass-panel rounded-xl p-6 min-h-[500px]">
<h3 class="text-lg font-bold text-amber-400 mb-4 flex items-center gap-2">
<i class="fas fa-lightbulb"></i> Suggestions
<span id="countSuggestions" class="bg-amber-500/10 text-amber-400 text-xs px-2 py-0.5 rounded-full ml-auto">0</span>
</h3>
<div id="suggestionsList" class="space-y-3">
<div class="text-center text-gray-500 py-10">No pending suggestions.</div>
</div>
</div>
</div>
</div>
<div id="tab-settings" class="tab-content space-y-6 max-w-3xl">
<h2 class="text-2xl font-bold text-white">System Configuration</h2>
<div class="glass-panel rounded-xl p-6">
<h3 class="text-lg font-semibold text-white mb-4"><i class="fas fa-bullhorn text-blue-400 mr-2"></i> Global Announcement</h3>
<form id="announcementForm" class="space-y-4">
<div>
<label class="block text-sm text-gray-400 mb-1">Banner Message</label>
<input type="text" id="announcementText" placeholder="System maintenance in 1 hour..." class="w-full glass-input rounded-lg p-2.5">
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm text-gray-400 mb-1">Alert Type</label>
<select id="announcementType" class="w-full glass-input rounded-lg p-2.5">
<option value="info">Info (Blue)</option>
<option value="success">Success (Green)</option>
<option value="warning">Warning (Yellow)</option>
<option value="error">Critical (Red)</option>
</select>
</div>
<div class="flex items-end">
<label class="flex items-center space-x-3 cursor-pointer p-2.5 bg-white/5 rounded-lg w-full hover:bg-white/10 transition">
<input type="checkbox" id="announcementActive" class="w-5 h-5 text-purple-600 rounded focus:ring-purple-500 bg-gray-700 border-gray-600">
<span class="text-gray-200">Enable Banner</span>
</label>
</div>
</div>
<div class="pt-2">
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-2 rounded-lg text-sm font-semibold transition">Save Config</button>
</div>
</form>
</div>
<div class="glass-panel rounded-xl p-6 border-l-4 border-green-500">
<h3 class="text-lg font-semibold text-white mb-2">Data Backup</h3>
<p class="text-gray-400 text-sm mb-4">Export all resources to a JSON file for safety.</p>
<button id="exportBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg text-sm font-semibold transition">
<i class="fas fa-download mr-2"></i> Download Database
</button>
</div>
</div>
</div>
</main>
</div>
<div id="addResourceModal" class="hidden fixed inset-0 z-[60] flex items-center justify-center bg-black/80 backdrop-blur-sm p-4">
<div class="glass-panel w-full max-w-2xl rounded-2xl shadow-2xl overflow-y-auto max-h-[90vh] animate-in fade-in zoom-in duration-200">
<div class="p-6 border-b border-white/10 flex justify-between items-center">
<h2 class="text-xl font-bold text-white" id="modalTitle">Add Resource</h2>
<button onclick="closeModal()" class="text-gray-400 hover:text-white"><i class="fas fa-times text-lg"></i></button>
</div>
<form id="resourceForm" class="p-6 space-y-4">
<input type="hidden" id="resourceId"> <input type="hidden" id="suggestionRefId">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="col-span-1 md:col-span-2">
<label class="block text-xs font-semibold text-gray-400 mb-1">URL</label>
<div class="flex gap-2">
<input type="url" id="formUrl" required class="w-full glass-input rounded-lg p-2.5" placeholder="https://...">
<button type="button" id="fetchMetaBtn" class="bg-white/10 hover:bg-white/20 text-white px-3 rounded-lg" title="Auto-fill info">
<i class="fas fa-magic"></i>
</button>
</div>
</div>
<div class="col-span-1 md:col-span-2">
<label class="block text-xs font-semibold text-gray-400 mb-1">Name</label>
<input type="text" id="formName" required class="w-full glass-input rounded-lg p-2.5">
</div>
<div class="col-span-1 md:col-span-2">
<label class="block text-xs font-semibold text-gray-400 mb-1">Description</label>
<textarea id="formDescription" rows="3" class="w-full glass-input rounded-lg p-2.5"></textarea>
</div>
<div class="col-span-1 md:col-span-2">
<label class="block text-xs font-semibold text-gray-400 mb-2">Categories (Select Multiple)</label>
<div class="grid grid-cols-2 md:grid-cols-4 gap-2">
<script>
const cats = ['entertainment', 'academics', 'productivity', 'design', 'utilities', 'student-projects'];
cats.forEach(c => {
document.write(`
<label class="flex items-center space-x-2 cursor-pointer p-2 bg-white/5 rounded hover:bg-white/10 transition">
<input type="checkbox" value="${c}" onchange="updateSubcatCheckboxes()" class="cat-check w-4 h-4 rounded bg-gray-700 border-gray-600 text-purple-600 focus:ring-purple-500">
<span class="text-xs text-gray-200 capitalize">${c.replace('-', ' ')}</span>
</label>
`);
});
</script>
</div>
</div>
<div class="col-span-1 md:col-span-2" id="dynamicSubcatsSection" style="display: none;">
<label class="block text-xs font-semibold text-gray-400 mb-2">Subcategories</label>
<div class="flex flex-col gap-2 p-3 bg-white/5 rounded-lg border border-white/10" id="dynamicSubcatsContainer">
<!-- Populated dynamically -->
</div>
</div>
<div class="flex flex-col gap-2">
<label class="block text-xs font-semibold text-gray-400 mb-1">Status</label>
<div class="flex gap-4">
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="formVerified" class="w-4 h-4 rounded bg-gray-700 text-blue-500">
<span class="text-sm text-blue-300"><i class="fas fa-check-circle"></i> Verified</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" id="formHidden" class="w-4 h-4 rounded bg-gray-700 text-amber-500">
<span class="text-sm text-amber-300"><i class="fas fa-eye-slash"></i> Hidden</span>
</label>
</div>
<div id="voteEditContainer" class="mt-2">
<label class="text-xs text-gray-500 mb-1 block">Vote Count Adjustment</label>
<input type="number" id="formVotes" placeholder="0" class="w-20 glass-input rounded p-2 text-sm">
</div>
</div>
</div>
<div class="pt-4 flex justify-end gap-3">
<button type="button" onclick="closeModal()" class="px-4 py-2 rounded-lg bg-gray-700 hover:bg-gray-600 text-white text-sm">Cancel</button>
<button type="submit" class="px-6 py-2 rounded-lg bg-purple-600 hover:bg-purple-700 text-white font-semibold text-sm shadow-lg">Save Resource</button>
</div>
</form>
</div>
</div>
<div id="confirmModal" class="hidden fixed inset-0 z-[70] flex items-center justify-center bg-black/90 backdrop-blur-sm">
<div class="glass-panel p-6 rounded-xl max-w-sm w-full text-center">
<div class="w-16 h-16 bg-red-500/20 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4 text-2xl">
<i class="fas fa-trash-alt"></i>
</div>
<h3 class="text-xl font-bold text-white mb-2">Confirm Deletion</h3>
<p id="confirmText" class="text-gray-400 text-sm mb-6">Are you sure?</p>
<div class="flex justify-center gap-3">
<button onclick="document.getElementById('confirmModal').classList.add('hidden')" class="px-4 py-2 rounded-lg bg-gray-700 text-white">Cancel</button>
<button id="confirmActionBtn" class="px-4 py-2 rounded-lg bg-red-600 text-white font-bold">Yes, Delete</button>
</div>
</div>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import { getFirestore, collection, addDoc, getDocs, getDoc, setDoc, doc, updateDoc, deleteDoc, query, orderBy, serverTimestamp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js";
import { getAuth, signInWithEmailAndPassword, onAuthStateChanged, signOut } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyB8f4b8xdU5Uq-HHqQ8kwxG6i18zdi8JAo",
authDomain: "site-hub-29fb2.firebaseapp.com",
projectId: "site-hub-29fb2",
storageBucket: "site-hub-29fb2.firebasestorage.app",
messagingSenderId: "373988520340",
appId: "1:373988520340:web:f9eafe75c8de05cca55f81",
measurementId: "G-DDEMB3X2XQ"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = getAuth(app);
const ADMIN_UID = "pc6zZYQM04ZS6488xkZd2GqrxsI2";
let allResources = [];
let chartInstances = {};
// --- AUTH LOGIC ---
onAuthStateChanged(auth, (user) => {
if (user && user.uid === ADMIN_UID) {
document.getElementById('loginSection').classList.add('hidden');
document.getElementById('adminLayout').classList.remove('hidden');
document.getElementById('adminEmailDisplay').textContent = user.email;
initDashboard();
} else {
document.getElementById('loginSection').classList.remove('hidden');
document.getElementById('adminLayout').classList.add('hidden');
if(user) signOut(auth); // Kick out non-admins
}
});
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
try {
await signInWithEmailAndPassword(auth, document.getElementById('loginEmail').value, document.getElementById('loginPassword').value);
showToast("Welcome back, Commander.", "success");
} catch (err) { showToast(err.message, "error"); }
});
document.getElementById('logoutButton').addEventListener('click', () => signOut(auth));
// --- UI NAVIGATION ---
window.switchTab = (tabId) => {
document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
document.getElementById(`tab-${tabId}`).classList.add('active');
document.querySelectorAll('.sidebar-link').forEach(el => el.classList.remove('active'));
document.getElementById(`nav-${tabId}`).classList.add('active');
// Mobile: close sidebar on selection
if(window.innerWidth < 768) document.querySelector('aside').classList.add('hidden');
};
// --- DASHBOARD INIT ---
async function initDashboard() {
await Promise.all([loadResources(), loadInbox(), loadSettings()]);
}
// --- RESOURCES LOGIC ---
async function loadResources() {
const tbody = document.getElementById('resourcesTableBody');
tbody.innerHTML = '<tr><td colspan="4" class="text-center py-8"><i class="fas fa-spinner fa-spin text-2xl"></i></td></tr>';
try {
const q = query(collection(db, 'resources'), orderBy('votes', 'desc'));
const snap = await getDocs(q);
allResources = snap.docs.map(d => {
let data = d.data();
let cats = data.categories || [];
let subcats = data.subcategories || [];
if (cats.includes('notes')) {
cats = cats.filter(c => c !== 'notes');
if (!cats.includes('academics')) cats.push('academics');
if (!subcats.includes('notes')) subcats.push('notes');
}
if (cats.includes('coding')) {
cats = cats.filter(c => c !== 'coding');
if (!cats.includes('academics')) cats.push('academics');
if (!subcats.includes('coding')) subcats.push('coding');
}
return { id: d.id, ...data, categories: cats, subcategories: subcats };
});
// Update Stats
document.getElementById('statTotalResources').innerText = allResources.length;
document.getElementById('statTotalVotes').innerText = allResources.reduce((acc, curr) => acc + (curr.votes || 0), 0);
renderResourcesTable(allResources);
renderCharts();
} catch (err) { console.error(err); tbody.innerHTML = '<tr><td colspan="4" class="text-center text-red-400">Error loading data.</td></tr>'; }
}
function renderResourcesTable(data) {
const tbody = document.getElementById('resourcesTableBody');
tbody.innerHTML = '';
if (data.length === 0) {
tbody.innerHTML = '<tr><td colspan="4" class="text-center py-8 text-gray-500">No resources found.</td></tr>';
return;
}
data.forEach(r => {
const tr = document.createElement('tr');
tr.className = 'border-b border-white/5 transition hover:bg-white/5';
// Categories Badges
const catsHtml = (r.categories || []).map(c =>
`<span class="inline-block bg-white/10 text-xs px-2 py-0.5 rounded mr-1 mb-1 capitalize text-gray-300">${c}</span>`
).join('');
tr.innerHTML = `
<td class="p-4">
<div class="font-semibold text-white flex items-center gap-2">
${r.name}
${r.isVerified ? '<i class="fas fa-check-circle text-blue-400 text-xs" title="Verified"></i>' : ''}
</div>
<div class="text-xs text-blue-300 truncate max-w-[200px] cursor-pointer hover:underline" onclick="window.open('${r.url}', '_blank')">${r.url}</div>
</td>
<td class="p-4 max-w-xs">${catsHtml}</td>
<td class="p-4">
<div class="flex items-center gap-2">
<span class="text-green-400 font-mono font-bold">${r.votes || 0}</span> <span class="text-xs text-gray-500">votes</span>
</div>
</td>
<td class="p-4 text-right">
<button onclick="toggleHideResource('${r.id}', ${r.isHidden || false})" class="${r.isHidden ? 'text-amber-500' : 'text-gray-400'} hover:text-white px-2 transition" title="${r.isHidden ? 'Unhide from Main Site' : 'Hide from Main Site'}">
<i class="fas ${r.isHidden ? 'fa-eye-slash' : 'fa-eye'}"></i>
</button>
<button onclick="editResource('${r.id}')" class="text-gray-400 hover:text-white px-2 transition"><i class="fas fa-pen"></i></button>
<button onclick="deleteResource('${r.id}')" class="text-gray-400 hover:text-red-400 px-2 transition"><i class="fas fa-trash"></i></button>
</td>
`;
tbody.appendChild(tr);
});
}
const filterFn = () => {
const text = document.getElementById('searchResources').value.toLowerCase();
const cat = document.getElementById('filterResources').value;
const filtered = allResources.filter(r => {
const matchesText = r.name.toLowerCase().includes(text) || r.url.includes(text);
const matchesCat = cat === 'all' || (r.categories && r.categories.includes(cat));
return matchesText && matchesCat;
});
renderResourcesTable(filtered);
};
document.getElementById('searchResources').addEventListener('input', filterFn);
document.getElementById('filterResources').addEventListener('change', filterFn);
// Charts
function renderCharts() {
const ctx1 = document.getElementById('categoryChart');
const ctx2 = document.getElementById('votesChart');
// Process Data
const catCounts = {};
const catVotes = {};
allResources.forEach(r => {
(r.categories || []).forEach(c => {
catCounts[c] = (catCounts[c] || 0) + 1;
catVotes[c] = (catVotes[c] || 0) + (r.votes || 0);
});
});
const labels = Object.keys(catCounts);
if (chartInstances.cat) chartInstances.cat.destroy();
if (chartInstances.vote) chartInstances.vote.destroy();
Chart.defaults.color = '#a6adc8';
Chart.defaults.borderColor = '#313244';
chartInstances.cat = new Chart(ctx1, {
type: 'doughnut',
data: {
labels: labels.map(l => l.toUpperCase()),
datasets: [{
data: Object.values(catCounts),
backgroundColor: ['#cba6f7', '#89b4fa', '#a6e3a1', '#f9e2af', '#fab387', '#f38ba8'],
borderWidth: 0
}]
},
options: { maintainAspectRatio: false, plugins: { legend: { position: 'right' } } }
});
chartInstances.vote = new Chart(ctx2, {
type: 'bar',
data: {
labels: labels.map(l => l.toUpperCase()),
datasets: [{
label: 'Votes',
data: Object.values(catVotes),
backgroundColor: '#89b4fa',
borderRadius: 4
}]
},
options: { maintainAspectRatio: false, scales: { x: { grid: { display: false } } } }
});
}
// --- CRUD OPERATIONS ---
window.closeModal = () => {
document.getElementById('addResourceModal').classList.add('hidden');
document.getElementById('resourceForm').reset();
document.querySelectorAll('.cat-check').forEach(c => c.checked = false);
document.getElementById('resourceId').value = '';
document.getElementById('suggestionRefId').value = '';
document.getElementById('formVotes').value = '';
document.getElementById('dynamicSubcatsContainer').innerHTML = '';
document.getElementById('dynamicSubcatsSection').style.display = 'none';
};
const predefinedSubcats = {
academics: ['notes', 'coding'],
entertainment: ['movies', 'anime', 'music'],
productivity: ['tools', 'planning'],
design: ['ui-ux', 'graphics', 'inspirations'],
utilities: [],
'student-projects': ['web', 'app']
};
window.updateSubcatCheckboxes = () => {
const container = document.getElementById('dynamicSubcatsContainer');
const section = document.getElementById('dynamicSubcatsSection');
const selectedCats = Array.from(document.querySelectorAll('.cat-check:checked')).map(c => c.value);
let html = '';
let showSection = false;
selectedCats.forEach(cat => {
if (predefinedSubcats[cat]) {
showSection = true;
html += `
<div class="w-full">
<div class="text-[10px] text-purple-400 font-bold uppercase mb-2 tracking-wider border-b border-purple-400/20 pb-1">${cat.replace('-', ' ')}</div>
<div class="flex flex-wrap gap-2">
`;
predefinedSubcats[cat].forEach(sub => {
html += `
<label class="flex items-center space-x-2 cursor-pointer p-1.5 px-3 bg-[#11111b] border border-white/5 rounded-full hover:bg-white/10 transition">
<input type="checkbox" value="${sub}" class="subcat-check w-3 h-3 rounded-sm bg-gray-700 border-gray-600 text-blue-500 focus:ring-blue-500">
<span class="text-xs text-gray-300 capitalize font-medium">${sub.replace('-', ' ')}</span>
</label>
`;
});
html += `</div></div>`;
}
});
container.innerHTML = html;
section.style.display = showSection ? 'block' : 'none';
};
window.editResource = (id) => {
const r = allResources.find(x => x.id === id);
if (!r) return;
document.getElementById('modalTitle').innerText = "Edit Resource";
document.getElementById('resourceId').value = id;
document.getElementById('formName').value = r.name;
document.getElementById('formUrl').value = r.url;
document.getElementById('formDescription').value = r.description || '';
document.getElementById('formVerified').checked = r.isVerified || false;
document.getElementById('formHidden').checked = r.isHidden || false;
document.getElementById('formVotes').value = r.votes || 0;
// Set Categories
document.querySelectorAll('.cat-check').forEach(cb => {
cb.checked = (r.categories || []).includes(cb.value);
});
// Update the subcategory checkboxes UI based on categories
window.updateSubcatCheckboxes();
// Re-check subcategories
const allSubcatCheckboxes = Array.from(document.querySelectorAll('.subcat-check'));
(r.subcategories || []).forEach(sub => {
const cb = allSubcatCheckboxes.find(c => c.value === sub);
if (cb) cb.checked = true;
});
document.getElementById('addResourceModal').classList.remove('hidden');
};
document.getElementById('resourceForm').addEventListener('submit', async (e) => {
e.preventDefault();
const id = document.getElementById('resourceId').value;
const suggId = document.getElementById('suggestionRefId').value;
const checkedSubcats = Array.from(document.querySelectorAll('.subcat-check:checked')).map(c => c.value);
const data = {
name: document.getElementById('formName').value,
url: document.getElementById('formUrl').value,
description: document.getElementById('formDescription').value,
categories: Array.from(document.querySelectorAll('.cat-check:checked')).map(c => c.value),
subcategories: checkedSubcats,
isVerified: document.getElementById('formVerified').checked,
isHidden: document.getElementById('formHidden').checked
};
if (data.categories.length === 0) { showToast("Select at least 1 category", "error"); return; }
const btn = e.target.querySelector('button[type="submit"]');
btn.disabled = true; btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
// Allow the admin to set explicit initial votes or edit old votes
data.votes = parseInt(document.getElementById('formVotes').value) || 0;
try {
if (id) {
// Update
await updateDoc(doc(db, 'resources', id), data);
showToast("Resource updated");
// Update local state
const idx = allResources.findIndex(r => r.id === id);
if (idx !== -1) {
allResources[idx] = { ...allResources[idx], ...data };
}
} else {
// Create
data.status = 'approved';
data.votedBy = [];
data.createdAt = serverTimestamp();
const docRef = await addDoc(collection(db, 'resources'), data);
// Add to local state
allResources.push({ id: docRef.id, ...data });
if (suggId) await deleteDoc(doc(db, 'suggestions', suggId));
showToast("Resource added");
}
closeModal();
// Update UI without full refresh
filterFn();
renderCharts();
document.getElementById('statTotalResources').innerText = allResources.length;
document.getElementById('statTotalVotes').innerText = allResources.reduce((acc, curr) => acc + (curr.votes || 0), 0);
// If it was a suggestion, we still need to reload inbox
if (suggId) loadInbox();
} catch (err) { showToast(err.message, "error"); }
finally { btn.disabled = false; btn.innerText = "Save Resource"; }
});
window.toggleHideResource = async (id, currentHidden) => {
// Optimistic Update: Update local state immediately for instant feedback
const resource = allResources.find(r => r.id === id);
if (resource) {
resource.isHidden = !currentHidden;
filterFn(); // Re-render the table with current search/filter state
}
try {
await updateDoc(doc(db, 'resources', id), { isHidden: !currentHidden });
showToast(`Resource ${!currentHidden ? 'hidden' : 'unhidden'} successfully`);
// We no longer call initDashboard() here to prevent the "sheet refresh"
} catch (err) {
// Rollback on failure
if (resource) {
resource.isHidden = currentHidden;
filterFn();
}
showToast("Operation failed", "error");
}
};
window.deleteResource = (id) => {
const btn = document.getElementById('confirmActionBtn');
btn.onclick = async () => {
const originalResources = [...allResources]; // Keep for rollback
try {
// Optimistic Delete: Update local state immediately
allResources = allResources.filter(r => r.id !== id);
filterFn();
document.getElementById('statTotalResources').innerText = allResources.length;
document.getElementById('statTotalVotes').innerText = allResources.reduce((acc, curr) => acc + (curr.votes || 0), 0);
renderCharts();
await deleteDoc(doc(db, 'resources', id));
document.getElementById('confirmModal').classList.add('hidden');
showToast("Deleted successfully");
} catch (err) {
// Rollback on failure
allResources = originalResources;
filterFn();
document.getElementById('statTotalResources').innerText = allResources.length;
document.getElementById('statTotalVotes').innerText = allResources.reduce((acc, curr) => acc + (curr.votes || 0), 0);
renderCharts();
showToast("Delete failed", "error");
}
};
document.getElementById('confirmText').innerText = "This action cannot be undone. Delete this resource?";
document.getElementById('confirmModal').classList.remove('hidden');
};
// --- INBOX (Reports & Suggestions) ---
async function loadInbox() {
// Suggestions
const sQ = query(collection(db, 'suggestions'), orderBy('submittedAt', 'desc'));
const sSnap = await getDocs(sQ);
const sList = document.getElementById('suggestionsList');
document.getElementById('statPendingSuggestions').innerText = sSnap.size;
document.getElementById('countSuggestions').innerText = sSnap.size;
document.getElementById('badgeInbox').innerText = sSnap.size; // Only show suggs in badge for now
if (sSnap.size > 0) document.getElementById('badgeInbox').classList.remove('hidden');
sList.innerHTML = sSnap.empty ? '<div class="text-center text-gray-500 py-10">Clean slate.</div>' : '';
sSnap.forEach(d => {
const s = d.data();
const card = document.createElement('div');
card.className = 'bg-white/5 p-4 rounded-lg border border-white/5';
card.innerHTML = `
<div class="flex justify-between items-start mb-2">
<h4 class="font-bold text-white">${s.name}</h4>
<span class="text-xs text-gray-500">${new Date(s.submittedAt?.seconds*1000).toLocaleDateString()}</span>
</div>
<a href="${s.url}" target="_blank" class="text-xs text-blue-400 break-all hover:underline">${s.url}</a>
<p class="text-sm text-gray-300 mt-2 bg-black/20 p-2 rounded italic">"${s.reason || 'No reason provided'}"</p>
<div class="flex gap-2 mt-3">
<button onclick="approveSugg('${d.id}', '${s.name.replace(/'/g, "\\'")}', '${s.url}', '${(s.reason||'').replace(/'/g, "\\'")}')" class="flex-1 bg-green-600/20 hover:bg-green-600/40 text-green-400 py-1.5 rounded text-xs font-bold transition">Approve</button>
<button onclick="rejectSugg('${d.id}')" class="flex-1 bg-red-600/20 hover:bg-red-600/40 text-red-400 py-1.5 rounded text-xs font-bold transition">Reject</button>
</div>
`;
sList.appendChild(card);
});
// Reports
const rQ = query(collection(db, 'reports'), orderBy('reportedAt', 'desc'));
const rSnap = await getDocs(rQ);
const rList = document.getElementById('reportsList');
document.getElementById('statActiveReports').innerText = rSnap.size;
document.getElementById('countReports').innerText = rSnap.size;
rList.innerHTML = rSnap.empty ? '<div class="text-center text-gray-500 py-10">No issues reported.</div>' : '';
rSnap.forEach(d => {
const r = d.data();
const card = document.createElement('div');
card.className = 'bg-red-500/5 p-4 rounded-lg border border-red-500/20';
card.innerHTML = `
<div class="flex justify-between items-center mb-1">
<span class="text-xs font-bold text-red-400 uppercase tracking-wider">${r.reason}</span>
<button onclick="dismissReport('${d.id}')" class="text-gray-500 hover:text-white"><i class="fas fa-times"></i></button>
</div>
<p class="text-white font-semibold mb-2">Resource: ${r.resourceName}</p>
<div class="flex gap-2">
<button onclick="editResource('${r.resourceId}')" class="text-xs bg-blue-600/20 text-blue-300 px-3 py-1 rounded hover:bg-blue-600/30">Check Resource</button>
</div>
`;
rList.appendChild(card);
});
}
window.approveSugg = (id, name, url, reason) => {
document.getElementById('modalTitle').innerText = "Approve Suggestion";
document.getElementById('formName').value = name;
document.getElementById('formUrl').value = url;
document.getElementById('formDescription').value = reason;
document.getElementById('suggestionRefId').value = id;
document.getElementById('addResourceModal').classList.remove('hidden');
};
window.rejectSugg = async (id) => {
if(confirm("Reject this suggestion permanently?")) {
await deleteDoc(doc(db, 'suggestions', id));
loadInbox();
showToast("Suggestion rejected");
}
};
window.dismissReport = async (id) => {
await deleteDoc(doc(db, 'reports', id));
loadInbox();
showToast("Report dismissed");
};
// --- SETTINGS ---
async function loadSettings() {
try {
const docSnap = await getDoc(doc(db, 'settings', 'config'));
if (docSnap.exists()) {
const data = docSnap.data();
document.getElementById('announcementText').value = data.announcementText || '';
document.getElementById('announcementType').value = data.announcementType || 'info';
document.getElementById('announcementActive').checked = data.showAnnouncement || false;
}
} catch (e) { console.log("Settings init error", e); }
}
document.getElementById('announcementForm').addEventListener('submit', async (e) => {
e.preventDefault();
const text = document.getElementById('announcementText').value;
const type = document.getElementById('announcementType').value;
const active = document.getElementById('announcementActive').checked;
try {
await setDoc(doc(db, 'settings', 'config'), { announcementText: text, announcementType: type, showAnnouncement: active }, { merge: true });
showToast("Configuration saved", "success");
} catch (err) { showToast("Save failed", "error"); }
});
// --- UTILS ---
document.getElementById('fetchMetaBtn').addEventListener('click', async () => {
const url = document.getElementById('formUrl').value;
if(!url) return showToast("Enter URL first", "error");
const btn = document.getElementById('fetchMetaBtn');
const originalHTML = btn.innerHTML;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
try {
const res = await fetch(`https://api.microlink.io?url=${encodeURIComponent(url)}`);
const data = await res.json();
if(data.status === 'success') {
// document.getElementById('formName').value = data.data.title || ''; // Removed per request
document.getElementById('formDescription').value = data.data.description || '';
showToast("Metadata fetched");
}
} catch(e) { showToast("Fetch failed", "error"); }
finally { btn.innerHTML = originalHTML; }
});
document.getElementById('exportBtn').addEventListener('click', () => {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(allResources, null, 2));
const a = document.createElement('a');
a.href = dataStr;
a.download = `sitehub_backup_${new Date().toISOString().split('T')[0]}.json`;
a.click();
});
function showToast(msg, type = 'success') {
const el = document.createElement('div');
const color = type === 'success' ? 'border-green-500 text-green-400' : 'border-red-500 text-red-400';
el.className = `glass-panel px-4 py-3 rounded-lg border-l-4 ${color} flex items-center gap-3 shadow-lg transform transition-all duration-300 translate-x-full opacity-0`;
el.innerHTML = `<i class="fas fa-${type==='success'?'check':'exclamation'}-circle"></i> <span class="text-sm font-medium text-white">${msg}</span>`;
document.getElementById('toast-container').appendChild(el);
requestAnimationFrame(() => el.classList.remove('translate-x-full', 'opacity-0'));
setTimeout(() => {
el.classList.add('opacity-0', 'translate-x-10');
setTimeout(() => el.remove(), 300);
}, 3000);
}
</script>
</body>
</html>