66 CompositeItem ,
77 CompositeGroup ,
88 CompositeGroupLabel ,
9- useCompositeContext ,
9+ useCompositeStore ,
1010} from '@ariakit/react/composite'
1111
1212import type { GitStatus } from 'src/shared/reducers/git'
@@ -46,22 +46,7 @@ type ActionButtonProps = {
4646 iconId : IconId
4747 tooltip ?: ReactNode
4848}
49- const ActionButton = ( { disabled, onClick, iconId, tooltip } : ActionButtonProps ) => {
50- const store = useCompositeContext ( )
51- return (
52- < CompositeItem
53- { ...store }
54- onClick = { ( ) => {
55- onClick ?.( )
56- store ?. move ( store ?. next ( ) )
57- } }
58- tabbable
59- className = 'mx-2'
60- disabled = { disabled }
61- render = { < IconButton iconId = { iconId } tooltip = { tooltip } /> }
62- />
63- )
64- }
49+ const ActionButton = ( props : ActionButtonProps ) => < IconButton { ...props } className = 'mx-2' />
6550
6651export const FilePanelBase = ( {
6752 status,
@@ -71,10 +56,32 @@ export const FilePanelBase = ({
7156 onStageAll,
7257 onUnstageAll,
7358} : FilePanelBaseProps ) => {
59+ const store = useCompositeStore ( )
7460 const unstaged = status ?. data ?. files . filter ( x => x . working_dir !== ' ' )
7561 const staged = status ?. data ?. files . filter ( x => x . index !== ' ' && x . working_dir !== '?' )
62+
63+ const handleStage = ( item : FileStatusResult ) => {
64+ onStage ?.( item )
65+ store . move ( store . previous ( ) || store . next ( ) )
66+ }
67+ const handleUnstage = ( item : FileStatusResult ) => {
68+ onUnstage ?.( item )
69+ store . move ( store . next ( ) || store . previous ( ) )
70+ }
71+ const handleDiscard = ( item : FileStatusResult ) => {
72+ onDiscard ?.( item )
73+ store . move ( store . previous ( ) || store . next ( ) )
74+ }
75+ const handleStageAll = ( ) => {
76+ onStageAll ?.( )
77+ store . move ( store . previous ( ) || store . next ( ) )
78+ }
79+ const handleUnstageAll = ( ) => {
80+ onUnstageAll ?.( )
81+ store . move ( store . previous ( ) || store . next ( ) )
82+ }
7683 return (
77- < CompositeProvider focusLoop virtualFocus >
84+ < CompositeProvider store = { store } focusLoop virtualFocus >
7885 < Composite
7986 className = 'group flex-1 flex flex-col outline-none overflow-clip scroll-pt-8'
8087 autoFocus
@@ -85,7 +92,7 @@ export const FilePanelBase = ({
8592 < Icon iconId = 'folder-dot' className = 'mr-2' /> unstaged changes
8693 </ FilePanelTitle >
8794 < ActionButton
88- onClick = { onStageAll }
95+ onClick = { handleStageAll }
8996 disabled = { ! unstaged ?. length }
9097 iconId = 'arrow-down-to-line'
9198 tooltip = 'stage all'
@@ -96,13 +103,13 @@ export const FilePanelBase = ({
96103 key = { x . path }
97104 menu = {
98105 < UnstagedContextMenu
99- onStage = { ( ) => onStage ?.( x ) }
100- onDiscardChanges = { ( ) => onDiscard ?.( x ) }
106+ onStage = { ( ) => handleStage ?.( x ) }
107+ onDiscardChanges = { ( ) => handleDiscard ?.( x ) }
101108 />
102109 }
103110 >
104111 { ( { onContextMenu } ) => (
105- < FileItem onClick = { ( ) => onStage ?.( x ) } onContextMenu = { onContextMenu } { ...x } />
112+ < FileItem onClick = { ( ) => handleStage ?.( x ) } onContextMenu = { onContextMenu } { ...x } />
106113 ) }
107114 </ ContextMenu >
108115 ) ) }
@@ -114,7 +121,7 @@ export const FilePanelBase = ({
114121 < Icon iconId = 'folder-git' className = 'mr-2' /> staged changes
115122 </ FilePanelTitle >
116123 < ActionButton
117- onClick = { onUnstageAll }
124+ onClick = { handleUnstageAll }
118125 disabled = { ! staged ?. length }
119126 iconId = 'arrow-up-from-line'
120127 tooltip = 'unstage all'
@@ -123,11 +130,11 @@ export const FilePanelBase = ({
123130 { staged ?. map ( x => (
124131 < ContextMenu
125132 key = { x . path }
126- menu = { < ContextMenuItem onClick = { ( ) => onUnstage ?.( x ) } > unstage</ ContextMenuItem > }
133+ menu = { < ContextMenuItem onClick = { ( ) => handleUnstage ?.( x ) } > unstage</ ContextMenuItem > }
127134 >
128135 { ( { onContextMenu } ) => (
129136 < FileItem
130- onClick = { ( ) => onUnstage ?.( x ) }
137+ onClick = { ( ) => handleUnstage ?.( x ) }
131138 key = { x . path }
132139 onContextMenu = { onContextMenu }
133140 { ...x }
0 commit comments