Return of new comment works...

Sascha created

...but the types are quite hacky

Change summary

webui/src/pages/bug/EditCommentForm.graphql |  9 +++++++++
webui/src/pages/bug/EditCommentForm.tsx     | 11 +++++++----
webui/src/pages/bug/Message.tsx             |  8 ++++++--
3 files changed, 22 insertions(+), 6 deletions(-)

Detailed changes

webui/src/pages/bug/EditCommentForm.graphql 🔗

@@ -1,7 +1,16 @@
+#import "./MessageCommentFragment.graphql"
+#import "./MessageCreateFragment.graphql"
+
 mutation EditComment($input: EditCommentInput!) {
   editComment(input: $input) {
     bug {
       id
+      timeline {
+        comments: nodes {
+          ...Create
+          ...AddComment
+        }
+      }
     }
   }
 }

webui/src/pages/bug/EditCommentForm.tsx 🔗

@@ -7,7 +7,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles';
 import CommentInput from '../../components/CommentInput/CommentInput';
 
 import { BugFragment } from './Bug.generated';
-import { useEditCommentMutation } from './EditCommentform.generated';
+import { useEditCommentMutation } from './EditCommentForm.generated';
 import { AddCommentFragment } from './MessageCommentFragment.generated';
 import { CreateFragment } from './MessageCreateFragment.generated';
 
@@ -43,7 +43,7 @@ type Props = {
   bug: BugFragment;
   comment: AddCommentFragment | CreateFragment;
   onCancelClick?: () => void;
-  onPostSubmit?: () => void;
+  onPostSubmit?: (comments: any) => void;
 };
 
 function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) {
@@ -54,7 +54,6 @@ function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) {
   const form = useRef<HTMLFormElement>(null);
 
   const submit = () => {
-    console.log('submit: ' + message + '\nTo: ' + comment.id);
     editComment({
       variables: {
         input: {
@@ -63,9 +62,13 @@ function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) {
           target: comment.id,
         },
       },
+    }).then((result) => {
+      const comments = result.data?.editComment.bug.timeline.comments;
+      const coms = comments as (AddCommentFragment | CreateFragment)[];
+      const res = coms.find((elem) => elem.id === comment.id);
+      if (onPostSubmit) onPostSubmit(res);
     });
     resetForm();
-    if (onPostSubmit) onPostSubmit();
   };
 
   function resetForm() {

webui/src/pages/bug/Message.tsx 🔗

@@ -78,7 +78,6 @@ function Message({ bug, op: comment }: Props) {
 
   const editComment = (id: String) => {
     switchToEditMode(true);
-    console.log(id);
   };
 
   function readMessageView() {
@@ -118,13 +117,18 @@ function Message({ bug, op: comment }: Props) {
       switchToEditMode(false);
     };
 
+    const onPostSubmit = (comments: AddCommentFragment | CreateFragment) => {
+      console.log('posted: ' + comments.message);
+      switchToEditMode(false);
+    };
+
     return (
       <div className={classes.bubble}>
         <EditCommentForm
           bug={bug}
           onCancelClick={cancelEdition}
           // Close edit view after submitted changes
-          onPostSubmit={cancelEdition}
+          onPostSubmit={onPostSubmit}
           comment={comment}
         />
       </div>