-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
492 lines (441 loc) · 25 KB
/
Copy pathadmin.html
File metadata and controls
492 lines (441 loc) · 25 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard — MSLOG</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="images/logo1.png">
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore-compat.js"></script>
<script src="firebase-config.js"></script>
</head>
<body class="bg-[#f8fafc] min-h-screen flex flex-col">
<!-- ─── NAV ─── -->
<header>
<nav class="bg-[#063559] shadow-md" role="navigation" aria-label="Main navigation">
<div class="max-w-6xl mx-auto px-4">
<div class="flex justify-between items-center h-14">
<a href="index.html" class="flex items-center space-x-2">
<img src="images/logo1.png" alt="MSLOG Logo" class="h-8 w-auto">
<span class="text-white font-bold text-lg tracking-tight">MSLOG</span>
</a>
<div class="hidden md:flex items-center">
<div class="flex items-center space-x-1">
<div id="nav-desktop-public" class="flex items-center space-x-1">
<a href="index.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Home</a>
<a href="sop.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">S.O.P.</a>
<a href="contact.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors" title="Administrator Jeff Pugh">Contact</a>
</div>
<div id="nav-desktop-member" class="hidden flex items-center space-x-1">
<a href="dashboard.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Dashboard</a>
<a href="directory.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Directory</a>
<a href="documents.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Documents</a>
<a href="calendar.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Calendar</a>
<a href="gatecode.html" class="nav-link admin-only text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Gate Code</a>
<a href="videos.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Videos</a>
<a href="photos.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Photos</a>
<a href="forum.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Forum</a>
<a href="polls.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Polls</a>
<a href="forsale.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">For Sale</a>
<a href="weathercam.html" class="nav-link text-[#94A1B0] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Weather Cam</a>
<a href="admin.html" class="nav-link admin-only text-[#F9812A] hover:text-white px-3 py-1.5 rounded text-sm transition-colors">Admin</a>
</div>
</div>
<div id="nav-desktop-auth" class="ml-4 flex items-center"></div>
</div>
<button id="hamburger" class="md:hidden text-white p-1" aria-label="Toggle menu" aria-expanded="false">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
</div>
</div>
<div id="mobile-menu" class="md:hidden">
<div class="px-4 pt-2 pb-3 bg-[#052d4a]">
<a href="index.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Home</a>
<a href="sop.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">S.O.P.</a>
<a href="contact.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm" title="Administrator Jeff Pugh">Contact</a>
<div id="nav-mobile-member" class="hidden">
<a href="dashboard.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Dashboard</a>
<a href="directory.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Directory</a>
<a href="documents.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Documents</a>
<a href="calendar.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Calendar</a>
<a href="gatecode.html" class="nav-link admin-only block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Gate Code</a>
<a href="videos.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Videos</a>
<a href="photos.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Photos</a>
<a href="forum.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Forum</a>
<a href="polls.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Polls</a>
<a href="forsale.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">For Sale</a>
<a href="weathercam.html" class="nav-link block text-[#94A1B0] hover:text-white px-3 py-2 rounded text-sm">Weather Cam</a>
<a href="admin.html" class="nav-link admin-only block text-[#F9812A] hover:text-white px-3 py-2 rounded text-sm">Admin</a>
</div>
<div id="nav-mobile-auth"></div>
</div>
</div>
</nav>
</header>
<!-- ─── MAIN ─── -->
<main class="flex-1 px-4 py-8">
<div class="max-w-6xl mx-auto">
<!-- Header -->
<div class="page-header rounded-xl p-6 mb-6">
<div class="flex items-center gap-3">
<h1 class="text-white text-2xl font-bold">Admin Dashboard</h1>
<span class="badge badge-admin">Admin</span>
</div>
<p class="text-[#94A1B0] text-sm mt-1">Manage members, content, and system settings</p>
</div>
<!-- Stats row -->
<div class="grid grid-cols-2 md:grid-cols-5 gap-4 mb-6">
<div class="bg-white rounded-xl p-4 shadow-sm border border-[#e2e8f0]">
<p class="text-[#7E8994] text-xs uppercase tracking-wide">Total Members</p>
<p id="stat-total-members" class="text-2xl font-bold text-[#063559] mt-1">—</p>
<p class="text-[#7E8994] text-xs mt-1">Approved members</p>
</div>
<div class="bg-white rounded-xl p-4 shadow-sm border border-[#e2e8f0]">
<p class="text-[#7E8994] text-xs uppercase tracking-wide">Pending Approvals</p>
<p id="stat-pending" class="text-2xl font-bold text-[#F9812A] mt-1">—</p>
<p class="text-[#F9812A] text-xs mt-1">Awaiting review</p>
</div>
<div class="bg-white rounded-xl p-4 shadow-sm border border-[#e2e8f0]">
<p class="text-[#7E8994] text-xs uppercase tracking-wide">Documents</p>
<p id="stat-docs" class="text-2xl font-bold text-[#063559] mt-1">—</p>
<p class="text-[#7E8994] text-xs mt-1">In library</p>
</div>
<div class="bg-white rounded-xl p-4 shadow-sm border border-[#e2e8f0]">
<p class="text-[#7E8994] text-xs uppercase tracking-wide">Forum Posts</p>
<p id="stat-forum" class="text-2xl font-bold text-[#063559] mt-1">—</p>
<p class="text-[#7E8994] text-xs mt-1">Discussions</p>
</div>
<div class="bg-white rounded-xl p-4 shadow-sm border border-[#e2e8f0]">
<p class="text-[#7E8994] text-xs uppercase tracking-wide">Page Views</p>
<p id="stat-pageviews" class="text-2xl font-bold text-[#063559] mt-1">—</p>
<p class="text-[#7E8994] text-xs mt-1">Total hits</p>
</div>
</div>
<!-- Two-column layout -->
<div class="grid md:grid-cols-2 gap-6">
<!-- Pending Registrations -->
<div class="bg-white rounded-xl shadow-sm border border-[#e2e8f0] p-5">
<h2 class="font-bold text-[#063559] mb-4 text-xs uppercase tracking-wide">Pending Registrations</h2>
<div id="pending-list" class="space-y-3">
<p class="text-[#7E8994] text-sm">Loading...</p>
</div>
</div>
<!-- Quick Admin Actions -->
<div class="space-y-6">
<!-- Content Management -->
<div class="bg-white rounded-xl shadow-sm border border-[#e2e8f0] p-5">
<h2 class="font-bold text-[#063559] mb-3 text-xs uppercase tracking-wide">Content Management</h2>
<div class="space-y-2">
<a href="documents.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">📄 Manage Documents</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
<a href="videos.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">🎥 Manage Videos</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
<a href="photos.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">📷 Manage Photos</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
<a href="calendar.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">📅 Manage Events</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
<a href="gatecode.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">🔑 Update Gate Code</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
<a href="directory.html" class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-[#f0f4f8] transition-colors">
<span class="text-sm text-[#334155]">👥 Member Directory</span>
<span class="text-[#F9812A] text-xs">→</span>
</a>
</div>
</div>
<!-- Recent Members -->
<div class="bg-white rounded-xl shadow-sm border border-[#e2e8f0] p-5">
<h2 class="font-bold text-[#063559] mb-3 text-xs uppercase tracking-wide">Recent Members</h2>
<div id="recent-members" class="space-y-2">
<p class="text-[#7E8994] text-sm">Loading...</p>
</div>
</div>
</div>
</div>
<!-- Page View Breakdown -->
<div class="mt-6 bg-white rounded-xl shadow-sm border border-[#e2e8f0] p-5">
<h2 class="font-bold text-[#063559] mb-4 text-xs uppercase tracking-wide">Page Views by Section</h2>
<div id="pageview-breakdown" class="grid grid-cols-2 sm:grid-cols-5 gap-3">
<p class="text-[#7E8994] text-sm col-span-5">Loading...</p>
</div>
</div>
<!-- Maintenance -->
<div class="mt-6 bg-white rounded-xl shadow-sm border border-[#e2e8f0] p-5">
<h2 class="font-bold text-[#063559] mb-3 text-xs uppercase tracking-wide">Maintenance</h2>
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<div>
<p class="text-sm text-[#334155] font-medium">Backfill notification opt-ins</p>
<p class="text-[#7E8994] text-xs mt-0.5">Set every existing member to opted-in for all email topics. Existing explicit opt-outs are preserved.</p>
</div>
<button id="backfill-notif-btn" onclick="backfillNotificationOptIns()" class="text-xs bg-[#063559] text-white hover:bg-[#0a4a78] px-4 py-2 rounded font-medium transition-colors whitespace-nowrap">Run backfill</button>
</div>
<p id="backfill-notif-status" class="text-xs mt-2 hidden"></p>
</div>
</div>
</main>
<!-- ─── FOOTER ─── -->
<footer class="bg-[#063559] text-[#94A1B0] py-8 px-4 mt-auto">
<div class="max-w-6xl mx-auto">
<div class="flex flex-col md:flex-row justify-between items-center gap-4">
<div class="flex items-center space-x-2">
<img src="images/logo1.png" alt="MSLOG" class="h-6 w-auto opacity-70">
<span class="text-sm font-semibold text-white">MSLOG</span>
</div>
<p class="text-xs text-center">Mount Spokane Land Owners Group · Mount Spokane, WA</p>
<p class="text-xs">© 2026 MSLOG. All rights reserved.</p>
</div>
</div>
</footer>
<script src="script.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async function() {
await requireAuth();
await requireAdmin();
loadAdminData();
});
function loadAdminData() {
const db = firebase.firestore();
// Load stats
db.collection('members').where('status', '==', 'approved').get()
.then(snap => document.getElementById('stat-total-members').textContent = snap.size)
.catch(() => document.getElementById('stat-total-members').textContent = '0');
db.collection('members').where('status', '==', 'pending').get()
.then(snap => document.getElementById('stat-pending').textContent = snap.size)
.catch(() => document.getElementById('stat-pending').textContent = '0');
db.collection('documents').get()
.then(snap => document.getElementById('stat-docs').textContent = snap.size)
.catch(() => document.getElementById('stat-docs').textContent = '0');
db.collection('forum_posts').get()
.then(snap => document.getElementById('stat-forum').textContent = snap.size)
.catch(() => document.getElementById('stat-forum').textContent = '0');
// Load pending registrations
loadPendingRegistrations(db);
// Load recent members
loadRecentMembers(db);
// Load page view analytics
loadPageViews(db);
}
function loadPendingRegistrations(db) {
const container = document.getElementById('pending-list');
// Simple query without orderBy to avoid needing composite index
db.collection('members')
.where('status', '==', 'pending')
.get()
.then(snap => {
if (snap.empty) {
container.innerHTML = '<p class="text-green-600 text-sm">No pending registrations!</p>';
return;
}
// Sort by createdAt client-side
const pending = [];
snap.forEach(doc => pending.push({ id: doc.id, ...doc.data() }));
pending.sort((a, b) => (b.createdAt?.toDate?.() || 0) - (a.createdAt?.toDate?.() || 0));
container.innerHTML = '';
pending.forEach(m => {
const date = m.createdAt?.toDate ? m.createdAt.toDate() : new Date();
const dateStr = date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
container.innerHTML += `
<div class="border border-[#e2e8f0] rounded-lg p-3" data-id="${m.id}">
<div class="flex justify-between items-start">
<div>
<h4 class="text-sm font-semibold text-[#063559]">${m.name || 'Unknown'}</h4>
<p class="text-[#7E8994] text-xs">${m.email} · Lot: ${m.lot || 'N/A'}</p>
<p class="text-[#94A1B0] text-xs">Submitted ${dateStr}</p>
</div>
<span class="badge badge-pending">Pending</span>
</div>
<div class="flex gap-2 mt-3">
<button onclick="approveMember('${m.id}')" class="text-xs bg-green-100 text-green-700 hover:bg-green-200 px-3 py-1 rounded font-medium transition-colors">✓ Approve</button>
<button onclick="rejectMember('${m.id}')" class="text-xs bg-red-100 text-red-700 hover:bg-red-200 px-3 py-1 rounded font-medium transition-colors">✗ Reject</button>
</div>
</div>
`;
});
})
.catch(e => {
console.error('Error loading pending:', e);
container.innerHTML = '<p class="text-green-600 text-sm">No pending registrations!</p>';
});
}
function loadRecentMembers(db) {
const container = document.getElementById('recent-members');
// Simple query without orderBy to avoid needing composite index
db.collection('members')
.where('status', '==', 'approved')
.get()
.then(snap => {
if (snap.empty) {
container.innerHTML = '<p class="text-[#7E8994] text-sm">No members yet.</p>';
return;
}
// Sort by createdAt client-side and take first 5
const members = [];
snap.forEach(doc => members.push(doc.data()));
members.sort((a, b) => (b.createdAt?.toDate?.() || 0) - (a.createdAt?.toDate?.() || 0));
container.innerHTML = '';
members.slice(0, 5).forEach(m => {
const date = m.createdAt?.toDate ? m.createdAt.toDate() : new Date();
const dateStr = date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
container.innerHTML += `
<div class="flex items-start gap-2">
<span class="text-green-500 text-xs mt-0.5">●</span>
<div>
<p class="text-sm text-[#334155]">${m.name || 'Unknown'}</p>
<p class="text-[#94A1B0] text-xs">Joined ${dateStr}</p>
</div>
</div>
`;
});
})
.catch(e => {
console.error('Error loading recent members:', e);
container.innerHTML = '<p class="text-[#7E8994] text-sm">No members yet.</p>';
});
}
async function approveMember(memberId) {
if (!confirm('Approve this member?')) return;
try {
await firebase.firestore().collection('members').doc(memberId).update({
status: 'approved'
});
alert('Member approved! They will receive a welcome email.');
loadAdminData(); // Refresh
} catch (e) {
console.error('Error approving:', e);
alert('Error approving member.');
}
}
async function rejectMember(memberId) {
if (!confirm('Reject and delete this registration?')) return;
try {
await firebase.firestore().collection('members').doc(memberId).delete();
alert('Registration rejected.');
loadAdminData(); // Refresh
} catch (e) {
console.error('Error rejecting:', e);
alert('Error rejecting member.');
}
}
const PAGE_LABELS = {
index: 'Home',
dashboard: 'Dashboard',
directory: 'Directory',
documents: 'Documents',
calendar: 'Calendar',
forum: 'Forum',
videos: 'Videos',
gatecode: 'Gate Code',
admin: 'Admin',
contact: 'Contact'
};
async function loadPageViews(db) {
const statEl = document.getElementById('stat-pageviews');
const breakdown = document.getElementById('pageview-breakdown');
try {
const doc = await db.collection('settings').doc('analytics').get();
if (!doc.exists) {
if (statEl) statEl.textContent = '0';
if (breakdown) breakdown.innerHTML = '<p class="text-[#7E8994] text-sm col-span-5">No views recorded yet.</p>';
return;
}
const data = doc.data();
const total = data.total || 0;
if (statEl) statEl.textContent = total.toLocaleString();
const pages = data.pages || {};
const sorted = Object.entries(pages).sort((a, b) => b[1] - a[1]);
const max = sorted.length ? sorted[0][1] : 1;
if (breakdown) {
breakdown.innerHTML = sorted.map(([key, count]) => {
const label = PAGE_LABELS[key] || key;
const pct = Math.round((count / max) * 100);
return `<div class="bg-[#f8fafc] rounded-lg p-3 border border-[#e2e8f0]">
<p class="text-xs font-semibold text-[#063559] mb-1">${label}</p>
<p class="text-xl font-bold text-[#063559]">${count.toLocaleString()}</p>
<div class="mt-2 h-1.5 bg-[#e2e8f0] rounded-full overflow-hidden">
<div class="h-full bg-[#F9812A] rounded-full" style="width:${pct}%"></div>
</div>
</div>`;
}).join('');
}
} catch (e) {
console.error('Error loading page views:', e);
if (statEl) statEl.textContent = '—';
}
}
async function backfillNotificationOptIns() {
const btn = document.getElementById('backfill-notif-btn');
const status = document.getElementById('backfill-notif-status');
if (!confirm('Set every existing member to opted-in for all email topics?\n\nMembers who explicitly opted out of a topic will keep that opt-out.')) return;
btn.disabled = true;
btn.textContent = 'Running…';
status.classList.remove('hidden', 'text-red-600', 'text-green-600');
status.classList.add('text-[#7E8994]');
status.textContent = 'Reading members…';
try {
const db = firebase.firestore();
const snap = await db.collection('members').get();
const ALL_TOPICS = ['calendar', 'videos', 'forum'];
let updated = 0;
let skipped = 0;
// Chunk into batches of 400 (Firestore limit is 500 ops per batch)
let batch = db.batch();
let opsInBatch = 0;
const commits = [];
snap.forEach(doc => {
const data = doc.data();
const existing = (data.notifications && data.notifications.topics) || {};
const merged = {};
let changed = false;
ALL_TOPICS.forEach(t => {
if (existing[t] === false) {
merged[t] = false; // preserve explicit opt-outs
} else {
merged[t] = true;
if (existing[t] !== true) changed = true;
}
});
if (!changed) { skipped++; return; }
batch.update(doc.ref, { 'notifications.topics': merged });
updated++;
opsInBatch++;
if (opsInBatch >= 400) {
commits.push(batch.commit());
batch = db.batch();
opsInBatch = 0;
}
});
if (opsInBatch > 0) commits.push(batch.commit());
status.textContent = `Writing ${updated} member updates…`;
await Promise.all(commits);
status.classList.remove('text-[#7E8994]');
status.classList.add('text-green-600');
status.textContent = `Done. Updated ${updated} member(s); ${skipped} already opted in.`;
btn.textContent = 'Run again';
} catch (e) {
console.error('Backfill failed:', e);
status.classList.remove('text-[#7E8994]');
status.classList.add('text-red-600');
status.textContent = 'Backfill failed: ' + (e.message || e);
btn.textContent = 'Run backfill';
} finally {
btn.disabled = false;
}
}
</script>
</body>
</html>