-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
403 lines (370 loc) · 18.8 KB
/
Copy pathadmin.html
File metadata and controls
403 lines (370 loc) · 18.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SF Eats — Admin</title>
<meta name="robots" content="noindex, nofollow" />
<style>
:root {
--sage-bg: #C3C9B8;
--sage-dark: #A9B09A;
--ink-dark: #2A2F28;
--ink-muted: rgba(42, 47, 40, 0.5);
--line-color: #2A2F28;
--mustard-yellow: #DFD154;
--love-high: #4a6e3a;
--love-mid: #8a7a2a;
--love-low: #8a3a3a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--sage-bg);
color: var(--ink-dark);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
min-height: 100vh;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
h1 { font-size: 1.3rem; letter-spacing: -0.02em; }
.sub { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-top: 4px; }
a { color: var(--ink-dark); }
/* login */
.gate { margin-top: 3rem; max-width: 380px; }
.gate label { display: block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); margin-bottom: 6px; }
.gate input {
width: 100%; padding: 10px 12px; font-size: 0.9rem;
border: 1px solid var(--line-color); background: transparent; color: var(--ink-dark);
}
.gate button {
margin-top: 0.75rem; padding: 10px 20px; font-size: 0.75rem; font-weight: 500;
text-transform: uppercase; letter-spacing: 0.08em; cursor: pointer;
background: var(--ink-dark); color: var(--sage-bg); border: 1px solid var(--ink-dark);
}
.gate .err { color: var(--love-low); font-size: 0.8rem; margin-top: 0.75rem; }
/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line-color); border: 1px solid var(--line-color); margin: 1.5rem 0; }
.stat { background: var(--sage-bg); padding: 0.9rem 1rem; }
.stat .k { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.stat .v { font-size: 1.5rem; font-weight: 500; margin-top: 2px; font-variant-numeric: tabular-nums; }
/* filter tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
border: 1px solid var(--line-color); background: transparent; color: var(--ink-dark);
padding: 6px 14px; cursor: pointer; font-size: 0.7rem; font-weight: 500;
text-transform: uppercase; letter-spacing: 0.08em;
}
.tab.active { background: var(--ink-dark); color: var(--sage-bg); }
/* rec cards */
.rec {
border: 1px solid var(--line-color); padding: 1rem 1.25rem; margin-bottom: 0.75rem;
background: rgba(42, 47, 40, 0.03); position: relative;
}
.rec .dish-tag { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.rec .name { font-size: 1rem; font-weight: 500; margin-top: 2px; }
.rec .meta { font-size: 0.7rem; color: var(--ink-muted); margin-top: 2px; }
.rec .note { font-size: 0.8rem; font-style: italic; opacity: 0.85; margin-top: 0.5rem; line-height: 1.5; }
.rec .byline { font-size: 0.6rem; color: var(--ink-muted); margin-top: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }
.rec .status {
position: absolute; top: 0.9rem; right: 1.1rem;
font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em;
padding: 3px 8px; border: 1px solid currentColor;
}
.status.pending { color: var(--love-mid); }
.status.approved { color: var(--love-high); }
.status.rejected { color: var(--love-low); }
.actions { display: flex; gap: 6px; margin-top: 0.75rem; }
.actions button {
border: 1px solid var(--line-color); background: transparent; color: var(--ink-dark);
padding: 5px 12px; cursor: pointer; font-size: 0.65rem; font-weight: 500;
text-transform: uppercase; letter-spacing: 0.06em; transition: all 0.15s;
}
.actions button:hover { background: rgba(42,47,40,0.08); }
.actions .approve:hover { color: var(--love-high); border-color: var(--love-high); }
.actions .reject:hover { color: var(--love-mid); border-color: var(--love-mid); }
.actions .delete:hover { color: var(--love-low); border-color: var(--love-low); }
.empty { color: var(--ink-muted); font-size: 0.85rem; padding: 2rem 0; }
/* data quality view */
.views { margin-top: 1.5rem; }
.dq-section { margin-top: 1.75rem; }
.dq-section h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); font-weight: 500; margin-bottom: 0.6rem; }
.dq-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0; font-size: 0.8rem; border-bottom: 1px solid rgba(42,47,40,0.12); }
.dq-row .n { width: 110px; flex-shrink: 0; }
.dq-row .bar { flex: 1; height: 8px; background: rgba(42,47,40,0.1); position: relative; }
.dq-row .bar i { position: absolute; inset: 0 auto 0 0; background: var(--love-low); }
.dq-row .c { width: 105px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-muted); font-size: 0.7rem; }
.dq-item { padding: 0.5rem 0.75rem; border: 1px solid rgba(42,47,40,0.2); margin-bottom: 4px; font-size: 0.78rem; display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; background: rgba(42,47,40,0.03); }
.dq-item .tag { color: var(--ink-muted); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; }
.dq-note { font-size: 0.72rem; color: var(--ink-muted); margin-top: 0.5rem; line-height: 1.5; }
details.dq-group { margin-bottom: 0.5rem; }
details.dq-group summary { cursor: pointer; font-size: 0.8rem; padding: 0.5rem 0; font-weight: 500; }
details.dq-group summary .cnt { color: var(--ink-muted); font-weight: 400; font-size: 0.7rem; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.links { font-size: 0.7rem; display: flex; gap: 1rem; }
.logout { background: none; border: none; color: var(--ink-muted); cursor: pointer; font-size: 0.7rem; text-decoration: underline; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
</style>
</head>
<body>
<div class="wrap">
<div class="topbar">
<div>
<h1>SF Eats — Admin</h1>
<div class="sub">Community picks moderation</div>
</div>
<div class="links" id="links" style="display:none">
<a href="https://vercel.com/selinayfilizps-projects/sf-eats/analytics" target="_blank">Analytics ↗</a>
<a href="https://dashboard.convex.dev" target="_blank">Convex ↗</a>
<button class="logout" id="logout">log out</button>
</div>
</div>
<div class="gate" id="gate">
<label for="keyInput">Admin key</label>
<input type="password" id="keyInput" autocomplete="current-password" />
<button id="loginBtn">Enter</button>
<div class="err" id="gateErr"></div>
</div>
<div id="dash" style="display:none">
<div class="tabs views" id="views">
<button class="tab view-tab active" data-view="picks">Community Picks</button>
<button class="tab view-tab" data-view="reports">Reports <span id="rep-badge"></span></button>
<button class="tab view-tab" data-view="data">Data Quality</button>
</div>
<div id="view-picks">
<div class="stats">
<div class="stat"><div class="k">Total</div><div class="v" id="st-total">–</div></div>
<div class="stat"><div class="k">Pending</div><div class="v" id="st-pending">–</div></div>
<div class="stat"><div class="k">Approved</div><div class="v" id="st-approved">–</div></div>
<div class="stat"><div class="k">This week</div><div class="v" id="st-week">–</div></div>
</div>
<div class="tabs" id="tabs"></div>
<div id="list"></div>
</div>
<div id="view-reports" style="display:none"></div>
<div id="view-data" style="display:none"></div>
</div>
</div>
<script src="sf-food-data.js"></script>
<script>
const CONVEX_URL = 'https://peaceful-cricket-351.convex.cloud';
let KEY = localStorage.getItem('sfeats-admin-key') || '';
let RECS = [];
let FILTER = 'pending';
// sf-food-data.js exposes window.SF_FOOD_DATA
const FOOD = window.SF_FOOD_DATA || {};
const CUISINES = FOOD.cuisines || {};
// dishId -> "Cuisine · Dish" label
const DISH_LABELS = {};
Object.keys(CUISINES).forEach(c => (CUISINES[c].dishes || []).forEach(d => {
DISH_LABELS[d.id] = `${CUISINES[c].label} · ${d.name}`;
}));
async function convexCall(kind, path, args) {
const res = await fetch(`${CONVEX_URL}/api/${kind}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, args })
});
const j = await res.json();
if (!res.ok || j.status === 'error') throw new Error(j.errorMessage || `HTTP ${res.status}`);
return j.value;
}
function esc(s) { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
function statusOf(r) { return r.status || 'approved'; }
let REPORTS = [];
async function login(key) {
document.getElementById('gateErr').textContent = '';
try {
RECS = await convexCall('query', 'admin:listAll', { key });
KEY = key;
localStorage.setItem('sfeats-admin-key', key);
document.getElementById('gate').style.display = 'none';
document.getElementById('dash').style.display = '';
document.getElementById('links').style.display = '';
render();
loadReports();
} catch (e) {
localStorage.removeItem('sfeats-admin-key');
document.getElementById('gateErr').textContent = /unauthorized/i.test(e.message) ? 'Wrong key.' : `Error: ${e.message}`;
}
}
async function refresh() {
RECS = await convexCall('query', 'admin:listAll', { key: KEY });
render();
}
async function loadReports() {
try {
REPORTS = await convexCall('query', 'admin:listReports', { key: KEY });
} catch (e) { REPORTS = []; }
const open = REPORTS.filter(r => !r.resolved).length;
document.getElementById('rep-badge').textContent = open ? `(${open})` : '';
renderReports();
}
function renderReports() {
const el = document.getElementById('view-reports');
if (!REPORTS.length) { el.innerHTML = '<div class="empty">No reports yet. They\'ll show up when visitors flag a closed spot or wrong info.</div>'; return; }
el.innerHTML = '';
const KINDS = { 'closed': 'Permanently closed', 'wrong-info': 'Wrong info', 'other': 'Other' };
[...REPORTS].sort((a, b) => (a.resolved ? 1 : 0) - (b.resolved ? 1 : 0) || b._creationTime - a._creationTime).forEach(r => {
const when = new Date(r._creationTime).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
const card = document.createElement('div');
card.className = 'rec';
card.innerHTML = `
<span class="status ${r.resolved ? 'approved' : 'pending'}">${r.resolved ? 'resolved' : 'open'}</span>
<div class="dish-tag">${esc(DISH_LABELS[r.dishId] || r.dishId)}</div>
<div class="name">${esc(r.spotName)}</div>
<div class="meta">${esc(KINDS[r.kind] || r.kind)}</div>
${r.note ? `<div class="note">"${esc(r.note)}"</div>` : ''}
<div class="byline">${when}</div>
<div class="actions">
<button class="approve">${r.resolved ? 'Reopen' : 'Mark resolved'}</button>
<button class="delete">Delete</button>
</div>`;
card.querySelector('.approve').onclick = async () => {
await convexCall('mutation', 'admin:resolveReport', { key: KEY, id: r._id, resolved: !r.resolved });
loadReports();
};
card.querySelector('.delete').onclick = async () => {
if (!confirm('Delete this report?')) return;
await convexCall('mutation', 'admin:removeReport', { key: KEY, id: r._id });
loadReports();
};
el.appendChild(card);
});
}
function render() {
const counts = { all: RECS.length, pending: 0, approved: 0, rejected: 0 };
const weekAgo = Date.now() - 7 * 24 * 3600 * 1000;
let week = 0;
RECS.forEach(r => { counts[statusOf(r)]++; if (r._creationTime > weekAgo) week++; });
document.getElementById('st-total').textContent = counts.all;
document.getElementById('st-pending').textContent = counts.pending;
document.getElementById('st-approved').textContent = counts.approved;
document.getElementById('st-week').textContent = week;
const tabs = document.getElementById('tabs');
tabs.innerHTML = '';
['pending', 'approved', 'rejected', 'all'].forEach(f => {
const b = document.createElement('button');
b.className = 'tab' + (f === FILTER ? ' active' : '');
b.textContent = `${f} (${counts[f]})`;
b.onclick = () => { FILTER = f; render(); };
tabs.appendChild(b);
});
const list = document.getElementById('list');
list.innerHTML = '';
const shown = RECS.filter(r => FILTER === 'all' || statusOf(r) === FILTER);
if (!shown.length) {
list.innerHTML = `<div class="empty">Nothing ${FILTER === 'all' ? 'here yet' : FILTER}.</div>`;
return;
}
shown.forEach(r => {
const st = statusOf(r);
const when = new Date(r._creationTime).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
const card = document.createElement('div');
card.className = 'rec';
card.innerHTML = `
<span class="status ${st}">${st}</span>
<div class="dish-tag">${esc(DISH_LABELS[r.dishId] || r.dishId)}</div>
<div class="name">${esc(r.name)}</div>
${r.neighborhood ? `<div class="meta">${esc(r.neighborhood)}</div>` : ''}
${r.note ? `<div class="note">"${esc(r.note)}"</div>` : ''}
<div class="byline">${r.by ? esc(r.by) : 'Anonymous'} · ${when}</div>
<div class="actions">
${st !== 'approved' ? '<button class="approve">Approve</button>' : ''}
${st !== 'rejected' ? '<button class="reject">Reject</button>' : ''}
<button class="delete">Delete</button>
</div>`;
const act = async (fn) => {
card.querySelectorAll('.actions button').forEach(b => b.disabled = true);
try { await fn(); await refresh(); }
catch (e) { alert(`Failed: ${e.message}`); card.querySelectorAll('.actions button').forEach(b => b.disabled = false); }
};
const ap = card.querySelector('.approve');
if (ap) ap.onclick = () => act(() => convexCall('mutation', 'admin:setStatus', { key: KEY, id: r._id, status: 'approved' }));
const rj = card.querySelector('.reject');
if (rj) rj.onclick = () => act(() => convexCall('mutation', 'admin:setStatus', { key: KEY, id: r._id, status: 'rejected' }));
card.querySelector('.delete').onclick = () => {
if (!confirm(`Permanently delete "${r.name}"? Reject hides it without deleting.`)) return;
act(() => convexCall('mutation', 'admin:remove', { key: KEY, id: r._id }));
};
list.appendChild(card);
});
}
// ── Data quality view ──────────────────────────────────────────────
function renderData() {
const el = document.getElementById('view-data');
let spots = 0, unrated = 0, verified = 0;
const perCuisine = []; // {label, unrated, total}
const unratedByDish = []; // {label, spots: [names]}
const hypeTraps = []; // {dish, name, mentions, approval}
Object.keys(CUISINES).forEach(c => {
const cu = CUISINES[c];
let cUn = 0, cTot = 0;
(cu.dishes || []).forEach(d => {
const missing = [];
(d.spots || []).forEach(s => {
spots++; cTot++;
if (s.dishVerified) verified++;
if (s.dishApproval == null && s.dishMentions == null) { unrated++; cUn++; missing.push(s.name); }
if (s.dishMentions >= 60 && s.dishApproval != null && s.dishApproval < 70)
hypeTraps.push({ dish: `${cu.label} · ${d.name}`, name: s.name, mentions: s.dishMentions, approval: s.dishApproval });
});
if (missing.length) unratedByDish.push({ label: `${cu.label} · ${d.name}`, spots: missing });
});
perCuisine.push({ label: cu.label, unrated: cUn, total: cTot });
});
perCuisine.sort((a, b) => (b.unrated / b.total) - (a.unrated / a.total));
const genDate = FOOD.generatedAt ? new Date(FOOD.generatedAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : '?';
const pct = spots ? Math.round(100 * unrated / spots) : 0;
el.innerHTML = `
<div class="stats">
<div class="stat"><div class="k">Spots</div><div class="v">${spots}</div></div>
<div class="stat"><div class="k">Unrated</div><div class="v">${unrated} <span style="font-size:0.8rem;color:var(--ink-muted)">(${pct}%)</span></div></div>
<div class="stat"><div class="k">Verified</div><div class="v">${verified}</div></div>
<div class="stat"><div class="k">Data from</div><div class="v" style="font-size:0.95rem;padding-top:6px">${genDate}</div></div>
</div>
<div class="dq-section">
<h2>Unrated by cuisine</h2>
${perCuisine.map(c => `
<div class="dq-row">
<span class="n">${esc(c.label)}</span>
<span class="bar"><i style="width:${c.total ? Math.round(100 * c.unrated / c.total) : 0}%"></i></span>
<span class="c">${c.unrated}/${c.total} unrated</span>
</div>`).join('')}
</div>
${hypeTraps.length ? `
<div class="dq-section">
<h2>Hype traps (talked about a lot, loved less)</h2>
${hypeTraps.map(t => `
<div class="dq-item">
<span><strong>${esc(t.name)}</strong> <span class="tag">${esc(t.dish)}</span></span>
<span class="tag">${t.mentions} mentions · ${t.approval}% loved</span>
</div>`).join('')}
</div>` : ''}
<div class="dq-section">
<h2>Checklist — spots missing hype/love scores</h2>
<div class="dq-note">Work through these in <code>verified-dishes.js</code>, or run the generator with a topped-up SerpAPI key to score them all automatically.</div>
${unratedByDish.map(g => `
<details class="dq-group">
<summary>${esc(g.label)} <span class="cnt">— ${g.spots.length} spot${g.spots.length !== 1 ? 's' : ''}</span></summary>
${g.spots.map(n => `<div class="dq-item">${esc(n)}</div>`).join('')}
</details>`).join('')}
</div>`;
}
document.querySelectorAll('.view-tab').forEach(b => {
b.onclick = () => {
document.querySelectorAll('.view-tab').forEach(x => x.classList.toggle('active', x === b));
const v = b.dataset.view;
document.getElementById('view-picks').style.display = v === 'picks' ? '' : 'none';
document.getElementById('view-reports').style.display = v === 'reports' ? '' : 'none';
document.getElementById('view-data').style.display = v === 'data' ? '' : 'none';
if (v === 'data') renderData();
if (v === 'reports') loadReports();
};
});
document.getElementById('loginBtn').onclick = () => login(document.getElementById('keyInput').value.trim());
document.getElementById('keyInput').addEventListener('keydown', e => { if (e.key === 'Enter') login(e.target.value.trim()); });
document.getElementById('logout').onclick = () => { localStorage.removeItem('sfeats-admin-key'); location.reload(); };
if (KEY) login(KEY);
</script>
</body>
</html>