@@ -55,7 +55,9 @@ function initRepoDiffConversationForm() {
5555 formData . append ( submitter . name , submitter . value ) ;
5656 }
5757
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' ) ;
5961 const response = await POST ( form . getAttribute ( 'action' ) , { data : formData } ) ;
6062 const newConversationHolder = createElementFromHTML ( await response . text ( ) ) ;
6163 const path = newConversationHolder . getAttribute ( 'data-path' ) ;
@@ -65,14 +67,18 @@ function initRepoDiffConversationForm() {
6567 form . closest ( '.conversation-holder' ) . replaceWith ( newConversationHolder ) ;
6668 form = null ; // prevent further usage of the form because it should have been replaced
6769
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+ }
7682 }
7783 fomanticQuery ( newConversationHolder . querySelectorAll ( '.ui.dropdown' ) ) . dropdown ( ) ;
7884
0 commit comments