From a8fbb8dff700b78f5011c4b5805b058e1a89125e Mon Sep 17 00:00:00 2001 From: Jarrod Servilla Date: Sun, 25 Oct 2026 23:36:53 -0700 Subject: [PATCH] feat(deck): move card modal actions into header ellipsis menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The owner-only actions panel at the bottom of the card detail modal took vertical space and pushed card content around. Actions now live behind a "Card actions" (⋮) button beside the modal's close button. - Extract the row menu's dropdown body into a shared CardActionsMenuContent so the decklist row menu and the modal render the same tabs, items and keyboard shortcuts. Remove from deck and the qty/zone/category summary ride along in the modal's menu. - Arrow keys pressed inside an open menu no longer page the modal. - Menu rows get a 36px min height below md for touch. - bulk-action-bar imports orderZoneOptions from its source module. Tests: modal tests drive actions through the menu and cover owner vs non-owner visibility, Escape closing only the menu, zone moves, and arrow keys inside the menu. Closes #102 Claude-Session: https://claude.ai/code/session_01EkdpKxvDaBokbtmJKqXex3 --- app/_components/builder/bulk-action-bar.tsx | 2 +- app/_components/builder/card-actions-menu.tsx | 378 ++++++++++++++++++ .../builder/card-actions-panel.tsx | 6 +- .../builder/deck-card-detail-actions.test.tsx | 133 ++++-- .../builder/deck-card-detail-actions.tsx | 90 +++-- app/_components/builder/move-card-menu.tsx | 306 +------------- app/_components/deck/deck-preview-pane.tsx | 8 +- 7 files changed, 568 insertions(+), 355 deletions(-) create mode 100644 app/_components/builder/card-actions-menu.tsx diff --git a/app/_components/builder/bulk-action-bar.tsx b/app/_components/builder/bulk-action-bar.tsx index 19f7b41..e46f2d3 100644 --- a/app/_components/builder/bulk-action-bar.tsx +++ b/app/_components/builder/bulk-action-bar.tsx @@ -15,7 +15,7 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { useBulkSelection } from "@/app/_components/builder/bulk-selection"; -import { orderZoneOptions } from "@/app/_components/builder/move-card-menu"; +import { orderZoneOptions } from "@/app/_components/builder/card-actions-panel"; import { applyBulkCardAction } from "@/app/_actions/deck/bulk-actions"; import { planBulkCardAction, diff --git a/app/_components/builder/card-actions-menu.tsx b/app/_components/builder/card-actions-menu.tsx new file mode 100644 index 0000000..77962a0 --- /dev/null +++ b/app/_components/builder/card-actions-menu.tsx @@ -0,0 +1,378 @@ +"use client"; + +import { useState, type ReactNode } from "react"; +import { Check, Layers, Minus, Plus, Star } from "lucide-react"; +import { + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuShortcut, +} from "@/components/ui/dropdown-menu"; +import { useMenuShortcuts } from "@/app/_components/hotkeys/use-menu-shortcuts"; +import { + cardActionsTabs, + orderZoneOptions, + type CardActionItem, + type CardActionsTab, + type DeckCardMutations, +} from "@/app/_components/builder/card-actions-panel"; +import { cn, toTitleCase } from "@/lib/utils"; +import type { Zone } from "@/lib/generated/prisma/client"; + +interface CardActionsMenuContentProps { + currentZone: Zone; + commanderSet: boolean; + /** Ordered category memberships; `[0]` is the primary. */ + currentCategories: string[]; + subcategories: string[]; + quantity: number; + onQuantityChange: (next: number) => void; + mutations: Pick< + DeckCardMutations, + "moveToZone" | "toggleCategory" | "promoteCategory" | "clearCategories" + >; + onChangePrinting?: (() => void) | undefined; + inventoryActions: CardActionItem[]; + onClose: () => void; + header?: ReactNode; + extraActions?: ReactNode; +} + +export function CardActionsMenuContent({ + currentZone, + commanderSet, + currentCategories, + subcategories, + quantity, + onQuantityChange, + mutations, + onChangePrinting, + inventoryActions, + onClose, + header, + extraActions, +}: CardActionsMenuContentProps) { + const [tab, setTab] = useState("actions"); + + const zoneOptions = orderZoneOptions(commanderSet); + const tabs = cardActionsTabs(currentZone, subcategories); + const showCategoryTab = tabs.some((t) => t.value === "category"); + const activeTab: CardActionsTab = + tab === "category" && !showCategoryTab ? "actions" : tab; + + const isMainboardUncategorized = + currentZone === "MAINBOARD" && currentCategories.length === 0; + const onMenuKeyDown = useCardActionShortcuts({ + currentZone, + zoneOptions, + subcategories, + quantity, + onQuantityChange, + mutations, + onChangePrinting, + isMainboardUncategorized, + onClose, + }); + + return ( + + {header} +
+ {tabs.map(({ value, label }) => { + const isActive = activeTab === value; + return ( + + ); + })} +
+ + + {activeTab === "actions" && ( + + onQuantityChange(quantity + 1)} + className="gap-2" + > + + Add one + + + + onQuantityChange(quantity - 1)} + className="gap-2" + > + + Remove one + − + + {onChangePrinting && ( + onChangePrinting()} + className="gap-2" + > + + Change printing + P + + )} + {inventoryActions.length > 0 && ( + <> + + {inventoryActions.map((action) => ( + + {action.icon} + {action.label} + + ))} + + )} + {extraActions} + + )} + + {activeTab === "zone" && ( + + {zoneOptions.map(({ value, label, key }) => { + const isCurrent = value === currentZone; + return ( + mutations.moveToZone(value)} + className="gap-2" + > + {isCurrent && ( + + )} + {label} + {key.toUpperCase()} + + ); + })} + + )} + + {activeTab === "category" && showCategoryTab && ( + + )} +
+ ); +} + +type CardActionsMutations = CardActionsMenuContentProps["mutations"]; + +function useCardActionShortcuts({ + currentZone, + zoneOptions, + subcategories, + quantity, + onQuantityChange, + mutations: { moveToZone, toggleCategory, promoteCategory, clearCategories }, + onChangePrinting, + isMainboardUncategorized, + onClose, +}: Pick< + CardActionsMenuContentProps, + | "currentZone" + | "subcategories" + | "quantity" + | "onQuantityChange" + | "mutations" + | "onChangePrinting" + | "onClose" +> & { + zoneOptions: ReturnType; + isMainboardUncategorized: boolean; +}) { + return useMenuShortcuts([ + { + key: "+", + action: () => { + onQuantityChange(quantity + 1); + onClose(); + }, + }, + { + key: "=", + action: () => { + onQuantityChange(quantity + 1); + onClose(); + }, + }, + { + key: "-", + disabled: quantity <= 1, + action: () => { + onQuantityChange(quantity - 1); + onClose(); + }, + }, + { + key: "p", + disabled: !onChangePrinting, + action: () => { + onChangePrinting?.(); + onClose(); + }, + }, + ...zoneOptions.map(({ value, key }) => ({ + key, + disabled: value === currentZone, + action: () => { + moveToZone(value); + onClose(); + }, + })), + { + key: "0", + disabled: isMainboardUncategorized, + action: () => { + clearCategories(); + }, + }, + // Shift+digit promotes a membership to primary; listed before the plain + // digit toggles so shifted presses can't fall through to them. + ...subcategories.slice(0, 9).map((name, idx) => ({ + key: String(idx + 1), + shift: true, + action: () => { + promoteCategory(name); + }, + })), + // Number keys toggle membership without closing, so several categories + // can be assigned in one menu visit. + ...subcategories.slice(0, 9).map((name, idx) => ({ + key: String(idx + 1), + action: () => { + toggleCategory(name); + }, + })), + ]); +} + +function CategoryGroup({ + currentZone, + currentCategories, + subcategories, + mutations, +}: { + currentZone: Zone; + currentCategories: string[]; + subcategories: string[]; + mutations: CardActionsMutations; +}) { + const isMainboardUncategorized = + currentZone === "MAINBOARD" && currentCategories.length === 0; + return ( + + mutations.clearCategories()} + className="gap-2" + > + {isMainboardUncategorized && ( + + )} + + Uncategorized + + 0 + + {subcategories.map((name, idx) => { + const isMember = + currentZone === "MAINBOARD" && currentCategories.includes(name); + const isPrimary = + currentZone === "MAINBOARD" && currentCategories[0] === name; + const shortcut = idx < 9 ? String(idx + 1) : null; + return ( + mutations.toggleCategory(name)} + aria-label={ + isMember && !isPrimary + ? `${toTitleCase(name)} — Enter toggles membership, Shift+${shortcut ?? ""} makes it primary` + : undefined + } + {...(shortcut && { + "aria-keyshortcuts": + isMember && !isPrimary + ? `${shortcut} Shift+${shortcut}` + : shortcut, + })} + className="gap-2" + > + {isMember && ( + + )} + + {toTitleCase(name)} + + {isPrimary ? ( + + ) : isMember ? ( + // Not a nested - + + + setPrintingPickerOpen(true)} + inventoryActions={inventoryActions} + onClose={() => setMenuOpen(false)} + header={ +

+ {summary} +

+ } + extraActions={ + <> + + + + Remove from deck + + + } + /> + } /> - + ); } diff --git a/app/_components/builder/move-card-menu.tsx b/app/_components/builder/move-card-menu.tsx index e88684e..fe61a36 100644 --- a/app/_components/builder/move-card-menu.tsx +++ b/app/_components/builder/move-card-menu.tsx @@ -1,28 +1,20 @@ "use client"; import { useState } from "react"; -import { MoreVertical, Check, Layers, Minus, Plus, Star } from "lucide-react"; +import { MoreVertical } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, - DropdownMenuContent, - DropdownMenuGroup, - DropdownMenuItem, - DropdownMenuSeparator, - DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import BottomSheet from "@/app/_components/bottom-sheet"; -import { useMenuShortcuts } from "@/app/_components/hotkeys/use-menu-shortcuts"; import { useInventoryActions } from "@/app/_components/builder/inventory-actions"; import { CardActionsPanel, - cardActionsTabs, - orderZoneOptions, useDeckCardMutations, - type CardActionsTab, } from "@/app/_components/builder/card-actions-panel"; -import { cn, toTitleCase } from "@/lib/utils"; +import { CardActionsMenuContent } from "@/app/_components/builder/card-actions-menu"; +import { cn } from "@/lib/utils"; import type { ZoneAction } from "@/lib/deck/zone-view"; import type { OwnershipState } from "@/lib/inventory/state"; import type { Zone } from "@/lib/generated/prisma/client"; @@ -69,7 +61,6 @@ export function MoveCardMenu({ }: MoveCardMenuProps) { const [sheetOpen, setSheetOpen] = useState(false); const [desktopOpenInternal, setDesktopOpenInternal] = useState(false); - const [tab, setTab] = useState("actions"); const desktopOpen = open ?? desktopOpenInternal; const setDesktopOpen = (next: boolean) => { @@ -85,13 +76,7 @@ export function MoveCardMenu({ subcategories, dispatch, }); - const { - isPending, - moveToZone: handleZoneMove, - toggleCategory, - promoteCategory, - clearCategories, - } = mutations; + const { isPending } = mutations; const inventoryActions = useInventoryActions({ ...(inventory ?? { @@ -103,18 +88,6 @@ export function MoveCardMenu({ sourceDeckId: deckId, }); - const zoneOptions = orderZoneOptions(commanderSet); - - const desktopTabs = cardActionsTabs(currentZone, subcategories); - const showCategoryTab = desktopTabs.some((t) => t.value === "category"); - const activeTab: CardActionsTab = - tab === "category" && !showCategoryTab ? "actions" : tab; - - function openDesktop(next: boolean) { - if (next) setTab("actions"); - setDesktopOpen(next); - } - const triggerButton = ( - ); - })} - - - - {activeTab === "actions" && ( - - onQuantityChange(quantity + 1)} - className="gap-2" - > - - Add one - + - - onQuantityChange(quantity - 1)} - className="gap-2" - > - - Remove one - − - - {onChangePrinting && ( - onChangePrinting()} - className="gap-2" - > - - Change printing - P - - )} - {inventoryActions.length > 0 && ( - <> - - {inventoryActions.map((action) => ( - - {action.icon} - {action.label} - - ))} - - )} - - )} - - {activeTab === "zone" && ( - - {zoneOptions.map(({ value, label, key }) => { - const isCurrent = value === currentZone; - return ( - handleZoneMove(value)} - className="gap-2" - > - {isCurrent && ( - - )} - {label} - - {key.toUpperCase()} - - - ); - })} - - )} - - {activeTab === "category" && showCategoryTab && ( - - clearCategories()} - className="gap-2" - > - {isMainboardUncategorized && ( - - )} - - Uncategorized - - 0 - - {subcategories.map((name, idx) => { - const isMember = - currentZone === "MAINBOARD" && - currentCategories.includes(name); - const isPrimary = - currentZone === "MAINBOARD" && - currentCategories[0] === name; - const shortcut = idx < 9 ? String(idx + 1) : null; - return ( - toggleCategory(name)} - aria-label={ - isMember && !isPrimary - ? `${toTitleCase(name)} — Enter toggles membership, Shift+${shortcut ?? ""} makes it primary` - : undefined - } - {...(shortcut && { - "aria-keyshortcuts": isMember && !isPrimary - ? `${shortcut} Shift+${shortcut}` - : shortcut, - })} - className="gap-2" - > - {isMember && ( - - )} - - {toTitleCase(name)} - - {isPrimary ? ( - - ) : isMember ? ( - // Not a nested