-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminPage.js
More file actions
171 lines (144 loc) · 5.83 KB
/
Copy pathadminPage.js
File metadata and controls
171 lines (144 loc) · 5.83 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
function renderAdminPage() {
if (!isAdmin) {
alert("Access denied. Admin only.");
renderHomePage();
return;
}
const app = document.getElementById("app");
const totalLikes = newsData.reduce((sum, item) => sum + item.likes, 0);
const totalShares = newsData.reduce((sum, item) => sum + item.shares, 0);
app.innerHTML = `
<div class="details-page">
<div class="details-container">
<h2>Admin Dashboard</h2>
<p style="color:var(--subtext); margin-bottom:20px;">
Upload, edit, and delete news videos.
</p>
<div class="stats-row" style="margin-bottom:24px;">
<div class="meta-pill">Total News: ${newsData.length}</div>
<div class="meta-pill">Total Likes: ${totalLikes}</div>
<div class="meta-pill">Total Shares: ${totalShares}</div>
</div>
<div class="card-box">
<input type="hidden" id="editNewsId" />
<div class="controls-row">
<label>News Title</label>
<input type="text" id="adminTitle" placeholder="Enter title" />
</div>
<div class="controls-row">
<label>Category (optional - AI will detect if empty)</label>
<input type="text" id="adminCategory" placeholder="Technology / Business / Sports / General" />
</div>
<div class="controls-row">
<label>Video Path</label>
<input type="text" id="adminVideo" placeholder="assets/videos/yourvideo.mp4" />
</div>
<div class="controls-row">
<label>Source</label>
<input type="text" id="adminSource" placeholder="Source name" />
</div>
<div class="controls-row">
<label>Subtitle Caption</label>
<input type="text" id="adminSubtitle" placeholder="Short subtitle for reel..." />
</div>
<div class="controls-row">
<label>Summary</label>
<textarea id="adminSummary" placeholder="Write news summary..."></textarea>
</div>
<button class="primary-btn" onclick="saveAdminNews()">Save News</button>
<button class="secondary-btn" onclick="clearAdminForm()">Clear</button>
</div>
<h3 style="margin-top:30px;">All News</h3>
<div class="admin-list">
${newsData.map(news => `
<div class="admin-item">
<h3>${news.title}</h3>
<p style="color:var(--subtext); margin-bottom:10px;">${news.category} • ${news.source}</p>
<p style="color:var(--subtext);">${news.summary}</p>
<div class="admin-actions">
<button class="primary-btn" onclick="editNews(${news.id})">Edit</button>
<button class="danger-btn" onclick="deleteNews(${news.id})">Delete</button>
</div>
</div>
`).join("")}
</div>
</div>
${renderBottomNav("admin")}
</div>
`;
}
function saveAdminNews() {
const editId = document.getElementById("editNewsId").value;
const title = document.getElementById("adminTitle").value.trim();
const manualCategory = document.getElementById("adminCategory").value.trim();
const video = document.getElementById("adminVideo").value.trim();
const source = document.getElementById("adminSource").value.trim();
const subtitle = document.getElementById("adminSubtitle").value.trim();
const summary = document.getElementById("adminSummary").value.trim();
if (!title || !video || !source || !summary) {
alert("Please fill required fields");
return;
}
const detectedCategory = manualCategory || detectCategory(title, summary);
const newItem = {
id: editId ? Number(editId) : Date.now(),
title,
category: detectedCategory,
video,
subtitle: subtitle || summary,
summary,
likes: 0,
comments: 0,
shares: 0,
saved: false,
liked: false,
trending: true,
publishedAt: "Just now",
source
};
if (editId) {
const index = newsData.findIndex(n => n.id === Number(editId));
if (index !== -1) {
newItem.likes = newsData[index].likes;
newItem.comments = newsData[index].comments;
newItem.shares = newsData[index].shares;
newItem.saved = newsData[index].saved;
newItem.liked = newsData[index].liked;
newsData[index] = newItem;
}
} else {
newsData.unshift(newItem);
}
saveNews();
clearAdminForm();
alert(`News saved successfully! AI detected category: ${detectedCategory}`);
renderAdminPage();
}
function editNews(newsId) {
const news = newsData.find(n => n.id === newsId);
if (!news) return;
document.getElementById("editNewsId").value = news.id;
document.getElementById("adminTitle").value = news.title;
document.getElementById("adminCategory").value = news.category;
document.getElementById("adminVideo").value = news.video;
document.getElementById("adminSource").value = news.source;
document.getElementById("adminSubtitle").value = news.subtitle || "";
document.getElementById("adminSummary").value = news.summary;
window.scrollTo({ top: 0, behavior: "smooth" });
}
function deleteNews(newsId) {
const confirmDelete = confirm("Are you sure you want to delete this news?");
if (!confirmDelete) return;
newsData = newsData.filter(n => n.id !== newsId);
saveNews();
renderAdminPage();
}
function clearAdminForm() {
document.getElementById("editNewsId").value = "";
document.getElementById("adminTitle").value = "";
document.getElementById("adminCategory").value = "";
document.getElementById("adminVideo").value = "";
document.getElementById("adminSource").value = "";
document.getElementById("adminSubtitle").value = "";
document.getElementById("adminSummary").value = "";
}