diff --git a/apps/app/components/pages/create-update-block-inline.tsx b/apps/app/components/pages/create-update-block-inline.tsx index baf5accf8..dbbe54696 100644 --- a/apps/app/components/pages/create-update-block-inline.tsx +++ b/apps/app/components/pages/create-update-block-inline.tsx @@ -22,6 +22,7 @@ type Props = { handleClose: () => void; data?: IPageBlock; setIsSyncing?: React.Dispatch>; + focus?: keyof IPageBlock; }; const defaultValues = { @@ -38,7 +39,12 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor ), }); -export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, setIsSyncing }) => { +export const CreateUpdateBlockInline: React.FC = ({ + handleClose, + data, + setIsSyncing, + focus, +}) => { const router = useRouter(); const { workspaceSlug, projectId, pageId } = router.query; @@ -50,6 +56,7 @@ export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, se control, watch, setValue, + setFocus, reset, formState: { isSubmitting }, } = useForm({ @@ -57,9 +64,10 @@ export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, se }); const onClose = useCallback(() => { - handleClose(); + if (data) handleClose(); + reset(); - }, [handleClose, reset]); + }, [handleClose, reset, data]); const createPageBlock = async (formData: Partial) => { if (!workspaceSlug || !projectId || !pageId) return; @@ -126,6 +134,8 @@ export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, se }; useEffect(() => { + if (focus) setFocus(focus); + if (!data) return; reset({ @@ -134,7 +144,7 @@ export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, se description: data.description, description_html: data.description_html, }); - }, [reset, data]); + }, [reset, data, focus, setFocus]); useEffect(() => { window.addEventListener("keydown", (e: KeyboardEvent) => { @@ -156,9 +166,10 @@ export const CreateUpdateBlockInline: React.FC = ({ handleClose, data, se name="name" placeholder="Title" register={register} - required={true} className="min-h-10 block w-full resize-none overflow-hidden border-none bg-transparent py-1 text-base ring-0 -ml-2 focus:ring-gray-200" role="textbox" + autoComplete="off" + maxLength={255} />
= ({ handleClose, data, se />
- Cancel - + Cancel + {data ? isSubmitting ? "Updating..." diff --git a/apps/app/components/pages/single-page-block.tsx b/apps/app/components/pages/single-page-block.tsx index 7f01811db..4ab8e81ed 100644 --- a/apps/app/components/pages/single-page-block.tsx +++ b/apps/app/components/pages/single-page-block.tsx @@ -42,6 +42,7 @@ type Props = { block: IPageBlock; projectDetails: IProject | undefined; index: number; + handleNewBlock: () => void; }; const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { @@ -53,7 +54,12 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor ), }); -export const SinglePageBlock: React.FC = ({ block, projectDetails, index }) => { +export const SinglePageBlock: React.FC = ({ + block, + projectDetails, + index, + handleNewBlock, +}) => { const [isSyncing, setIsSyncing] = useState(false); const [createBlockForm, setCreateBlockForm] = useState(false); const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); @@ -65,7 +71,7 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails, index const { setToastAlert } = useToast(); - const { handleSubmit, watch, reset, setValue, control, register } = useForm({ + const { handleSubmit, watch, reset, setValue, register } = useForm({ defaultValues: { name: "", description: {}, @@ -273,12 +279,29 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails, index reset({ ...block }); }, [reset, block]); + useEffect(() => { + window.addEventListener("keydown", (e: KeyboardEvent) => { + if (e.key === "Enter" && !createBlockForm) handleNewBlock(); + }); + + return () => { + window.removeEventListener("keydown", (e: KeyboardEvent) => { + if (e.key === "Enter" && !createBlockForm) handleNewBlock(); + }); + }; + }, [handleNewBlock, createBlockForm]); + return ( - + {(provided, snapshot) => ( <> {createBlockForm ? ( -
+
setCreateBlockForm(false)} data={block} @@ -287,131 +310,110 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails, index
) : (
-
-
- -

setCreateBlockForm(true)}> - {block.name} -

-
-
- {block.issue && block.sync && ( -
- {isSyncing ? ( - - ) : ( - - )} - {isSyncing ? "Syncing..." : "Synced"} -
- )} - {block.issue && ( - - - - {projectDetails?.identifier}-{block.issue_detail?.sequence_id} - - - )} - +
+ {block.issue && block.sync && ( +
+ {isSyncing ? ( + ) : ( - <> - I{"'"}m feeling lucky - + )} - - - - } noBorder noChevron> - {block.issue ? ( - <> - - <>Turn sync {block.sync ? "off" : "on"} - - - Copy issue link - - - ) : ( - - Push into issues + {isSyncing ? "Syncing..." : "Synced"} +
+ )} + + + + } noBorder noChevron> + {block.issue ? ( + <> + + <>Turn sync {block.sync ? "off" : "on"} - )} - - Delete block + + Copy issue link + + + ) : ( + + Push into issues - -
+ )} + Delete block +
-
-
setCreateBlockForm(true)}> - ( - - )} - /> -
- setGptAssistantModal(false)} - inset="top-2 left-0" - content={block.description_stripped} - htmlContent={block.description_html} - onResponse={handleAiAssistance} - projectId={projectId as string} - /> +
+ {block.issue && ( + + + + {projectDetails?.identifier}-{block.issue_detail?.sequence_id} + + + )} +

setCreateBlockForm(true)} + > + {block.name} +

+ setGptAssistantModal(false)} + inset="top-8 left-0" + content={block.description_stripped} + htmlContent={block.description_html} + onResponse={handleAiAssistance} + projectId={projectId as string} + />
)} diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx index 35097094b..29cdede37 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { useRouter } from "next/router"; @@ -54,9 +54,10 @@ import { } from "constants/fetch-keys"; const SinglePage: NextPage = (props) => { - const [isAddingBlock, setIsAddingBlock] = useState(false); const [createBlockForm, setCreateBlockForm] = useState(false); + const scrollToRef = useRef(null); + const router = useRouter(); const { workspaceSlug, projectId, pageId } = router.query; @@ -238,6 +239,13 @@ const SinglePage: NextPage = (props) => { ); }; + const handleNewBlock = () => { + setCreateBlockForm(true); + scrollToRef.current?.scrollIntoView({ + behavior: "smooth", + }); + }; + const options = labels?.map((label) => ({ value: label.id, @@ -449,14 +457,15 @@ const SinglePage: NextPage = (props) => { {pageBlocks.length !== 0 && ( - {(provided, snapshot) => ( -
+ {(provided) => ( +
{pageBlocks.map((block, index) => ( ))} {provided.placeholder} @@ -469,20 +478,19 @@ const SinglePage: NextPage = (props) => { )} {createBlockForm && ( - setCreateBlockForm(false)} /> +
+ setCreateBlockForm(false)} + focus="name" + /> +
)} ) : ( diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx index 534409ec4..013f74a38 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/labels.tsx @@ -46,7 +46,7 @@ const LabelsSettings: NextPage = (props) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; - const scollToRef = useRef(null); + const scrollToRef = useRef(null); const { data: projectDetails } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, @@ -130,7 +130,7 @@ const LabelsSettings: NextPage = (props) => { setLabelForm={setLabelForm} isUpdating={isUpdating} labelToUpdate={labelToUpdate} - ref={scollToRef} + ref={scrollToRef} /> )} <> @@ -147,7 +147,7 @@ const LabelsSettings: NextPage = (props) => { addLabelToGroup={() => addLabelToGroup(label)} editLabel={(label) => { editLabel(label); - scollToRef.current?.scrollIntoView({ + scrollToRef.current?.scrollIntoView({ behavior: "smooth", }); }} @@ -163,7 +163,7 @@ const LabelsSettings: NextPage = (props) => { addLabelToGroup={addLabelToGroup} editLabel={(label) => { editLabel(label); - scollToRef.current?.scrollIntoView({ + scrollToRef.current?.scrollIntoView({ behavior: "smooth", }); }}