A longer swipe left on an item (past the edit threshold) opens a dialog with the user's other lists; picking one moves the item there while the user stays on the current list. On desktop, right-click now opens a context menu with "Editar" and "Mover a otra lista…". The API gets POST /api/lists/:listId/items/:itemId/move, which requires membership in both lists and publishes item.removed on the source list and item.created on the target, so other members see the change live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import type { ListItem } from '@superlist/shared'
|
|
import { ChevronDownIcon } from 'lucide-react'
|
|
|
|
import { Card } from '@/components/ui/card'
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
|
|
import type { useUpdateItem } from '@/hooks/use-items'
|
|
|
|
import { ItemRow, type ItemRowProps } from './item-row'
|
|
|
|
type BoughtItemListProps = {
|
|
items: ListItem[]
|
|
updateItem: ReturnType<typeof useUpdateItem>
|
|
savingIds: string[]
|
|
/** The editing state of each row, owned by the parent so only one row edits at a time. */
|
|
editingProps: (itemId: string) => Pick<ItemRowProps, 'editing' | 'onEditingChange'>
|
|
onMove: (item: ListItem) => void
|
|
}
|
|
|
|
/**
|
|
* Collapsible "Comprados" card below the pending items. Expanded by default so
|
|
* marking an item visibly moves it down; the user can fold it. Tapping an item
|
|
* here un-buys it and it returns to the pending list.
|
|
*/
|
|
export function BoughtItemList({
|
|
items,
|
|
updateItem,
|
|
savingIds,
|
|
editingProps,
|
|
onMove,
|
|
}: BoughtItemListProps) {
|
|
return (
|
|
<Collapsible defaultOpen asChild>
|
|
<Card className="gap-0 py-0">
|
|
<CollapsibleTrigger className="group bg-muted text-muted-foreground hover:text-foreground flex w-full items-center gap-3 px-4 py-3 text-left transition-colors">
|
|
<ChevronDownIcon className="size-5 transition-transform group-data-[state=closed]:-rotate-90" />
|
|
<span className="text-base">Comprados · {items.length}</span>
|
|
</CollapsibleTrigger>
|
|
<CollapsibleContent>
|
|
<ul className="divide-y">
|
|
{items.map((item) => (
|
|
<ItemRow
|
|
key={item.id}
|
|
item={item}
|
|
updateItem={updateItem}
|
|
isSaving={savingIds.includes(item.id)}
|
|
{...editingProps(item.id)}
|
|
onMove={() => onMove(item)}
|
|
/>
|
|
))}
|
|
</ul>
|
|
</CollapsibleContent>
|
|
</Card>
|
|
</Collapsible>
|
|
)
|
|
}
|