Ensure the patchset level draft is saved before sending reply

Release-Notes: skip
Google-bug-id: b/242982372
Change-Id: I5fbef9705e593142036f6b45e857a23e6cc6d5f0
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
index e42c0f1..603b180 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
@@ -120,6 +120,7 @@
 import {hasHumanReviewer, isOwner} from '../../../utils/change-util';
 import {KnownExperimentId} from '../../../services/flags/flags';
 import {commentsModelToken} from '../../../models/comments/comments-model';
+import {GrComment} from '../../shared/gr-comment/gr-comment';
 
 const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
 
@@ -963,6 +964,7 @@
       this.patchsetLevelComment = this.createDraft();
     return html`
       <gr-comment
+        id="patchsetLevelComment"
         .comment=${this.patchsetLevelComment}
         .comments=${[this.patchsetLevelComment]}
         @comment-unresolved-changed=${(e: CustomEvent) => {
@@ -1475,7 +1477,7 @@
     );
   }
 
-  send(includeComments: boolean, startReview: boolean) {
+  async send(includeComments: boolean, startReview: boolean) {
     this.reporting.time(Timing.SEND_REPLY);
     const labels = this.getLabelScores().getLabelValues();
 
@@ -1490,6 +1492,8 @@
       reviewInput.ready = true;
     }
 
+    this.disabled = true;
+
     const reason = getReplyByReason(this.account, this.serverConfig);
 
     reviewInput.ignore_automatic_attention_set_rules = true;
@@ -1511,7 +1515,24 @@
       reviewInput.remove_from_attention_set
     );
 
-    if (this.draft) {
+    if (
+      this.flagsService.isEnabled(
+        KnownExperimentId.PATCHSET_LEVEL_COMMENT_USES_GRCOMMENT
+      )
+    ) {
+      const patchsetLevelComment = queryAndAssert<GrComment>(
+        this,
+        '#patchsetLevelComment'
+      );
+      await patchsetLevelComment.save();
+    }
+
+    if (
+      this.draft &&
+      !this.flagsService.isEnabled(
+        KnownExperimentId.PATCHSET_LEVEL_COMMENT_USES_GRCOMMENT
+      )
+    ) {
       const comment: CommentInput = {
         message: this.draft,
         unresolved: !this.isResolvedPatchsetLevelComment,
@@ -1523,7 +1544,6 @@
 
     assertIsDefined(this.change, 'change');
     reviewInput.reviewers = this.computeReviewers();
-    this.disabled = true;
 
     const errFn = (r?: Response | null) => this.handle400Error(r);
     return this.saveReview(reviewInput, errFn)