Dedupe menu admin CSS/markup, restore Mark Sold Out/Available labels

CSS redundancy cleanup on the online menu management feature:

- .menu-category was a byte-for-byte duplicate of the existing .panel
  class (background/border/border-radius/padding); folds it into
  .panel's shared selector group instead, keeping only what's not
  shared (no margin-bottom, since these sit in a grid whose own gap
  already spaces them)
- Several inline style="..." attributes were hand-copied verbatim
  between admin/menu.php's PHP template and admin/menu.js's client-
  side row/panel templates (price/sort/description cell formatting,
  category heading spacing, the empty-state row). Replaced with real
  CSS classes (.item-price-cell, .item-sort-cell, .item-desc-cell,
  .cat-name-heading, .cat-desc-text, .no-items-row td) so the styling
  lives in one place instead of two
- class="font-mono" was referenced four times but never defined
  anywhere in CSS (silently doing nothing); it's now a real one-line
  utility, which also fixes two previously-dead uses of it already
  sitting in admin/index.php
- .form-actions already existed as a class with its own margin-top,
  but every usage (two new modals here, plus a pre-existing one in
  admin/index.php) redundantly re-specified layout via inline style
  with a slightly different margin-top value each time; extended the
  shared class to own the whole pattern and dropped all three inline
  overrides
- Removed a no-op `justify-content: flex-start` (the default value)
  from the new .admin-toolbar

Caught and fixed a regression from the above before it shipped:
removing the inline margin-bottom override on the category heading
exposed that .panel h2's margin-bottom (from the existing panel
styles) has higher specificity than a bare .cat-name-heading class,
so the heading would have rendered with 5x the intended spacing.
Rescoped as .category-panel .cat-name-heading to reliably win.

Also restores the "Mark Sold Out" / "Mark Available" button wording
(both directions of the toggle, in both the PHP-rendered rows and
the two JS render paths) after it had been shortened to just "Sold
Out" / "Available".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
David DyerandClaude Sonnet 5 committed 2026-08-30 22:03:22 -04:00
1 parent f1bbf59548
commit 50eeb41375
4 files changed
+87 -33

No files matched your search

