import React, { useRef } from 'react'; import { useDrag, useDrop } from 'react-dnd'; import { GripVertical } from 'lucide-react'; import type { TConversationTag } from 'librechat-data-provider'; import { TooltipAnchor, useToastContext } from '@librechat/client'; import { useConversationTagMutation } from '~/data-provider'; import { NotificationSeverity } from '~/common'; import BookmarkCardActions from './BookmarkCardActions'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; interface BookmarkCardProps { bookmark: TConversationTag; position: number; moveRow: (dragIndex: number, hoverIndex: number) => void; } interface DragItem { index: number; id: string; type: string; } export default function BookmarkCard({ bookmark, position, moveRow }: BookmarkCardProps) { const ref = useRef(null); const localize = useLocalize(); const { showToast } = useToastContext(); const mutation = useConversationTagMutation({ context: 'BookmarkCard', tag: bookmark.tag, }); const handleDrop = (item: DragItem) => { mutation.mutate( { ...bookmark, position: item.index }, { onSuccess: () => { showToast({ message: localize('com_ui_bookmarks_update_success'), severity: NotificationSeverity.SUCCESS, }); }, onError: () => { showToast({ message: localize('com_ui_bookmarks_update_error'), severity: NotificationSeverity.ERROR, }); }, }, ); }; const [, drop] = useDrop({ accept: 'bookmark', drop: handleDrop, hover(item: DragItem) { if (!ref.current || item.index === position) { return; } moveRow(item.index, position); item.index = position; }, }); const [{ isDragging }, drag] = useDrag({ type: 'bookmark', item: { index: position }, collect: (monitor) => ({ isDragging: monitor.isDragging(), }), }); drag(drop(ref)); return (
{/* Drag handle */}
); }