1
- import React , { useCallback , useContext } from 'react' ;
1
+ import React , { useCallback , useContext , useMemo } from 'react' ;
2
2
import { useSelector } from 'react-redux' ;
3
3
import AutoSizer from 'react-virtualized-auto-sizer' ;
4
4
@@ -24,14 +24,23 @@ import { ListContainer } from './ListContainer';
24
24
25
25
export interface FileListProps { }
26
26
27
+ interface StyleState {
28
+ dndCanDrop : boolean ;
29
+ dndIsOverCurrent : boolean ;
30
+ }
31
+
27
32
export const FileList : React . FC < FileListProps > = React . memo ( ( ) => {
28
33
const displayFileIds = useSelector ( selectDisplayFileIds ) ;
29
34
const viewConfig = useSelector ( selectFileViewConfig ) ;
30
35
31
36
const currentFolder = useSelector ( selectCurrentFolder ) ;
32
- const { dndCanDrop, drop } = useFileDrop ( { file : currentFolder } ) ;
37
+ const { drop, dndCanDrop, dndIsOverCurrent } = useFileDrop ( { file : currentFolder } ) ;
38
+ const styleState = useMemo < StyleState > ( ( ) => ( { dndCanDrop, dndIsOverCurrent } ) , [
39
+ dndCanDrop ,
40
+ dndIsOverCurrent ,
41
+ ] ) ;
33
42
34
- const localClasses = useLocalStyles ( dndCanDrop ) ;
43
+ const localClasses = useLocalStyles ( styleState ) ;
35
44
const classes = useStyles ( viewConfig ) ;
36
45
37
46
// In Chonky v0.x, this field was user-configurable. In Chonky v1.x+, we hardcode
@@ -61,7 +70,13 @@ export const FileList: React.FC<FileListProps> = React.memo(() => {
61
70
>
62
71
< div className = { localClasses . dndDropZone } >
63
72
< div className = { localClasses . dndDropZoneIcon } >
64
- < ChonkyIcon icon = { ChonkyIconName . dndCanDrop } />
73
+ < ChonkyIcon
74
+ icon = {
75
+ dndCanDrop
76
+ ? ChonkyIconName . dndCanDrop
77
+ : ChonkyIconName . dndCannotDrop
78
+ }
79
+ />
65
80
</ div >
66
81
</ div >
67
82
< AutoSizer disableHeight = { ! fillParentContainer } > { listRenderer } </ AutoSizer >
@@ -72,16 +87,23 @@ export const FileList: React.FC<FileListProps> = React.memo(() => {
72
87
const useLocalStyles = makeLocalChonkyStyles ( ( theme ) => ( {
73
88
fileListWrapper : {
74
89
minHeight : ChonkyActions . EnableGridView . fileViewConfig . entryHeight + 2 ,
75
- background : ( showIndicator : boolean ) =>
76
- showIndicator
77
- ? getStripeGradient (
78
- theme . dnd . fileListMaskOne ,
79
- theme . dnd . fileListMaskTwo
80
- )
90
+ background : ( state : StyleState ) =>
91
+ state . dndIsOverCurrent && state . dndCanDrop
92
+ ? state . dndCanDrop
93
+ ? getStripeGradient (
94
+ theme . dnd . fileListCanDropMaskOne ,
95
+ theme . dnd . fileListCanDropMaskTwo
96
+ )
97
+ : getStripeGradient (
98
+ theme . dnd . fileListCannotDropMaskOne ,
99
+ theme . dnd . fileListCannotDropMaskTwo
100
+ )
81
101
: 'none' ,
82
102
} ,
83
103
dndDropZone : {
84
- display : ( showIndicator : boolean ) => ( showIndicator ? 'block' : 'none' ) ,
104
+ display : ( state : StyleState ) =>
105
+ // When we cannot drop, we don't show an indicator at all
106
+ state . dndIsOverCurrent && state . dndCanDrop ? 'block' : 'none' ,
85
107
borderRadius : theme . gridFileEntry . borderRadius ,
86
108
pointerEvents : 'none' ,
87
109
position : 'absolute' ,
@@ -90,10 +112,12 @@ const useLocalStyles = makeLocalChonkyStyles((theme) => ({
90
112
zIndex : 2 ,
91
113
} ,
92
114
dndDropZoneIcon : {
115
+ backgroundColor : ( state : StyleState ) =>
116
+ state . dndCanDrop ? theme . dnd . canDropMask : theme . dnd . cannotDropMask ,
117
+ color : ( state : StyleState ) =>
118
+ state . dndCanDrop ? theme . dnd . canDropColor : theme . dnd . cannotDropColor ,
93
119
borderRadius : theme . gridFileEntry . borderRadius ,
94
120
transform : 'translateX(-50%) translateY(-50%)' ,
95
- backgroundColor : theme . dnd . canDropMask ,
96
- color : theme . dnd . canDropColor ,
97
121
position : 'absolute' ,
98
122
textAlign : 'center' ,
99
123
lineHeight : '60px' ,
0 commit comments