2024-08-16 10:30:14 +02:00
|
|
|
import React, { useRef, useState, Dispatch, SetStateAction } from 'react';
|
2024-07-29 07:45:59 -07:00
|
|
|
import { TConversationTag, TConversation } from 'librechat-data-provider';
|
2024-07-29 19:25:36 -04:00
|
|
|
import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
|
2024-08-16 10:30:14 +02:00
|
|
|
import { OGDialog, OGDialogClose } from '~/components/ui/';
|
2024-07-29 07:45:59 -07:00
|
|
|
import BookmarkForm from './BookmarkForm';
|
|
|
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
|
import { Spinner } from '../svg';
|
|
|
|
|
|
|
|
|
|
type BookmarkEditDialogProps = {
|
|
|
|
|
bookmark?: TConversationTag;
|
|
|
|
|
conversation?: TConversation;
|
|
|
|
|
tags?: string[];
|
|
|
|
|
setTags?: (tags: string[]) => void;
|
2024-08-16 10:30:14 +02:00
|
|
|
open: boolean;
|
|
|
|
|
setOpen: Dispatch<SetStateAction<boolean>>;
|
2024-07-29 07:45:59 -07:00
|
|
|
};
|
2024-08-16 10:30:14 +02:00
|
|
|
|
2024-07-29 07:45:59 -07:00
|
|
|
const BookmarkEditDialog = ({
|
|
|
|
|
bookmark,
|
|
|
|
|
conversation,
|
|
|
|
|
tags,
|
|
|
|
|
setTags,
|
2024-08-16 10:30:14 +02:00
|
|
|
open,
|
|
|
|
|
setOpen,
|
2024-07-29 07:45:59 -07:00
|
|
|
}: BookmarkEditDialogProps) => {
|
|
|
|
|
const localize = useLocalize();
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const formRef = useRef<HTMLFormElement>(null);
|
|
|
|
|
|
|
|
|
|
const handleSubmitForm = () => {
|
|
|
|
|
if (formRef.current) {
|
|
|
|
|
formRef.current.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-07-29 19:25:36 -04:00
|
|
|
<OGDialog open={open} onOpenChange={setOpen}>
|
|
|
|
|
<OGDialogTemplate
|
2024-07-29 07:45:59 -07:00
|
|
|
title="Bookmark"
|
|
|
|
|
showCloseButton={false}
|
|
|
|
|
main={
|
|
|
|
|
<BookmarkForm
|
|
|
|
|
conversation={conversation}
|
|
|
|
|
onOpenChange={setOpen}
|
|
|
|
|
setIsLoading={setIsLoading}
|
|
|
|
|
bookmark={bookmark}
|
|
|
|
|
formRef={formRef}
|
|
|
|
|
setTags={setTags}
|
|
|
|
|
tags={tags}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
buttons={
|
2024-07-29 19:25:36 -04:00
|
|
|
<OGDialogClose asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
2024-07-29 07:45:59 -07:00
|
|
|
disabled={isLoading}
|
|
|
|
|
onClick={handleSubmitForm}
|
2024-07-29 19:25:36 -04:00
|
|
|
className="btn rounded bg-green-500 font-bold text-white transition-all hover:bg-green-600"
|
2024-07-29 07:45:59 -07:00
|
|
|
>
|
|
|
|
|
{isLoading ? <Spinner /> : localize('com_ui_save')}
|
2024-07-29 19:25:36 -04:00
|
|
|
</button>
|
|
|
|
|
</OGDialogClose>
|
2024-07-29 07:45:59 -07:00
|
|
|
}
|
|
|
|
|
/>
|
2024-07-29 19:25:36 -04:00
|
|
|
</OGDialog>
|
2024-07-29 07:45:59 -07:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BookmarkEditDialog;
|