+1 -1
View File
@@ -176,7 +176,7 @@ $today = date('Y-m-d');
</div> </div>
</div> </div>
<div class="form-actions" style="display: flex; gap: 0.75rem; align-items: center;"> <div class="form-actions">
<button type="submit" class="btn btn-primary">Save Announcement</button> <button type="submit" class="btn btn-primary">Save Announcement</button>
<a href="index.php" class="btn btn-outline">Cancel</a> <a href="index.php" class="btn btn-outline">Cancel</a>
</div> </div>
+10 -10
View File
@@ -277,10 +277,10 @@ function updateOrInsertItemRow(item, isNew) {
const badgeCell = existingRow.querySelector('.item-badge-cell'); const badgeCell = existingRow.querySelector('.item-badge-cell');
badgeCell.innerHTML = item.badge badgeCell.innerHTML = item.badge
? `<span class="eyebrow" style="font-size: 0.68rem;">${escapeHtml(item.badge)}</span>` ? `<span class="eyebrow">${escapeHtml(item.badge)}</span>`
: '<span class="muted">—</span>'; : '<span class="muted">—</span>';
existingRow.querySelector('.btn-toggle-item').textContent = isAvail ? 'Sold Out' : 'Available'; existingRow.querySelector('.btn-toggle-item').textContent = isAvail ? 'Mark Sold Out' : 'Mark Available';
return; return;
} }
@@ -298,13 +298,13 @@ function updateOrInsertItemRow(item, isNew) {
tr.innerHTML = ` tr.innerHTML = `
<td><span class="status-badge ${isAvail ? 'active' : 'inactive'}">${isAvail ? '● Available' : '○ Sold Out / Hidden'}</span></td> <td><span class="status-badge ${isAvail ? 'active' : 'inactive'}">${isAvail ? '● Available' : '○ Sold Out / Hidden'}</span></td>
<td><strong class="item-name-cell">${escapeHtml(item.name)}</strong><div class="muted item-desc-cell" style="font-size: 0.82rem; margin-top: 0.2rem;">${escapeHtml(item.description || '')}</div></td> <td><strong class="item-name-cell">${escapeHtml(item.name)}</strong><div class="muted item-desc-cell">${escapeHtml(item.description || '')}</div></td>
<td class="font-mono item-price-cell" style="color: var(--gold-bright); font-weight: 500;">${escapeHtml(item.price)}</td> <td class="font-mono item-price-cell">${escapeHtml(item.price)}</td>
<td class="item-badge-cell">${item.badge ? `<span class="eyebrow" style="font-size: 0.68rem;">${escapeHtml(item.badge)}</span>` : '<span class="muted">—</span>'}</td> <td class="item-badge-cell">${item.badge ? `<span class="eyebrow">${escapeHtml(item.badge)}</span>` : '<span class="muted">—</span>'}</td>
<td class="font-mono item-sort-cell" style="color: var(--ink-muted); font-size: 0.8rem;">${item.sort_order || 0}</td> <td class="font-mono item-sort-cell">${item.sort_order || 0}</td>
<td><div class="admin-table-actions"> <td><div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-edit-item">Edit</button> <button type="button" class="btn btn-outline btn-sm btn-edit-item">Edit</button>
<button type="button" class="btn btn-outline btn-sm btn-toggle-item" data-id="${item.id}">${isAvail ? 'Sold Out' : 'Available'}</button> <button type="button" class="btn btn-outline btn-sm btn-toggle-item" data-id="${item.id}">${isAvail ? 'Mark Sold Out' : 'Mark Available'}</button>
<button type="button" class="btn btn-danger btn-sm btn-delete-item" data-id="${item.id}">Delete</button> <button type="button" class="btn btn-danger btn-sm btn-delete-item" data-id="${item.id}">Delete</button>
</div></td> </div></td>
`; `;
@@ -320,10 +320,10 @@ function categoryPanelHtml(category) {
return ` return `
<div class="panel-head"> <div class="panel-head">
<div> <div>
<h2 class="cat-name-heading" style="margin-bottom: 0.25rem;"> <h2 class="cat-name-heading">
<span>${escapeHtml(category.name)}</span> <span>${escapeHtml(category.name)}</span>
</h2> </h2>
<p class="muted cat-desc-text" style="font-size: 0.88rem;">${escapeHtml(category.description || '')}</p> <p class="muted cat-desc-text">${escapeHtml(category.description || '')}</p>
</div> </div>
<div class="admin-table-actions"> <div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-edit-cat">Edit Category</button> <button type="button" class="btn btn-outline btn-sm btn-edit-cat">Edit Category</button>
@@ -345,7 +345,7 @@ function categoryPanelHtml(category) {
</thead> </thead>
<tbody class="items-tbody"> <tbody class="items-tbody">
<tr class="no-items-row"> <tr class="no-items-row">
<td colspan="6" class="muted" style="text-align: center; padding: 1.5rem 0;">No items in this category yet.</td> <td colspan="6" class="muted">No items in this category yet.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
+28 -18
View File
@@ -11,12 +11,14 @@ $user = get_logged_in_user();
* Safely read a trimmed string from a POST payload, guarding against * Safely read a trimmed string from a POST payload, guarding against
* unexpected non-string input (e.g. a spoofed `name[]=` array field). * unexpected non-string input (e.g. a spoofed `name[]=` array field).
*/ */
function post_str(array $data, string $key, string $default = ''): string { function post_str(array $data, string $key, string $default = ''): string
{
$value = $data[$key] ?? $default; $value = $data[$key] ?? $default;
return is_string($value) ? trim($value) : $default; return is_string($value) ? trim($value) : $default;
} }
function handle_save_item(array $post): array { function handle_save_item(array $post): array
{
$categoryId = (int) ($post['category_id'] ?? 0); $categoryId = (int) ($post['category_id'] ?? 0);
if (!category_exists($categoryId)) { if (!category_exists($categoryId)) {
return ['success' => false, 'error' => 'Please choose a valid menu category.']; return ['success' => false, 'error' => 'Please choose a valid menu category.'];
@@ -46,7 +48,8 @@ function handle_save_item(array $post): array {
return ['success' => true, 'item' => get_menu_item_by_id($savedId), 'is_new' => $itemId === null]; return ['success' => true, 'item' => get_menu_item_by_id($savedId), 'is_new' => $itemId === null];
} }
function handle_toggle_item(array $post): array { function handle_toggle_item(array $post): array
{
$itemId = (int) ($post['item_id'] ?? 0); $itemId = (int) ($post['item_id'] ?? 0);
if ($itemId <= 0 || !get_menu_item_by_id($itemId)) { if ($itemId <= 0 || !get_menu_item_by_id($itemId)) {
return ['success' => false, 'error' => 'Menu item not found.']; return ['success' => false, 'error' => 'Menu item not found.'];
@@ -60,11 +63,12 @@ function handle_toggle_item(array $post): array {
'is_available' => (bool) $item['is_available'], 'is_available' => (bool) $item['is_available'],
'status_badge' => $item['is_available'] ? '● Available' : '○ Sold Out / Hidden', 'status_badge' => $item['is_available'] ? '● Available' : '○ Sold Out / Hidden',
'status_class' => $item['is_available'] ? 'active' : 'inactive', 'status_class' => $item['is_available'] ? 'active' : 'inactive',
'btn_text' => $item['is_available'] ? 'Sold Out' : 'Available', 'btn_text' => $item['is_available'] ? 'Mark Sold Out' : 'Mark Available',
]; ];
} }
function handle_delete_item(array $post): array { function handle_delete_item(array $post): array
{
$itemId = (int) ($post['item_id'] ?? 0); $itemId = (int) ($post['item_id'] ?? 0);
if ($itemId <= 0) { if ($itemId <= 0) {
return ['success' => false, 'error' => 'Menu item not found.']; return ['success' => false, 'error' => 'Menu item not found.'];
@@ -74,7 +78,8 @@ function handle_delete_item(array $post): array {
return ['success' => true]; return ['success' => true];
} }
function handle_save_category(array $post): array { function handle_save_category(array $post): array
{
$name = post_str($post, 'name'); $name = post_str($post, 'name');
if ($name === '') { if ($name === '') {
return ['success' => false, 'error' => 'Category name is required.']; return ['success' => false, 'error' => 'Category name is required.'];
@@ -94,7 +99,8 @@ function handle_save_category(array $post): array {
return ['success' => true, 'category' => get_category_by_id($savedId), 'is_new' => $catId === null]; return ['success' => true, 'category' => get_category_by_id($savedId), 'is_new' => $catId === null];
} }
function handle_delete_category(array $post): array { function handle_delete_category(array $post): array
{
$catId = (int) ($post['category_id'] ?? 0); $catId = (int) ($post['category_id'] ?? 0);
if ($catId <= 0) { if ($catId <= 0) {
return ['success' => false, 'error' => 'Category not found.']; return ['success' => false, 'error' => 'Category not found.'];
@@ -104,7 +110,8 @@ function handle_delete_category(array $post): array {
return ['success' => true]; return ['success' => true];
} }
function handle_menu_action(string $action, array $post): array { function handle_menu_action(string $action, array $post): array
{
return match ($action) { return match ($action) {
'save_item' => handle_save_item($post), 'save_item' => handle_save_item($post),
'toggle_item' => handle_toggle_item($post), 'toggle_item' => handle_toggle_item($post),
@@ -136,6 +143,7 @@ $menuGrouped = get_full_menu(false);
?> ?>
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -145,6 +153,7 @@ $menuGrouped = get_full_menu(false);
<link href="https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;1,9..144,400&family=Karla:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;1,9..144,400&family=Karla:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../styles.css"> <link rel="stylesheet" href="../styles.css">
</head> </head>
<body data-csrf-token="<?= htmlspecialchars(get_csrf_token(), ENT_QUOTES, 'UTF-8') ?>"> <body data-csrf-token="<?= htmlspecialchars(get_csrf_token(), ENT_QUOTES, 'UTF-8') ?>">
<nav class="admin-nav"> <nav class="admin-nav">
@@ -190,10 +199,10 @@ $menuGrouped = get_full_menu(false);
<div class="panel category-panel" id="cat-panel-<?= (int) $category['id'] ?>" data-cat-id="<?= (int) $category['id'] ?>" data-sort-order="<?= (int) $category['sort_order'] ?>"> <div class="panel category-panel" id="cat-panel-<?= (int) $category['id'] ?>" data-cat-id="<?= (int) $category['id'] ?>" data-sort-order="<?= (int) $category['sort_order'] ?>">
<div class="panel-head"> <div class="panel-head">
<div> <div>
<h2 class="cat-name-heading" style="margin-bottom: 0.25rem;"> <h2 class="cat-name-heading">
<span><?= htmlspecialchars($category['name']) ?></span> <span><?= htmlspecialchars($category['name']) ?></span>
</h2> </h2>
<p class="muted cat-desc-text" style="font-size: 0.88rem;"><?= htmlspecialchars($category['description'] ?? '') ?></p> <p class="muted cat-desc-text"><?= htmlspecialchars($category['description'] ?? '') ?></p>
</div> </div>
<div class="admin-table-actions"> <div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-edit-cat" <button type="button" class="btn btn-outline btn-sm btn-edit-cat"
@@ -224,7 +233,7 @@ $menuGrouped = get_full_menu(false);
<tbody class="items-tbody"> <tbody class="items-tbody">
<?php if (empty($category['items'])): ?> <?php if (empty($category['items'])): ?>
<tr class="no-items-row"> <tr class="no-items-row">
<td colspan="6" class="muted" style="text-align: center; padding: 1.5rem 0;">No items in this category yet.</td> <td colspan="6" class="muted">No items in this category yet.</td>
</tr> </tr>
<?php else: ?> <?php else: ?>
<?php foreach ($category['items'] as $item): ?> <?php foreach ($category['items'] as $item): ?>
@@ -238,28 +247,28 @@ $menuGrouped = get_full_menu(false);
</td> </td>
<td> <td>
<strong class="item-name-cell"><?= htmlspecialchars($item['name']) ?></strong> <strong class="item-name-cell"><?= htmlspecialchars($item['name']) ?></strong>
<div class="muted item-desc-cell" style="font-size: 0.82rem; margin-top: 0.2rem;"> <div class="muted item-desc-cell">
<?= htmlspecialchars($item['description'] ?? '') ?> <?= htmlspecialchars($item['description'] ?? '') ?>
</div> </div>
</td> </td>
<td class="font-mono item-price-cell" style="color: var(--gold-bright); font-weight: 500;"> <td class="font-mono item-price-cell">
<?= htmlspecialchars($item['price']) ?> <?= htmlspecialchars($item['price']) ?>
</td> </td>
<td class="item-badge-cell"> <td class="item-badge-cell">
<?php if (!empty($item['badge'])): ?> <?php if (!empty($item['badge'])): ?>
<span class="eyebrow" style="font-size: 0.68rem;"><?= htmlspecialchars($item['badge']) ?></span> <span class="eyebrow"><?= htmlspecialchars($item['badge']) ?></span>
<?php else: ?> <?php else: ?>
<span class="muted">—</span> <span class="muted">—</span>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td class="font-mono item-sort-cell" style="color: var(--ink-muted); font-size: 0.8rem;"> <td class="font-mono item-sort-cell">
<?= (int) $item['sort_order'] ?> <?= (int) $item['sort_order'] ?>
</td> </td>
<td> <td>
<div class="admin-table-actions"> <div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-edit-item">Edit</button> <button type="button" class="btn btn-outline btn-sm btn-edit-item">Edit</button>
<button type="button" class="btn btn-outline btn-sm btn-toggle-item" data-id="<?= (int) $item['id'] ?>"> <button type="button" class="btn btn-outline btn-sm btn-toggle-item" data-id="<?= (int) $item['id'] ?>">
<?= $item['is_available'] ? 'Sold Out' : 'Available' ?> <?= $item['is_available'] ? 'Mark Sold Out' : 'Mark Available' ?>
</button> </button>
<button type="button" class="btn btn-danger btn-sm btn-delete-item" data-id="<?= (int) $item['id'] ?>"> <button type="button" class="btn btn-danger btn-sm btn-delete-item" data-id="<?= (int) $item['id'] ?>">
Delete Delete
@@ -334,7 +343,7 @@ $menuGrouped = get_full_menu(false);
</div> </div>
</div> </div>
<div class="form-actions" style="display: flex; gap: 0.75rem; align-items: center; margin-top: 1.5rem;"> <div class="form-actions">
<button type="submit" class="btn btn-primary" id="btn-save-item">Save Item</button> <button type="submit" class="btn btn-primary" id="btn-save-item">Save Item</button>
<button type="button" class="btn btn-outline" id="btn-cancel-item">Cancel</button> <button type="button" class="btn btn-outline" id="btn-cancel-item">Cancel</button>
</div> </div>
@@ -371,7 +380,7 @@ $menuGrouped = get_full_menu(false);
</div> </div>
</div> </div>
<div class="form-actions" style="display: flex; gap: 0.75rem; align-items: center; margin-top: 1.5rem;"> <div class="form-actions">
<button type="submit" class="btn btn-primary" id="btn-save-cat">Save Category</button> <button type="submit" class="btn btn-primary" id="btn-save-cat">Save Category</button>
<button type="button" class="btn btn-outline" id="btn-cancel-cat">Cancel</button> <button type="button" class="btn btn-outline" id="btn-cancel-cat">Cancel</button>
</div> </div>
@@ -382,4 +391,5 @@ $menuGrouped = get_full_menu(false);
<script src="menu.js" defer></script> <script src="menu.js" defer></script>
</body> </body>
</html> </html>
+48 -4
View File
@@ -543,7 +543,8 @@
.stat-card, .stat-card,
.card, .card,
.login-card, .login-card,
.panel { .panel,
.menu-category {
background: var(--surface); background: var(--surface);
border: 1px solid var(--rule); border: 1px solid var(--rule);
} }
@@ -1114,6 +1115,9 @@
} }
.form-actions { .form-actions {
display: flex;
gap: 0.75rem;
align-items: center;
margin-top: 1.75rem; margin-top: 1.75rem;
} }
@@ -1276,9 +1280,9 @@
text-align: left; text-align: left;
} }
/* background/border come from the shared .panel rule above; no
margin-bottom here since these sit in a grid whose own gap spaces them */
.menu-category { .menu-category {
background: var(--surface);
border: 1px solid var(--rule);
border-radius: 0.25rem; border-radius: 0.25rem;
padding: 2rem; padding: 2rem;
} }
@@ -1357,6 +1361,47 @@
font-weight: normal; font-weight: normal;
} }
/* admin menu table: category panel header + item cell formatting.
Shared between admin/menu.php's server render and admin/menu.js's
client-side row/panel templates, so it lives here once instead of
being duplicated as inline styles in both places. */
.font-mono {
font-family: var(--font-mono);
}
/* two classes to reliably outrank .panel h2's margin-bottom above */
.category-panel .cat-name-heading {
margin-bottom: 0.25rem;
}
.cat-desc-text {
font-size: 0.88rem;
}
.no-items-row td {
text-align: center;
padding: 1.5rem 0;
}
.item-desc-cell {
font-size: 0.82rem;
margin-top: 0.2rem;
}
.item-price-cell {
color: var(--gold-bright);
font-weight: 500;
}
.item-sort-cell {
color: var(--ink-muted);
font-size: 0.8rem;
}
.item-badge-cell .eyebrow {
font-size: 0.68rem;
}
/* ---------- admin modal dialogs ---------- */ /* ---------- admin modal dialogs ---------- */
.admin-modal-backdrop { .admin-modal-backdrop {
position: fixed; position: fixed;
@@ -1428,7 +1473,6 @@
.admin-toolbar { .admin-toolbar {
display: flex; display: flex;
justify-content: flex-start;
gap: 0.75rem; gap: 0.75rem;
align-items: center; align-items: center;
margin-bottom: 2rem; margin-bottom: 2rem;