@@ -1281,7 +1281,7 @@ function initPullRequestReview() {
1281
1281
$ ( this ) . closest ( '.menu' ) . toggle ( 'visible' ) ;
1282
1282
} ) ;
1283
1283
1284
- $ ( 'a.add-code-comment' ) . on ( 'click' , function ( e ) {
1284
+ $ ( 'a.add-code-comment' ) . on ( 'click' , async function ( e ) {
1285
1285
if ( $ ( e . target ) . hasClass ( 'btn-add-single' ) ) return ; // https://github.com/go-gitea/gitea/issues/4745
1286
1286
e . preventDefault ( ) ;
1287
1287
@@ -1314,22 +1314,18 @@ function initPullRequestReview() {
1314
1314
const td = ntr . find ( `.add-comment-${ side } ` ) ;
1315
1315
let commentCloud = td . find ( '.comment-code-cloud' ) ;
1316
1316
if ( commentCloud . length === 0 && ! ntr . find ( 'button[name="is_review"]' ) . length ) {
1317
- const url = $ ( this ) . data ( 'new-comment-url' ) ;
1318
- $ . post ( url , {
1319
- _csrf : csrf
1320
- } , ( data ) => {
1321
- td . html ( data ) ;
1322
- commentCloud = td . find ( '.comment-code-cloud' ) ;
1323
- assingMenuAttributes ( commentCloud . find ( '.menu' ) ) ;
1324
- td . find ( "input[name='line']" ) . val ( idx ) ;
1325
- td . find ( "input[name='side']" ) . val ( side === 'left' ? 'previous' : 'proposed' ) ;
1326
- td . find ( "input[name='path']" ) . val ( path ) ;
1327
- const $textarea = commentCloud . find ( 'textarea' ) ;
1328
- attachTribute ( $textarea . get ( ) , { mentions : true , emoji : true } ) ;
1329
- const $simplemde = setCommentSimpleMDE ( $textarea ) ;
1330
- $textarea . focus ( ) ;
1331
- $simplemde . codemirror . focus ( ) ;
1332
- } ) ;
1317
+ const data = await $ . get ( $ ( this ) . data ( 'new-comment-url' ) ) ;
1318
+ td . html ( data ) ;
1319
+ commentCloud = td . find ( '.comment-code-cloud' ) ;
1320
+ assingMenuAttributes ( commentCloud . find ( '.menu' ) ) ;
1321
+ td . find ( "input[name='line']" ) . val ( idx ) ;
1322
+ td . find ( "input[name='side']" ) . val ( side === 'left' ? 'previous' : 'proposed' ) ;
1323
+ td . find ( "input[name='path']" ) . val ( path ) ;
1324
+ const $textarea = commentCloud . find ( 'textarea' ) ;
1325
+ attachTribute ( $textarea . get ( ) , { mentions : true , emoji : true } ) ;
1326
+ const $simplemde = setCommentSimpleMDE ( $textarea ) ;
1327
+ $textarea . focus ( ) ;
1328
+ $simplemde . codemirror . focus ( ) ;
1333
1329
}
1334
1330
} ) ;
1335
1331
}
@@ -2491,28 +2487,24 @@ $(document).ready(async () => {
2491
2487
$ ( e ) . trigger ( 'click' ) ;
2492
2488
} ) ;
2493
2489
2494
- $ ( document ) . on ( 'click' , '.resolve-conversation' , function ( e ) {
2490
+ $ ( document ) . on ( 'click' , '.resolve-conversation' , async function ( e ) {
2495
2491
e . preventDefault ( ) ;
2496
- const id = $ ( this ) . data ( 'comment-id' ) ;
2492
+ const comment_id = $ ( this ) . data ( 'comment-id' ) ;
2497
2493
const origin = $ ( this ) . data ( 'origin' ) ;
2498
2494
const action = $ ( this ) . data ( 'action' ) ;
2499
2495
const url = $ ( this ) . data ( 'update-url' ) ;
2500
2496
2501
- $ . post ( url , {
2502
- _csrf : csrf ,
2503
- origin,
2504
- action,
2505
- comment_id : id ,
2506
- } , ( data ) => {
2497
+ const data = await $ . post ( url , { _csrf : csrf , origin, action, comment_id} ) ;
2498
+
2499
+ if ( $ ( this ) . closest ( '.conversation-holder' ) . length ) {
2507
2500
const conversation = $ ( data ) ;
2508
- if ( $ ( this ) . closest ( '.conversation-holder' ) . replaceWith ( conversation ) ) {
2509
- conversation . find ( '.dropdown' ) . dropdown ( ) ;
2510
- initReactionSelector ( conversation ) ;
2511
- initClipboard ( ) ;
2512
- } else {
2513
- reload ( ) ;
2514
- }
2515
- } ) ;
2501
+ $ ( this ) . closest ( '.conversation-holder' ) . replaceWith ( conversation ) ;
2502
+ conversation . find ( '.dropdown' ) . dropdown ( ) ;
2503
+ initReactionSelector ( conversation ) ;
2504
+ initClipboard ( ) ;
2505
+ } else {
2506
+ reload ( ) ;
2507
+ }
2516
2508
} ) ;
2517
2509
2518
2510
buttonsClickOnEnter ( ) ;
@@ -3631,25 +3623,21 @@ $(document).on('click', 'button[name="is_review"]', (e) => {
3631
3623
$ ( e . target ) . closest ( 'form' ) . append ( '<input type="hidden" name="is_review" value="true">' ) ;
3632
3624
} ) ;
3633
3625
3634
- $ ( document ) . on ( 'submit' , '.conversation-holder form' , ( e ) => {
3626
+ $ ( document ) . on ( 'submit' , '.conversation-holder form' , async ( e ) => {
3635
3627
e . preventDefault ( ) ;
3636
3628
const form = $ ( e . target ) ;
3637
- $ . post ( form . attr ( 'action' ) , form . serialize ( ) , ( data ) => {
3638
- const conversation = $ ( data ) ;
3639
- const path = conversation . data ( 'path' ) ;
3640
- const side = conversation . data ( 'side' ) ;
3641
- const idx = conversation . data ( 'idx' ) ;
3642
- const lineType = form . closest ( 'tr' ) . data ( 'line-type' ) ;
3643
- form . closest ( '.conversation-holder' ) . replaceWith ( conversation ) ;
3644
- if ( lineType === 'same' ) {
3645
- $ ( `a.add-code-comment[data-path="${ path } "][data-idx="${ idx } "]` ) . addClass ( 'invisible' ) ;
3646
- } else {
3647
- $ ( `a.add-code-comment[data-path="${ path } "][data-side="${ side } "][data-idx="${ idx } "]` ) . addClass ( 'invisible' ) ;
3648
- }
3649
- conversation . find ( '.dropdown' ) . dropdown ( ) ;
3650
- initReactionSelector ( conversation ) ;
3651
- initClipboard ( ) ;
3652
- } ) ;
3629
+ const newConversationHolder = $ ( await $ . post ( form . attr ( 'action' ) , form . serialize ( ) ) ) ;
3630
+ const { path, side, idx} = newConversationHolder . data ( ) ;
3631
+
3632
+ form . closest ( '.conversation-holder' ) . replaceWith ( newConversationHolder ) ;
3633
+ if ( form . closest ( 'tr' ) . data ( 'line-type' ) === 'same' ) {
3634
+ $ ( `a.add-code-comment[data-path="${ path } "][data-idx="${ idx } "]` ) . addClass ( 'invisible' ) ;
3635
+ } else {
3636
+ $ ( `a.add-code-comment[data-path="${ path } "][data-side="${ side } "][data-idx="${ idx } "]` ) . addClass ( 'invisible' ) ;
3637
+ }
3638
+ newConversationHolder . find ( '.dropdown' ) . dropdown ( ) ;
3639
+ initReactionSelector ( newConversationHolder ) ;
3640
+ initClipboard ( ) ;
3653
3641
} ) ;
3654
3642
3655
3643
window . cancelCodeComment = function ( btn ) {
0 commit comments