Revert "refactor: shopping list item row — direct buttons instead of "..." overflow menu"
This reverts commit 0022d807d0.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import { useMemo, useRef, useState } from "react";
|
import { useMemo, useRef, useState } from "react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Check, Package, Loader2, GripVertical, Trash2, Search, Sparkles } from "lucide-react";
|
import { Check, Package, Loader2, GripVertical, MoreVertical, Trash2, Search, Sparkles } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
@@ -14,7 +14,16 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuSub,
|
||||||
|
DropdownMenuSubContent,
|
||||||
|
DropdownMenuSubTrigger,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -615,12 +624,12 @@ type ItemRowProps = {
|
|||||||
function ItemRow({ item, readOnly, categoryOptions, categoryLabel, tShopping, onToggle, onChangeCategory, onDeleteRequest, dragHandle }: ItemRowProps) {
|
function ItemRow({ item, readOnly, categoryOptions, categoryLabel, tShopping, onToggle, onChangeCategory, onDeleteRequest, dragHandle }: ItemRowProps) {
|
||||||
const [newCategory, setNewCategory] = useState("");
|
const [newCategory, setNewCategory] = useState("");
|
||||||
return (
|
return (
|
||||||
<div className="w-full flex items-center gap-2 px-4 py-3 hover:bg-muted/30 transition-colors">
|
<div className="w-full flex items-center gap-3 px-4 py-3 hover:bg-muted/30 transition-colors">
|
||||||
{dragHandle}
|
{dragHandle}
|
||||||
<button
|
<button
|
||||||
onClick={() => onToggle(item)}
|
onClick={() => onToggle(item)}
|
||||||
disabled={readOnly}
|
disabled={readOnly}
|
||||||
className="flex flex-1 min-w-0 items-center gap-3 text-left disabled:cursor-default"
|
className="flex flex-1 items-center gap-3 text-left disabled:cursor-default"
|
||||||
>
|
>
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
"h-5 w-5 rounded border-2 flex items-center justify-center shrink-0 transition-colors",
|
"h-5 w-5 rounded border-2 flex items-center justify-center shrink-0 transition-colors",
|
||||||
@@ -628,7 +637,7 @@ function ItemRow({ item, readOnly, categoryOptions, categoryLabel, tShopping, on
|
|||||||
)}>
|
)}>
|
||||||
{item.checked && <Check className="h-3 w-3 text-primary-foreground" />}
|
{item.checked && <Check className="h-3 w-3 text-primary-foreground" />}
|
||||||
</div>
|
</div>
|
||||||
<span className={cn("flex-1 min-w-0 truncate text-sm", item.checked && "line-through text-muted-foreground")}>
|
<span className={cn("flex-1 text-sm", item.checked && "line-through text-muted-foreground")}>
|
||||||
{item.rawName}
|
{item.rawName}
|
||||||
</span>
|
</span>
|
||||||
{item.inPantry && (
|
{item.inPantry && (
|
||||||
@@ -643,21 +652,23 @@ function ItemRow({ item, readOnly, categoryOptions, categoryLabel, tShopping, on
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
{!readOnly && (
|
{!readOnly && (
|
||||||
<div className="flex items-center gap-1 shrink-0">
|
<DropdownMenu>
|
||||||
<Select
|
<DropdownMenuTrigger className="shrink-0 rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground">
|
||||||
value={item.aisle ?? OTHER_KEY}
|
<MoreVertical className="h-4 w-4" />
|
||||||
onValueChange={(v) => onChangeCategory(item, v === OTHER_KEY ? null : v)}
|
</DropdownMenuTrigger>
|
||||||
>
|
<DropdownMenuContent align="end">
|
||||||
<SelectTrigger className="h-7 max-w-28 border-none bg-transparent px-1.5 text-xs text-muted-foreground hover:bg-muted hover:text-foreground [&_svg]:size-3">
|
<DropdownMenuSub>
|
||||||
<SelectValue>
|
<DropdownMenuSubTrigger>{tShopping("changeCategory")}</DropdownMenuSubTrigger>
|
||||||
{(v: string) => <span className="truncate">{v === OTHER_KEY ? tShopping("aisleOther") : categoryLabel(v)}</span>}
|
<DropdownMenuSubContent className="w-56">
|
||||||
</SelectValue>
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent className="w-56">
|
|
||||||
{categoryOptions.map((category) => (
|
{categoryOptions.map((category) => (
|
||||||
<SelectItem key={category} value={category}>{categoryLabel(category)}</SelectItem>
|
<DropdownMenuItem key={category} onClick={() => onChangeCategory(item, category)}>
|
||||||
|
{categoryLabel(category)}
|
||||||
|
</DropdownMenuItem>
|
||||||
))}
|
))}
|
||||||
<SelectItem value={OTHER_KEY}>{tShopping("aisleOther")}</SelectItem>
|
<DropdownMenuItem onClick={() => onChangeCategory(item, null)}>
|
||||||
|
{tShopping("aisleOther")}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
<div className="flex items-center gap-1 p-1.5" onClick={(e) => e.stopPropagation()}>
|
<div className="flex items-center gap-1 p-1.5" onClick={(e) => e.stopPropagation()}>
|
||||||
<Input
|
<Input
|
||||||
value={newCategory}
|
value={newCategory}
|
||||||
@@ -681,25 +692,15 @@ function ItemRow({ item, readOnly, categoryOptions, categoryLabel, tShopping, on
|
|||||||
{tShopping("addCategory")}
|
{tShopping("addCategory")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</SelectContent>
|
</DropdownMenuSubContent>
|
||||||
</Select>
|
</DropdownMenuSub>
|
||||||
<TooltipProvider>
|
<DropdownMenuSeparator />
|
||||||
<Tooltip>
|
<DropdownMenuItem variant="destructive" onClick={() => onDeleteRequest(item)}>
|
||||||
<TooltipTrigger render={
|
<Trash2 className="h-4 w-4" />
|
||||||
<Button
|
{tShopping("deleteItem")}
|
||||||
variant="ghost"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuContent>
|
||||||
className="h-7 w-7 text-muted-foreground hover:text-destructive"
|
</DropdownMenu>
|
||||||
aria-label={tShopping("deleteItem")}
|
|
||||||
onClick={() => onDeleteRequest(item)}
|
|
||||||
>
|
|
||||||
<Trash2 className="h-3.5 w-3.5" />
|
|
||||||
</Button>
|
|
||||||
} />
|
|
||||||
<TooltipContent>{tShopping("deleteItem")}</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</TooltipProvider>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user