@@ -38,7 +38,7 @@ function initRepoDiffFileViewToggle() {
38
38
}
39
39
40
40
function initRepoDiffConversationForm ( ) {
41
- addDelegatedEventListener < HTMLFormElement > ( document , 'submit' , '.conversation-holder form' , async ( form , e ) => {
41
+ addDelegatedEventListener < HTMLFormElement , SubmitEvent > ( document , 'submit' , '.conversation-holder form' , async ( form , e ) => {
42
42
e . preventDefault ( ) ;
43
43
const textArea = form . querySelector < HTMLTextAreaElement > ( 'textarea' ) ;
44
44
if ( ! validateTextareaNonEmpty ( textArea ) ) return ;
@@ -55,7 +55,9 @@ function initRepoDiffConversationForm() {
55
55
formData . append ( submitter . name , submitter . value ) ;
56
56
}
57
57
58
- const trLineType = form . closest ( 'tr' ) . getAttribute ( 'data-line-type' ) ;
58
+ // on the diff page, the form is inside a "tr" and need to get the line-type ahead
59
+ // but on the conversation page, there is no parent "tr"
60
+ const trLineType = form . closest ( 'tr' ) ?. getAttribute ( 'data-line-type' ) ;
59
61
const response = await POST ( form . getAttribute ( 'action' ) , { data : formData } ) ;
60
62
const newConversationHolder = createElementFromHTML ( await response . text ( ) ) ;
61
63
const path = newConversationHolder . getAttribute ( 'data-path' ) ;
@@ -65,14 +67,18 @@ function initRepoDiffConversationForm() {
65
67
form . closest ( '.conversation-holder' ) . replaceWith ( newConversationHolder ) ;
66
68
form = null ; // prevent further usage of the form because it should have been replaced
67
69
68
- let selector ;
69
- if ( trLineType === 'same' ) {
70
- selector = `[data-path="${ path } "] .add-code-comment[data-idx="${ idx } "]` ;
71
- } else {
72
- selector = `[data-path="${ path } "] .add-code-comment[data-side="${ side } "][data-idx="${ idx } "]` ;
73
- }
74
- for ( const el of document . querySelectorAll ( selector ) ) {
75
- el . classList . add ( 'tw-invisible' ) ; // TODO need to figure out why
70
+ if ( trLineType ) {
71
+ // if there is a line-type for the "tr", it means the form is on the diff page
72
+ // then hide the "add-code-comment" [+] button for current code line by adding "tw-invisible" because the conversation has been added
73
+ let selector ;
74
+ if ( trLineType === 'same' ) {
75
+ selector = `[data-path="${ path } "] .add-code-comment[data-idx="${ idx } "]` ;
76
+ } else {
77
+ selector = `[data-path="${ path } "] .add-code-comment[data-side="${ side } "][data-idx="${ idx } "]` ;
78
+ }
79
+ for ( const el of document . querySelectorAll ( selector ) ) {
80
+ el . classList . add ( 'tw-invisible' ) ;
81
+ }
76
82
}
77
83
fomanticQuery ( newConversationHolder . querySelectorAll ( '.ui.dropdown' ) ) . dropdown ( ) ;
78
84
@@ -109,7 +115,7 @@ function initRepoDiffConversationForm() {
109
115
const $conversation = $ ( data ) ;
110
116
$ ( this ) . closest ( '.conversation-holder' ) . replaceWith ( $conversation ) ;
111
117
$conversation . find ( '.dropdown' ) . dropdown ( ) ;
112
- initCompReactionSelector ( $conversation ) ;
118
+ initCompReactionSelector ( $conversation [ 0 ] ) ;
113
119
} else {
114
120
window . location . reload ( ) ;
115
121
}
0 commit comments