11/*global*/
22import type { ViewFilesLayout } from '../../../config' ;
33import type { Serialized } from '../../../system/serialize' ;
4- import type { CommitActionsParams , State } from '../../commitDetails/protocol' ;
4+ import type { CommitActionsParams , Mode , State } from '../../commitDetails/protocol' ;
55import {
66 AutolinkSettingsCommandType ,
77 CommitActionsCommandType ,
88 DidChangeNotificationType ,
9- DidExplainCommitCommandType ,
10- ExplainCommitCommandType ,
9+ DidChangeWipStateNotificationType ,
10+ DidExplainCommandType ,
11+ ExplainCommandType ,
1112 FileActionsCommandType ,
1213 NavigateCommitCommandType ,
1314 OpenFileCommandType ,
@@ -16,8 +17,11 @@ import {
1617 OpenFileOnRemoteCommandType ,
1718 PickCommitCommandType ,
1819 PinCommitCommandType ,
19- PreferencesCommandType ,
2020 SearchCommitCommandType ,
21+ StageFileCommandType ,
22+ SwitchModeCommandType ,
23+ UnstageFileCommandType ,
24+ UpdatePreferencesCommandType ,
2125} from '../../commitDetails/protocol' ;
2226import type { IpcMessage } from '../../protocol' ;
2327import { ExecuteCommandType , onIpc } from '../../protocol' ;
@@ -44,7 +48,7 @@ import './components/commit-details-app';
4448
4549export const uncommittedSha = '0000000000000000000000000000000000000000' ;
4650
47- export type CommitState = SomeNonNullable < Serialized < State > , 'selected ' > ;
51+ export type CommitState = SomeNonNullable < Serialized < State > , 'commit ' > ;
4852export class CommitDetailsApp extends App < Serialized < State > > {
4953 constructor ( ) {
5054 super ( 'CommitDetailsApp' ) ;
@@ -71,8 +75,16 @@ export class CommitDetailsApp extends App<Serialized<State>> {
7175 DOM . on < FileChangeListItem , FileChangeListItemDetail > ( 'file-change-list-item' , 'file-more-actions' , e =>
7276 this . onFileMoreActions ( e . detail ) ,
7377 ) ,
78+ DOM . on < FileChangeListItem , FileChangeListItemDetail > ( 'file-change-list-item' , 'file-stage' , e =>
79+ this . onStageFile ( e . detail ) ,
80+ ) ,
81+ DOM . on < FileChangeListItem , FileChangeListItemDetail > ( 'file-change-list-item' , 'file-unstage' , e =>
82+ this . onUnstageFile ( e . detail ) ,
83+ ) ,
7484 DOM . on ( '[data-action="commit-actions"]' , 'click' , e => this . onCommitActions ( e ) ) ,
7585 DOM . on ( '[data-action="pick-commit"]' , 'click' , e => this . onPickCommit ( e ) ) ,
86+ DOM . on ( '[data-action="wip"]' , 'click' , e => this . onSwitchMode ( e , 'wip' ) ) ,
87+ DOM . on ( '[data-action="details"]' , 'click' , e => this . onSwitchMode ( e , 'commit' ) ) ,
7688 DOM . on ( '[data-action="search-commit"]' , 'click' , e => this . onSearchCommit ( e ) ) ,
7789 DOM . on ( '[data-action="autolink-settings"]' , 'click' , e => this . onAutolinkSettings ( e ) ) ,
7890 DOM . on ( '[data-action="files-layout"]' , 'click' , e => this . onToggleFilesLayout ( e ) ) ,
@@ -129,6 +141,14 @@ export class CommitDetailsApp extends App<Serialized<State>> {
129141 } ) ;
130142 break ;
131143
144+ case DidChangeWipStateNotificationType . method :
145+ onIpc ( DidChangeWipStateNotificationType , msg , params => {
146+ this . state = { ...this . state , ...params } ;
147+ this . setState ( this . state ) ;
148+ this . attachState ( ) ;
149+ } ) ;
150+ break ;
151+
132152 default :
133153 super . onMessageReceived ?.( e ) ;
134154 }
@@ -147,19 +167,14 @@ export class CommitDetailsApp extends App<Serialized<State>> {
147167
148168 async onExplainCommit ( _e : MouseEvent ) {
149169 try {
150- const result = await this . sendCommandWithCompletion (
151- ExplainCommitCommandType ,
152- undefined ,
153- DidExplainCommitCommandType ,
154- ) ;
170+ const result = await this . sendCommandWithCompletion ( ExplainCommandType , undefined , DidExplainCommandType ) ;
155171
156172 if ( result . error ) {
157173 this . component . explain = { error : { message : result . error . message ?? 'Error retrieving content' } } ;
158174 } else if ( result . summary ) {
159175 this . component . explain = { summary : result . summary } ;
160176 } else {
161177 this . component . explain = undefined ;
162- this . component . explainBusy = false ;
163178 }
164179 } catch ( ex ) {
165180 this . component . explain = { error : { message : 'Error retrieving content' } } ;
@@ -173,24 +188,19 @@ export class CommitDetailsApp extends App<Serialized<State>> {
173188 const files = {
174189 ...this . state . preferences ?. files ,
175190 layout : layout ?? 'auto' ,
176- compact : this . state . preferences ?. files ?. compact ?? true ,
177- threshold : this . state . preferences ?. files ?. threshold ?? 5 ,
178- icon : this . state . preferences ?. files ?. icon ?? 'type' ,
179191 } ;
180192
181193 this . state = { ...this . state , preferences : { ...this . state . preferences , files : files } } ;
182194 this . attachState ( ) ;
183195
184- this . sendCommand ( PreferencesCommandType , { files : files } ) ;
196+ this . sendCommand ( UpdatePreferencesCommandType , { files : files } ) ;
185197 }
186198
187199 private onExpandedChange ( e : WebviewPaneExpandedChangeEventDetail ) {
188- this . state . preferences = {
189- ...this . state . preferences ,
190- autolinksExpanded : e . expanded ,
191- } ;
200+ this . state = { ...this . state , preferences : { ...this . state . preferences , autolinksExpanded : e . expanded } } ;
201+ this . attachState ( ) ;
192202
193- this . sendCommand ( PreferencesCommandType , { autolinksExpanded : e . expanded } ) ;
203+ this . sendCommand ( UpdatePreferencesCommandType , { autolinksExpanded : e . expanded } ) ;
194204 }
195205
196206 private onNavigate ( direction : 'back' | 'forward' , e : Event ) {
@@ -208,12 +218,19 @@ export class CommitDetailsApp extends App<Serialized<State>> {
208218 this . sendCommand ( AutolinkSettingsCommandType , undefined ) ;
209219 }
210220
221+ private onPickCommit ( _e : MouseEvent ) {
222+ this . sendCommand ( PickCommitCommandType , undefined ) ;
223+ }
224+
211225 private onSearchCommit ( _e : MouseEvent ) {
212226 this . sendCommand ( SearchCommitCommandType , undefined ) ;
213227 }
214228
215- private onPickCommit ( _e : MouseEvent ) {
216- this . sendCommand ( PickCommitCommandType , undefined ) ;
229+ private onSwitchMode ( _e : MouseEvent , mode : Mode ) {
230+ this . state = { ...this . state , mode : mode } ;
231+ this . attachState ( ) ;
232+
233+ this . sendCommand ( SwitchModeCommandType , { mode : mode , repoPath : this . state . commit ?. repoPath } ) ;
217234 }
218235
219236 private onOpenFileOnRemote ( e : FileChangeListItemDetail ) {
@@ -236,9 +253,17 @@ export class CommitDetailsApp extends App<Serialized<State>> {
236253 this . sendCommand ( FileActionsCommandType , e ) ;
237254 }
238255
256+ onStageFile ( e : FileChangeListItemDetail ) : void {
257+ this . sendCommand ( StageFileCommandType , e ) ;
258+ }
259+
260+ onUnstageFile ( e : FileChangeListItemDetail ) : void {
261+ this . sendCommand ( UnstageFileCommandType , e ) ;
262+ }
263+
239264 private onCommitActions ( e : MouseEvent ) {
240265 e . preventDefault ( ) ;
241- if ( this . state . selected === undefined ) {
266+ if ( this . state . commit === undefined ) {
242267 e . stopPropagation ( ) ;
243268 return ;
244269 }
0 commit comments