2024-08-16 10:30:14 +02:00
|
|
|
import { useState } from 'react';
|
2024-07-29 07:45:59 -07:00
|
|
|
import type { FC } from 'react';
|
|
|
|
|
import type { TConversationTag } from 'librechat-data-provider';
|
2024-12-29 23:31:41 +01:00
|
|
|
import { TooltipAnchor, OGDialogTrigger } from '~/components/ui';
|
2024-07-29 07:45:59 -07:00
|
|
|
import BookmarkEditDialog from './BookmarkEditDialog';
|
|
|
|
|
import { EditIcon } from '~/components/svg';
|
|
|
|
|
import { useLocalize } from '~/hooks';
|
2024-07-29 19:25:36 -04:00
|
|
|
|
|
|
|
|
const EditBookmarkButton: FC<{
|
|
|
|
|
bookmark: TConversationTag;
|
|
|
|
|
tabIndex?: number;
|
|
|
|
|
onFocus?: () => void;
|
|
|
|
|
onBlur?: () => void;
|
|
|
|
|
}> = ({ bookmark, tabIndex = 0, onFocus, onBlur }) => {
|
2024-07-29 07:45:59 -07:00
|
|
|
const localize = useLocalize();
|
2024-08-16 10:30:14 +02:00
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
2024-09-13 08:59:09 -04:00
|
|
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
2024-12-29 23:31:41 +01:00
|
|
|
if (event.key === 'Enter' || event.key === ' ') {
|
2024-09-13 08:59:09 -04:00
|
|
|
setOpen(!open);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-29 07:45:59 -07:00
|
|
|
return (
|
2024-12-29 23:31:41 +01:00
|
|
|
<BookmarkEditDialog
|
|
|
|
|
context="EditBookmarkButton"
|
|
|
|
|
bookmark={bookmark}
|
|
|
|
|
open={open}
|
|
|
|
|
setOpen={setOpen}
|
|
|
|
|
>
|
|
|
|
|
<OGDialogTrigger asChild>
|
|
|
|
|
<TooltipAnchor
|
|
|
|
|
role="button"
|
|
|
|
|
aria-label={localize('com_ui_bookmarks_edit')}
|
|
|
|
|
description={localize('com_ui_edit')}
|
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
|
onFocus={onFocus}
|
|
|
|
|
onBlur={onBlur}
|
|
|
|
|
onClick={() => setOpen(!open)}
|
|
|
|
|
className="flex size-7 items-center justify-center rounded-lg transition-colors duration-200 hover:bg-surface-hover"
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
>
|
|
|
|
|
<EditIcon />
|
|
|
|
|
</TooltipAnchor>
|
|
|
|
|
</OGDialogTrigger>
|
|
|
|
|
</BookmarkEditDialog>
|
2024-07-29 07:45:59 -07:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default EditBookmarkButton;
|