chore: added ai generation inside block in pages (#732)

This commit is contained in:
Kunal Vishwakarma 2023-04-10 12:33:12 +05:30 committed by GitHub
parent 0caadd0f7a
commit 33ea1cb9d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -3,6 +3,8 @@ import dynamic from "next/dynamic";
import { mutate } from "swr";
import { SparklesIcon } from "@heroicons/react/24/outline";
// react-hook-form
import { Controller, useForm } from "react-hook-form";
// services
@ -23,6 +25,9 @@ type Props = {
data?: IPageBlock;
setIsSyncing?: React.Dispatch<React.SetStateAction<boolean>>;
focus?: keyof IPageBlock;
handelAutoGenerateDescription?: () => Promise<void>;
iAmFeelingLucky?: boolean;
setGptAssistantModal: () => void;
};
const defaultValues = {
@ -44,6 +49,9 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
data,
setIsSyncing,
focus,
handelAutoGenerateDescription,
setGptAssistantModal,
iAmFeelingLucky,
}) => {
const router = useRouter();
const { workspaceSlug, projectId, pageId } = router.query;
@ -185,6 +193,7 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
onJSONChange={(jsonValue) => setValue("description", jsonValue)}
onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)}
placeholder="Description"
aria-hidden
customClassName="text-sm"
noBorder
borderOnFocus={false}
@ -193,6 +202,37 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
/>
</div>
<div className="flex justify-end items-center gap-2">
{ data &&
<>
{console.log(handelAutoGenerateDescription, setGptAssistantModal, iAmFeelingLucky)}
<button
type="button"
className={`flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-gray-100 ${iAmFeelingLucky ? "cursor-wait bg-gray-100" : ""
}`}
onClick={handelAutoGenerateDescription}
disabled={iAmFeelingLucky}
>
{iAmFeelingLucky ? (
"Generating response..."
) : (
<>
<SparklesIcon className="h-4 w-4" />I{"'"}m feeling lucky
</>
)}
</button>
<button
type="button"
className="flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-gray-100"
onClick={() => {
handleClose();
setGptAssistantModal();
}}
>
<SparklesIcon className="h-4 w-4" />
AI
</button>
</>
}
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
<PrimaryButton type="submit" disabled={watch("name") === ""} loading={isSubmitting}>
{data

View File

@ -303,6 +303,9 @@ export const SinglePageBlock: React.FC<Props> = ({
{...provided.dragHandleProps}
>
<CreateUpdateBlockInline
handelAutoGenerateDescription={handelAutoGenerateDescription}
setGptAssistantModal={()=>setGptAssistantModal((prev)=>!prev)}
iAmFeelingLucky={iAmFeelingLucky}
handleClose={() => setCreateBlockForm(false)}
data={block}
setIsSyncing={setIsSyncing}

View File

@ -486,6 +486,7 @@ const SinglePage: NextPage = () => {
<CreateUpdateBlockInline
handleClose={() => setCreateBlockForm(false)}
focus="name"
setGptAssistantModal={()=>{}}
/>
</div>
)}