forked from github/plane
refactor: useEffect placement
This commit is contained in:
parent
aecb9d8619
commit
6d1a99846d
@ -1,5 +1,7 @@
|
|||||||
import { ChangeEvent, FC, useCallback, useEffect, useState } from "react";
|
import { ChangeEvent, FC, useCallback, useEffect, useState } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
import useReloadConfirmations from "hooks/use-reload-confirmation";
|
||||||
// packages
|
// packages
|
||||||
import { RichTextEditor } from "@plane/rich-text-editor";
|
import { RichTextEditor } from "@plane/rich-text-editor";
|
||||||
// components
|
// components
|
||||||
@ -12,7 +14,6 @@ import useEditorSuggestions from "hooks/use-editor-suggestions";
|
|||||||
import { IIssue } from "types";
|
import { IIssue } from "types";
|
||||||
// services
|
// services
|
||||||
import { FileService } from "services/file.service";
|
import { FileService } from "services/file.service";
|
||||||
import { useMobxStore } from "lib/mobx/store-provider";
|
|
||||||
|
|
||||||
const fileService = new FileService();
|
const fileService = new FileService();
|
||||||
|
|
||||||
@ -24,15 +25,14 @@ interface IPeekOverviewIssueDetails {
|
|||||||
issueUpdate: (issue: Partial<IIssue>) => void;
|
issueUpdate: (issue: Partial<IIssue>) => void;
|
||||||
issueReactionCreate: (reaction: string) => void;
|
issueReactionCreate: (reaction: string) => void;
|
||||||
issueReactionRemove: (reaction: string) => void;
|
issueReactionRemove: (reaction: string) => void;
|
||||||
setShowAlert: (value: boolean) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PeekOverviewIssueDetails: FC<IPeekOverviewIssueDetails> = (props) => {
|
export const PeekOverviewIssueDetails: FC<IPeekOverviewIssueDetails> = (props) => {
|
||||||
const { workspaceSlug, issue, issueReactions, user, issueUpdate, issueReactionCreate, issueReactionRemove,setShowAlert } = props;
|
const { workspaceSlug, issue, issueReactions, user, issueUpdate, issueReactionCreate, issueReactionRemove } = props;
|
||||||
// store
|
// store
|
||||||
const {
|
const {
|
||||||
user: userStore,
|
user: userStore,
|
||||||
projectIssues: { setIsSubmitting },
|
projectIssues: { isSubmitting, setIsSubmitting },
|
||||||
} = useMobxStore();
|
} = useMobxStore();
|
||||||
const { currentProjectRole } = userStore;
|
const { currentProjectRole } = userStore;
|
||||||
const isAllowed = [15, 20].includes(currentProjectRole || 0);
|
const isAllowed = [15, 20].includes(currentProjectRole || 0);
|
||||||
@ -41,6 +41,7 @@ export const PeekOverviewIssueDetails: FC<IPeekOverviewIssueDetails> = (props) =
|
|||||||
|
|
||||||
// hooks
|
// hooks
|
||||||
const editorSuggestions = useEditorSuggestions();
|
const editorSuggestions = useEditorSuggestions();
|
||||||
|
const { setShowAlert } = useReloadConfirmations();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -80,6 +81,17 @@ export const PeekOverviewIssueDetails: FC<IPeekOverviewIssueDetails> = (props) =
|
|||||||
handleSubmit(handleDescriptionFormSubmit)();
|
handleSubmit(handleDescriptionFormSubmit)();
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSubmitting === "submitted") {
|
||||||
|
setShowAlert(false);
|
||||||
|
setTimeout(async () => {
|
||||||
|
setIsSubmitting("saved");
|
||||||
|
}, 2000);
|
||||||
|
} else if (isSubmitting === "submitting") {
|
||||||
|
setShowAlert(true);
|
||||||
|
}
|
||||||
|
}, [isSubmitting, setShowAlert]);
|
||||||
|
|
||||||
// reset form values
|
// reset form values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!issue) return;
|
if (!issue) return;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { FC, ReactNode, useEffect, useState } from "react";
|
import { FC, ReactNode, useState } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
@ -143,17 +143,6 @@ export const IssueView: FC<IIssueView> = observer((props) => {
|
|||||||
|
|
||||||
const currentMode = peekOptions.find((m) => m.key === peekMode);
|
const currentMode = peekOptions.find((m) => m.key === peekMode);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSubmitting === "submitted") {
|
|
||||||
setShowAlert(false);
|
|
||||||
setTimeout(async () => {
|
|
||||||
setIsSubmitting("saved");
|
|
||||||
}, 2000);
|
|
||||||
} else if (isSubmitting === "submitting") {
|
|
||||||
setShowAlert(true);
|
|
||||||
}
|
|
||||||
}, [isSubmitting, setShowAlert]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{issue && !isArchived && (
|
{issue && !isArchived && (
|
||||||
@ -291,7 +280,6 @@ export const IssueView: FC<IIssueView> = observer((props) => {
|
|||||||
<div className="absolute top-0 left-0 h-full min-h-full w-full z-[9] flex items-center justify-center bg-custom-background-100 opacity-60" />
|
<div className="absolute top-0 left-0 h-full min-h-full w-full z-[9] flex items-center justify-center bg-custom-background-100 opacity-60" />
|
||||||
)}
|
)}
|
||||||
<PeekOverviewIssueDetails
|
<PeekOverviewIssueDetails
|
||||||
setShowAlert={(value) => setShowAlert(value)}
|
|
||||||
workspaceSlug={workspaceSlug}
|
workspaceSlug={workspaceSlug}
|
||||||
issue={issue}
|
issue={issue}
|
||||||
issueUpdate={issueUpdate}
|
issueUpdate={issueUpdate}
|
||||||
@ -326,7 +314,6 @@ export const IssueView: FC<IIssueView> = observer((props) => {
|
|||||||
<div className="relative w-full h-full space-y-6 p-4 py-5 overflow-auto">
|
<div className="relative w-full h-full space-y-6 p-4 py-5 overflow-auto">
|
||||||
<div className={isArchived ? "pointer-events-none" : ""}>
|
<div className={isArchived ? "pointer-events-none" : ""}>
|
||||||
<PeekOverviewIssueDetails
|
<PeekOverviewIssueDetails
|
||||||
setShowAlert={(value) => setShowAlert(value)}
|
|
||||||
workspaceSlug={workspaceSlug}
|
workspaceSlug={workspaceSlug}
|
||||||
issue={issue}
|
issue={issue}
|
||||||
issueReactions={issueReactions}
|
issueReactions={issueReactions}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
@ -8,6 +9,7 @@ import { useMobxStore } from "lib/mobx/store-provider";
|
|||||||
import { IssueService, IssueCommentService } from "services/issue";
|
import { IssueService, IssueCommentService } from "services/issue";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
|
import useReloadConfirmations from "hooks/use-reload-confirmation";
|
||||||
// components
|
// components
|
||||||
import {
|
import {
|
||||||
AddComment,
|
AddComment,
|
||||||
@ -31,7 +33,6 @@ type Props = {
|
|||||||
issueDetails: IIssue;
|
issueDetails: IIssue;
|
||||||
submitChanges: (formData: Partial<IIssue>) => Promise<void>;
|
submitChanges: (formData: Partial<IIssue>) => Promise<void>;
|
||||||
uneditable?: boolean;
|
uneditable?: boolean;
|
||||||
setShowAlert: (value: boolean) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// services
|
// services
|
||||||
@ -39,18 +40,20 @@ const issueService = new IssueService();
|
|||||||
const issueCommentService = new IssueCommentService();
|
const issueCommentService = new IssueCommentService();
|
||||||
|
|
||||||
export const IssueMainContent: React.FC<Props> = observer((props) => {
|
export const IssueMainContent: React.FC<Props> = observer((props) => {
|
||||||
const { issueDetails, submitChanges, uneditable = false, setShowAlert } = props;
|
const { issueDetails, submitChanges, uneditable = false } = props;
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, issueId } = router.query;
|
const { workspaceSlug, projectId, issueId } = router.query;
|
||||||
|
|
||||||
|
// hooks
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
const { setShowAlert } = useReloadConfirmations();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
user: userStore,
|
user: userStore,
|
||||||
project: projectStore,
|
project: projectStore,
|
||||||
projectState: { states },
|
projectState: { states },
|
||||||
projectIssues: { isSubmitting },
|
projectIssues: { isSubmitting, setIsSubmitting },
|
||||||
} = useMobxStore();
|
} = useMobxStore();
|
||||||
const user = userStore.currentUser ?? undefined;
|
const user = userStore.currentUser ?? undefined;
|
||||||
const userRole = userStore.currentProjectRole;
|
const userRole = userStore.currentProjectRole;
|
||||||
@ -109,6 +112,16 @@ export const IssueMainContent: React.FC<Props> = observer((props) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (isSubmitting === "submitted") {
|
||||||
|
setShowAlert(false);
|
||||||
|
setTimeout(async () => {
|
||||||
|
setIsSubmitting("saved");
|
||||||
|
}, 2000);
|
||||||
|
} else if (isSubmitting === "submitting") {
|
||||||
|
setShowAlert(true);
|
||||||
|
}
|
||||||
|
}, [isSubmitting, setShowAlert]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -139,17 +139,6 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = observer(() => {
|
|||||||
.finally(() => setIsRestoring(false));
|
.finally(() => setIsRestoring(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSubmitting === "submitted") {
|
|
||||||
setShowAlert(false);
|
|
||||||
setTimeout(async () => {
|
|
||||||
setIsSubmitting("saved");
|
|
||||||
}, 2000);
|
|
||||||
} else if (isSubmitting === "submitting") {
|
|
||||||
setShowAlert(true);
|
|
||||||
}
|
|
||||||
}, [isSubmitting, setShowAlert]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{issueDetails && projectId ? (
|
{issueDetails && projectId ? (
|
||||||
@ -173,12 +162,7 @@ const ArchivedIssueDetailsPage: NextPageWithLayout = observer(() => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="space-y-5 divide-y-2 divide-custom-border-200 opacity-60 pointer-events-none">
|
<div className="space-y-5 divide-y-2 divide-custom-border-200 opacity-60 pointer-events-none">
|
||||||
<IssueMainContent
|
<IssueMainContent issueDetails={issueDetails} submitChanges={submitChanges} uneditable />
|
||||||
setShowAlert={(value) => setShowAlert(value)}
|
|
||||||
issueDetails={issueDetails}
|
|
||||||
submitChanges={submitChanges}
|
|
||||||
uneditable
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 p-5 overflow-hidden">
|
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 p-5 overflow-hidden">
|
||||||
|
@ -11,8 +11,6 @@ import { AppLayout } from "layouts/app-layout";
|
|||||||
// components
|
// components
|
||||||
import { ProjectIssueDetailsHeader } from "components/headers";
|
import { ProjectIssueDetailsHeader } from "components/headers";
|
||||||
import { IssueDetailsSidebar, IssueMainContent } from "components/issues";
|
import { IssueDetailsSidebar, IssueMainContent } from "components/issues";
|
||||||
// hooks
|
|
||||||
import useReloadConfirmations from "hooks/use-reload-confirmation";
|
|
||||||
// ui
|
// ui
|
||||||
import { EmptyState } from "components/common";
|
import { EmptyState } from "components/common";
|
||||||
import { Loader } from "@plane/ui";
|
import { Loader } from "@plane/ui";
|
||||||
@ -50,9 +48,6 @@ const IssueDetailsPage: NextPageWithLayout = observer(() => {
|
|||||||
projectIssues: { isSubmitting, setIsSubmitting },
|
projectIssues: { isSubmitting, setIsSubmitting },
|
||||||
} = useMobxStore();
|
} = useMobxStore();
|
||||||
|
|
||||||
// hooks
|
|
||||||
const { setShowAlert } = useReloadConfirmations();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: issueDetails,
|
data: issueDetails,
|
||||||
mutate: mutateIssueDetails,
|
mutate: mutateIssueDetails,
|
||||||
@ -116,17 +111,6 @@ const IssueDetailsPage: NextPageWithLayout = observer(() => {
|
|||||||
});
|
});
|
||||||
}, [issueDetails, reset, issueId]);
|
}, [issueDetails, reset, issueId]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSubmitting === "submitted") {
|
|
||||||
setShowAlert(false);
|
|
||||||
setTimeout(async () => {
|
|
||||||
setIsSubmitting("saved");
|
|
||||||
}, 2000);
|
|
||||||
} else if (isSubmitting === "submitting") {
|
|
||||||
setShowAlert(true);
|
|
||||||
}
|
|
||||||
}, [isSubmitting, setShowAlert]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{" "}
|
{" "}
|
||||||
@ -143,11 +127,7 @@ const IssueDetailsPage: NextPageWithLayout = observer(() => {
|
|||||||
) : issueDetails && projectId ? (
|
) : issueDetails && projectId ? (
|
||||||
<div className="flex h-full overflow-hidden">
|
<div className="flex h-full overflow-hidden">
|
||||||
<div className="w-2/3 h-full overflow-y-auto space-y-5 divide-y-2 divide-custom-border-300 p-5">
|
<div className="w-2/3 h-full overflow-y-auto space-y-5 divide-y-2 divide-custom-border-300 p-5">
|
||||||
<IssueMainContent
|
<IssueMainContent issueDetails={issueDetails} submitChanges={submitChanges} />
|
||||||
setShowAlert={(value) => setShowAlert(value)}
|
|
||||||
issueDetails={issueDetails}
|
|
||||||
submitChanges={submitChanges}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 py-5 overflow-hidden">
|
<div className="w-1/3 h-full space-y-5 border-l border-custom-border-300 py-5 overflow-hidden">
|
||||||
<IssueDetailsSidebar
|
<IssueDetailsSidebar
|
||||||
|
Loading…
Reference in New Issue
Block a user