Add mobile nav toggle, responsive admin tables, and menu reordering

- Public site: replace the always-hidden mobile nav with a hamburger
  toggle (index.php, menu.php, main.js, styles.css)
- Admin: render the Menu/Announcements/Users tables as labeled cards
  below ~760px instead of squeezing descriptions into unreadable
  single-word-per-line columns
- Admin menu: replace the manual "Order" number (which allowed
  duplicates and never reflected in real time) with ↑/↓ buttons that
  reorder items and categories immediately and renumber sort_order
  sequentially on every move, self-healing any stale duplicates

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
David DyerandClaude Sonnet 5 committed 2026-08-31 22:12:24 -04:00
1 parent 7c96b952e9
commit 40f4c102b4
10 files changed
+553 -94

No files matched your search

+45 -26
View File
@@ -42,7 +42,6 @@ function handle_save_item(array $post): array
'price' => $price,
'badge' => post_str($post, 'badge'),
'is_available' => isset($post['is_available']) ? 1 : 0,
'sort_order' => (int) ($post['sort_order'] ?? 0),
], $itemId);
return ['success' => true, 'item' => get_menu_item_by_id($savedId), 'is_new' => $itemId === null];
@@ -67,6 +66,20 @@ function handle_toggle_item(array $post): array
];
}
function handle_move_item(array $post): array
{
$itemId = (int) ($post['item_id'] ?? 0);
$direction = post_str($post, 'direction');
if ($itemId <= 0 || !get_menu_item_by_id($itemId)) {
return ['success' => false, 'error' => 'Menu item not found.'];
}
if (!in_array($direction, ['up', 'down'], true)) {
return ['success' => false, 'error' => 'Invalid direction.'];
}
return move_menu_item($itemId, $direction);
}
function handle_delete_item(array $post): array
{
$itemId = (int) ($post['item_id'] ?? 0);
@@ -93,12 +106,25 @@ function handle_save_category(array $post): array
$savedId = save_category([
'name' => $name,
'description' => post_str($post, 'description'),
'sort_order' => (int) ($post['sort_order'] ?? 0),
], $catId);
return ['success' => true, 'category' => get_category_by_id($savedId), 'is_new' => $catId === null];
}
function handle_move_category(array $post): array
{
$catId = (int) ($post['category_id'] ?? 0);
$direction = post_str($post, 'direction');
if ($catId <= 0 || !get_category_by_id($catId)) {
return ['success' => false, 'error' => 'Category not found.'];
}
if (!in_array($direction, ['up', 'down'], true)) {
return ['success' => false, 'error' => 'Invalid direction.'];
}
return move_category($catId, $direction);
}
function handle_delete_category(array $post): array
{
$catId = (int) ($post['category_id'] ?? 0);
@@ -115,8 +141,10 @@ function handle_menu_action(string $action, array $post): array
return match ($action) {
'save_item' => handle_save_item($post),
'toggle_item' => handle_toggle_item($post),
'move_item' => handle_move_item($post),
'delete_item' => handle_delete_item($post),
'save_category' => handle_save_category($post),
'move_category' => handle_move_category($post),
'delete_category' => handle_delete_category($post),
default => ['success' => false, 'error' => 'Unknown action'],
};
@@ -196,7 +224,8 @@ $menuGrouped = get_full_menu(false);
</div>
</div>
<?php else: ?>
<?php foreach ($menuGrouped as $category): ?>
<?php $catCount = count($menuGrouped); ?>
<?php foreach ($menuGrouped as $catIndex => $category): ?>
<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>
@@ -206,11 +235,12 @@ $menuGrouped = get_full_menu(false);
<p class="muted cat-desc-text"><?= htmlspecialchars($category['description'] ?? '') ?></p>
</div>
<div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-icon btn-move-cat" data-direction="up" data-id="<?= (int) $category['id'] ?>" aria-label="Move <?= htmlspecialchars($category['name']) ?> category up" <?= $catIndex === 0 ? 'disabled' : '' ?>>↑</button>
<button type="button" class="btn btn-outline btn-sm btn-icon btn-move-cat" data-direction="down" data-id="<?= (int) $category['id'] ?>" aria-label="Move <?= htmlspecialchars($category['name']) ?> category down" <?= $catIndex === $catCount - 1 ? 'disabled' : '' ?>>↓</button>
<button type="button" class="btn btn-outline btn-sm btn-edit-cat"
data-id="<?= (int) $category['id'] ?>"
data-name="<?= htmlspecialchars($category['name']) ?>"
data-desc="<?= htmlspecialchars($category['description'] ?? '') ?>"
data-sort="<?= (int) $category['sort_order'] ?>">
data-desc="<?= htmlspecialchars($category['description'] ?? '') ?>">
Edit Category
</button>
<button type="button" class="btn btn-danger btn-sm btn-delete-cat" data-id="<?= (int) $category['id'] ?>">
@@ -227,46 +257,45 @@ $menuGrouped = get_full_menu(false);
<th>Item</th>
<th>Price</th>
<th>Tag</th>
<th>Order</th>
<th>Actions</th>
</tr>
</thead>
<tbody class="items-tbody">
<?php if (empty($category['items'])): ?>
<tr class="no-items-row">
<td colspan="6" class="muted">No items in this category yet.</td>
<td colspan="5" class="muted">No items in this category yet.</td>
</tr>
<?php else: ?>
<?php foreach ($category['items'] as $item): ?>
<?php $itemCount = count($category['items']); ?>
<?php foreach ($category['items'] as $itemIndex => $item): ?>
<tr id="item-row-<?= (int) $item['id'] ?>" data-item-id="<?= (int) $item['id'] ?>" data-item='<?= htmlspecialchars(json_encode($item), ENT_QUOTES, 'UTF-8') ?>'>
<td>
<td data-label="Status">
<?php if ($item['is_available']): ?>
<span class="status-badge active">● Available</span>
<?php else: ?>
<span class="status-badge inactive">○ Sold Out / Hidden</span>
<?php endif; ?>
</td>
<td>
<td data-label="Item">
<strong class="item-name-cell"><?= htmlspecialchars($item['name']) ?></strong>
<div class="muted item-desc-cell">
<?= htmlspecialchars($item['description'] ?? '') ?>
</div>
</td>
<td class="font-mono item-price-cell">
<td class="font-mono item-price-cell" data-label="Price">
<?= htmlspecialchars($item['price']) ?>
</td>
<td class="item-badge-cell">
<td class="item-badge-cell" data-label="Tag">
<?php if (!empty($item['badge'])): ?>
<span class="eyebrow"><?= htmlspecialchars($item['badge']) ?></span>
<?php else: ?>
<span class="muted">—</span>
<?php endif; ?>
</td>
<td class="font-mono item-sort-cell">
<?= (int) $item['sort_order'] ?>
</td>
<td>
<td data-label="Actions">
<div class="admin-table-actions">
<button type="button" class="btn btn-outline btn-sm btn-icon btn-move-item" data-direction="up" aria-label="Move <?= htmlspecialchars($item['name']) ?> up" <?= $itemIndex === 0 ? 'disabled' : '' ?>>↑</button>
<button type="button" class="btn btn-outline btn-sm btn-icon btn-move-item" data-direction="down" aria-label="Move <?= htmlspecialchars($item['name']) ?> down" <?= $itemIndex === $itemCount - 1 ? 'disabled' : '' ?>>↓</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'] ?>">
<?= $item['is_available'] ? 'Mark Sold Out' : 'Mark Available' ?>
@@ -337,11 +366,6 @@ $menuGrouped = get_full_menu(false);
<label for="item-field-desc">Description</label>
<textarea id="item-field-desc" name="description" class="form-control" placeholder="Ingredients, preparation, flavor notes..."></textarea>
</div>
<div class="form-group">
<label for="item-field-sort">Sort Order</label>
<input type="number" id="item-field-sort" name="sort_order" class="form-control" value="0">
</div>
</div>
<div class="form-actions">
@@ -374,11 +398,6 @@ $menuGrouped = get_full_menu(false);
<label for="cat-field-desc">Description / Subtitle (Optional)</label>
<input type="text" id="cat-field-desc" name="description" class="form-control" placeholder="e.g. Small bites and shareable plates.">
</div>
<div class="form-group">
<label for="cat-field-sort">Sort Order</label>
<input type="number" id="cat-field-sort" name="sort_order" class="form-control" value="0">
</div>
</div>
<div class="form-actions">