@@ -2716,52 +2716,52 @@ class GitGraphView {
27162716 } ) ;
27172717 }
27182718
2719- private cdvSetLastViewedFile ( filePath : string , fileElem : HTMLElement ) {
2720- const expandedCommit = this . expandedCommit ;
2721- if ( expandedCommit === null || expandedCommit . fileTree === null ) return ;
2722-
2723- expandedCommit . lastViewedFile = filePath ;
2724- let lastViewedElem = document . getElementById ( 'cdvLastFileViewed' ) ;
2725- if ( lastViewedElem !== null ) lastViewedElem . remove ( ) ;
2726- lastViewedElem = document . createElement ( 'span' ) ;
2727- lastViewedElem . id = 'cdvLastFileViewed' ;
2728- lastViewedElem . title = 'Last File Viewed' ;
2729- lastViewedElem . innerHTML = SVG_ICONS . eyeOpen ;
2730- insertBeforeFirstChildWithClass ( lastViewedElem , fileElem , 'fileTreeFileAction' ) ;
2731- }
2732-
2733- private cdvChangeFileReviewedState ( file : GG . GitFileChange , fileElem : HTMLElement , isReviewed : boolean , fileWasViewed : boolean ) {
2734- const expandedCommit = this . expandedCommit , filePath = file . newFilePath ;
2735- const filesElem = document . getElementById ( 'cdvFiles' ) ;
2736-
2737- if ( expandedCommit === null || expandedCommit . fileTree === null || expandedCommit . codeReview === null || filesElem === null ) {
2738- return ;
2739- }
2740-
2741- if ( isReviewed ) {
2742- expandedCommit . codeReview . remainingFiles = expandedCommit . codeReview . remainingFiles . filter ( ( path : string ) => path !== filePath ) ;
2743- } else {
2744- expandedCommit . codeReview . remainingFiles . push ( filePath ) ;
2745- }
2719+ /**
2720+ * Updates the state of a file in the Commit Details View.
2721+ * @param file The file that was affected.
2722+ * @param fileElem The HTML Element of the file.
2723+ * @param isReviewed TRUE/FALSE => Set the files reviewed state accordingly, NULL => Don't update the files reviewed state.
2724+ * @param fileWasViewed Was the file viewed - if so, set it to be the last viewed file.
2725+ */
2726+ private cdvUpdateFileState ( file : GG . GitFileChange , fileElem : HTMLElement , isReviewed : boolean | null , fileWasViewed : boolean ) {
2727+ const expandedCommit = this . expandedCommit , filesElem = document . getElementById ( 'cdvFiles' ) , filePath = file . newFilePath ;
2728+ if ( expandedCommit === null || expandedCommit . fileTree === null || filesElem === null ) return ;
27462729
27472730 if ( fileWasViewed ) {
2748- this . cdvSetLastViewedFile ( filePath , fileElem ) ;
2749- }
2731+ expandedCommit . lastViewedFile = filePath ;
2732+ let lastViewedElem = document . getElementById ( 'cdvLastFileViewed' ) ;
2733+ if ( lastViewedElem !== null ) lastViewedElem . remove ( ) ;
2734+ lastViewedElem = document . createElement ( 'span' ) ;
2735+ lastViewedElem . id = 'cdvLastFileViewed' ;
2736+ lastViewedElem . title = 'Last File Viewed' ;
2737+ lastViewedElem . innerHTML = SVG_ICONS . eyeOpen ;
2738+ insertBeforeFirstChildWithClass ( lastViewedElem , fileElem , 'fileTreeFileAction' ) ;
2739+ }
2740+
2741+ if ( expandedCommit . codeReview !== null ) {
2742+ if ( isReviewed !== null ) {
2743+ if ( isReviewed ) {
2744+ expandedCommit . codeReview . remainingFiles = expandedCommit . codeReview . remainingFiles . filter ( ( path : string ) => path !== filePath ) ;
2745+ } else {
2746+ expandedCommit . codeReview . remainingFiles . push ( filePath ) ;
2747+ }
27502748
2751- sendMessage ( {
2752- command : 'updateCodeReview' ,
2753- repo : this . currentRepo ,
2754- id : expandedCommit . codeReview . id ,
2755- remainingFiles : expandedCommit . codeReview . remainingFiles ,
2756- lastViewedFile : expandedCommit . lastViewedFile
2757- } ) ;
2749+ alterFileTreeFileReviewed ( expandedCommit . fileTree , filePath , isReviewed ) ;
2750+ updateFileTreeHtmlFileReviewed ( filesElem , expandedCommit . fileTree , filePath ) ;
2751+ }
27582752
2759- alterFileTreeFileReviewed ( expandedCommit . fileTree , filePath , isReviewed ) ;
2760- updateFileTreeHtmlFileReviewed ( filesElem , expandedCommit . fileTree , filePath ) ;
2753+ sendMessage ( {
2754+ command : 'updateCodeReview' ,
2755+ repo : this . currentRepo ,
2756+ id : expandedCommit . codeReview . id ,
2757+ remainingFiles : expandedCommit . codeReview . remainingFiles ,
2758+ lastViewedFile : expandedCommit . lastViewedFile
2759+ } ) ;
27612760
2762- if ( expandedCommit . codeReview . remainingFiles . length === 0 ) {
2763- expandedCommit . codeReview = null ;
2764- this . renderCodeReviewBtn ( ) ;
2761+ if ( expandedCommit . codeReview . remainingFiles . length === 0 ) {
2762+ expandedCommit . codeReview = null ;
2763+ this . renderCodeReviewBtn ( ) ;
2764+ }
27652765 }
27662766
27672767 this . saveState ( ) ;
@@ -2846,7 +2846,7 @@ class GitGraphView {
28462846 toHash = expandedCommit . commitHash ;
28472847 }
28482848
2849- this . cdvChangeFileReviewedState ( file , fileElem , true , true ) ;
2849+ this . cdvUpdateFileState ( file , fileElem , true , true ) ;
28502850 sendMessage ( {
28512851 command : 'viewDiff' ,
28522852 repo : this . currentRepo ,
@@ -2866,23 +2866,23 @@ class GitGraphView {
28662866 const expandedCommit = this . expandedCommit ;
28672867 if ( expandedCommit === null ) return ;
28682868
2869- this . cdvChangeFileReviewedState ( file , fileElem , true , true ) ;
2869+ this . cdvUpdateFileState ( file , fileElem , true , true ) ;
28702870 sendMessage ( { command : 'viewFileAtRevision' , repo : this . currentRepo , hash : getCommitHashForFile ( file , expandedCommit ) , filePath : file . newFilePath } ) ;
28712871 } ;
28722872
28732873 const triggerViewFileDiffWithWorkingFile = ( file : GG . GitFileChange , fileElem : HTMLElement ) => {
28742874 const expandedCommit = this . expandedCommit ;
28752875 if ( expandedCommit === null ) return ;
28762876
2877- this . cdvChangeFileReviewedState ( file , fileElem , false , true ) ;
2877+ this . cdvUpdateFileState ( file , fileElem , null , true ) ;
28782878 sendMessage ( { command : 'viewDiffWithWorkingFile' , repo : this . currentRepo , hash : getCommitHashForFile ( file , expandedCommit ) , filePath : file . newFilePath } ) ;
28792879 } ;
28802880
28812881 const triggerOpenFile = ( file : GG . GitFileChange , fileElem : HTMLElement ) => {
28822882 const expandedCommit = this . expandedCommit ;
28832883 if ( expandedCommit === null ) return ;
28842884
2885- this . cdvChangeFileReviewedState ( file , fileElem , true , true ) ;
2885+ this . cdvUpdateFileState ( file , fileElem , true , true ) ;
28862886 sendMessage ( { command : 'openFile' , repo : this . currentRepo , hash : getCommitHashForFile ( file , expandedCommit ) , filePath : file . newFilePath } ) ;
28872887 } ;
28882888
@@ -2989,12 +2989,12 @@ class GitGraphView {
29892989 {
29902990 title : 'Mark as Reviewed' ,
29912991 visible : codeReviewInProgressAndNotReviewed ,
2992- onClick : ( ) => this . cdvChangeFileReviewedState ( file , fileElem , true , false )
2992+ onClick : ( ) => this . cdvUpdateFileState ( file , fileElem , true , false )
29932993 } ,
29942994 {
29952995 title : 'Mark as Not Reviewed' ,
29962996 visible : expandedCommit . codeReview !== null && ! codeReviewInProgressAndNotReviewed ,
2997- onClick : ( ) => this . cdvChangeFileReviewedState ( file , fileElem , false , false )
2997+ onClick : ( ) => this . cdvUpdateFileState ( file , fileElem , false , false )
29982998 }
29992999 ] ,
30003000 [
0 commit comments