fix: commenting fixes

This commit is contained in:
sriram veeraghanta 2023-09-01 11:49:07 +05:30
parent 5c8060c777
commit 77a043b141
5 changed files with 31 additions and 48 deletions

View File

@ -21,43 +21,29 @@ type Props = {
export const CommentCard: React.FC<Props> = observer((props) => {
const { comment, workspaceSlug } = props;
// store
const { user: userStore, issue: issueStore, issueDetails: issueDetailStore } = useMobxStore();
const { user: userStore, issueDetails: issueDetailStore } = useMobxStore();
// states
const [isEditing, setIsEditing] = useState(false);
const {
formState: { isSubmitting },
handleSubmit,
setFocus,
control,
} = useForm<any>({
defaultValues: { comment_html: comment.comment_html },
});
const handleDelete = async () => {
const handleDelete = () => {
if (!workspaceSlug || !issueDetailStore.peekId) return;
await issueDetailStore.deleteIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id);
issueDetailStore.deleteIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id);
};
const handleCommentUpdate = async (formData: Comment) => {
if (!workspaceSlug || !issueDetailStore.peekId) return;
console.log("formData", formData);
const response = await issueDetailStore.updateIssueComment(
workspaceSlug,
comment.project,
issueDetailStore.peekId,
comment.id,
formData
);
issueDetailStore.updateIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id, formData);
setIsEditing(false);
};
useEffect(() => {
isEditing && setFocus("comment_html");
}, [isEditing, setFocus]);
return (
<div className="relative flex items-start space-x-3">
<div className="relative px-1">
@ -133,6 +119,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
</div>
</form>
<div className={`${isEditing ? "hidden" : ""}`}>
{comment.comment_html}
<TipTapEditor
workspaceSlug={workspaceSlug.toString()}
value={comment.comment_html}
@ -185,9 +172,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
<div className="py-1">
<button
type="button"
onClick={() => {
handleDelete();
}}
onClick={handleDelete}
className={`w-full select-none truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80 ${
active ? "bg-custom-background-80" : ""
}`}

View File

@ -64,7 +64,7 @@ export const PeekOverviewHeader: React.FC<Props> = (props) => {
<div className="flex justify-between items-center">
<div className="flex items-center gap-4">
{issueDetailStore.peekMode === "side" && (
<button type="button" onClick={handleClose}>
<button type="button" onClick={handleClose} autoFocus={false}>
<East
sx={{
fontSize: "14px",

View File

@ -20,7 +20,7 @@ export const PeekOverviewIssueActivity: React.FC<Props> = observer((props) => {
const comments = issueDetailStore.details[issueDetailStore.peekId || ""]?.comments || [];
console.log("comments", comments);
console.log("issueDetailStore", issueDetailStore);
return (
<div>

View File

@ -1,9 +1,10 @@
import { useImperativeHandle, useRef, forwardRef, useEffect } from "react";
import { useEditor, EditorContent, Editor } from "@tiptap/react";
import { useDebouncedCallback } from "use-debounce";
// components
import { EditorBubbleMenu } from "./bubble-menu";
import { TiptapExtensions } from "./extensions";
import { TiptapEditorProps } from "./props";
import { useImperativeHandle, useRef, forwardRef } from "react";
import { ImageResizer } from "./extensions/image-resize";
export interface ITipTapRichTextEditor {
@ -36,7 +37,7 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
borderOnFocus,
customClassName,
} = props;
console.log("tiptap_value", value);
const editor = useEditor({
editable: editable ?? true,
editorProps: TiptapEditorProps(workspaceSlug, setIsSubmitting),
@ -54,6 +55,12 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
},
});
useEffect(() => {
if (editor) {
editor.commands.setContent(value);
}
}, [value]);
const editorRef: React.MutableRefObject<Editor | null> = useRef(null);
useImperativeHandle(forwardedRef, () => ({
@ -75,8 +82,8 @@ const Tiptap = (props: ITipTapRichTextEditor) => {
const editorClassNames = `relative w-full max-w-full sm:rounded-lg mt-2 p-3 relative focus:outline-none rounded-md
${noBorder ? "" : "border border-custom-border-200"} ${
borderOnFocus ? "focus:border border-custom-border-300" : "focus:border-0"
} ${customClassName}`;
borderOnFocus ? "focus:border border-custom-border-300" : "focus:border-0"
} ${customClassName}`;
if (!editor) return null;
editorRef.current = editor;

View File

@ -137,11 +137,10 @@ class IssueDetailStore implements IssueDetailStore {
commentId,
data
);
// const issueComments = await this.issueService.getIssueComments(workspaceSlug, projectId, issueId);
if (issueCommentUpdateResponse) {
const remainingComments = this.details[issueId].comments.filter((com) => com.id != commentId);
runInAction(() => {
const remainingComments = this.details[issueId].comments.filter((com) => com.id === commentId);
this.details = {
...this.details,
[issueId]: {
@ -159,25 +158,17 @@ class IssueDetailStore implements IssueDetailStore {
deleteIssueComment = async (workspaceSlug: string, projectId: string, issueId: string, comment_id: string) => {
try {
const issueVoteResponse = await this.issueService.deleteIssueComment(
workspaceSlug,
projectId,
issueId,
comment_id
);
const issueComments = await this.issueService.getIssueComments(workspaceSlug, projectId, issueId);
if (issueVoteResponse) {
runInAction(() => {
this.details = {
...this.details,
[issueId]: {
...this.details[issueId],
comments: issueComments,
},
};
});
}
await this.issueService.deleteIssueComment(workspaceSlug, projectId, issueId, comment_id);
const remainingComments = this.details[issueId].comments.filter((c) => c.id != comment_id);
runInAction(() => {
this.details = {
...this.details,
[issueId]: {
...this.details[issueId],
comments: remainingComments,
},
};
});
} catch (error) {
console.log("Failed to add issue vote");
}