"use client" import * as React from "react" import { Checkbox } from "@/components/ui/checkbox" import { LinkIcon, Trash2Icon } from "lucide-react" import Link from "next/link" import Image from "next/image" import { useSortable } from "@dnd-kit/sortable" import { CSS } from "@dnd-kit/utilities" import { PersonalLink } from "@/lib/schema/personal-link" import { cn } from "@/lib/utils" import { LinkForm } from "./form/manage" import { Button } from "@/components/ui/button" import { ConfirmOptions } from "@omit/react-confirm-dialog" import { Badge } from "@/components/ui/badge" interface ListItemProps { confirm: (options: ConfirmOptions) => Promise personalLink: PersonalLink disabled?: boolean isEditing: boolean setEditId: (id: string | null) => void isDragging: boolean isFocused: boolean setFocusedId: (id: string | null) => void registerRef: (id: string, ref: HTMLLIElement | null) => void onDelete?: (personalLink: PersonalLink) => void } export const ListItem: React.FC = ({ confirm, isEditing, setEditId, personalLink, disabled = false, isDragging, isFocused, setFocusedId, registerRef, onDelete }) => { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: personalLink.id, disabled }) const formRef = React.useRef(null) const [showDeleteIcon, setShowDeleteIcon] = React.useState(false) const style = { transform: CSS.Transform.toString(transform), transition, pointerEvents: isDragging ? "none" : "auto" } React.useEffect(() => { if (isEditing) { formRef.current?.focus() } }, [isEditing]) const refCallback = React.useCallback( (node: HTMLLIElement | null) => { setNodeRef(node) registerRef(personalLink.id, node) }, [setNodeRef, registerRef, personalLink.id] ) const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault() setEditId(personalLink.id) } } const handleSuccess = () => { setEditId(null) } const handleCancel = () => { setEditId(null) } // const handleRowClick = () => { // console.log("Row clicked", personalLink.id) // setEditId(personalLink.id) // } const handleRowClick = () => { setShowDeleteIcon(!showDeleteIcon) } const handleDoubleClick = () => { setEditId(personalLink.id) } const handleDelete = async (e: React.MouseEvent, personalLink: PersonalLink) => { e.stopPropagation() const result = await confirm({ title: `Delete "${personalLink.title}"?`, description: "This action cannot be undone.", alertDialogTitle: { className: "text-base" }, customActions: (onConfirm, onCancel) => ( <> ) }) if (result) { onDelete?.(personalLink) } } if (isEditing) { return } return (
  • setFocusedId(personalLink.id)} onBlur={() => setFocusedId(null)} onKeyDown={handleKeyDown} className={cn("hover:bg-muted/50 relative flex h-14 cursor-default items-center outline-none xl:h-11", { "bg-muted/50": isFocused })} onClick={handleRowClick} onDoubleClick={handleDoubleClick} >
    e.stopPropagation()} onCheckedChange={() => { personalLink.completed = !personalLink.completed }} className="border-muted-foreground border" /> {personalLink.isLink && personalLink.meta && ( {personalLink.title} )}

    {personalLink.title}

    {personalLink.isLink && personalLink.meta && (
    )}
    Topic Name {showDeleteIcon && ( )}
  • ) }