1
1
import classnames from 'classnames' ;
2
2
import React , { MouseEvent , ReactNode , ReactText , useRef } from 'react' ;
3
3
import { FileLike } from '../../data' ;
4
- import { useAccessibleFocus , useFile , useFocus } from '../../hooks' ;
4
+ import { useAccessibleFocus , useFileSubscribe , useFocus } from '../../hooks' ;
5
5
import { ClickableDiv , ClickableDivProps } from '../ClickableDiv' ;
6
6
import { EditableText } from '../EditableText' ;
7
7
import { FilePlaceholder } from '../FilePlaceholder' ;
@@ -75,7 +75,7 @@ export interface ThumbnailProps<F> extends ClickableDivProps {
75
75
}
76
76
77
77
export function Thumbnail < F extends FileLike > ( {
78
- file : _file ,
78
+ file,
79
79
label,
80
80
selected,
81
81
dragging,
@@ -99,19 +99,21 @@ export function Thumbnail<F extends FileLike>({
99
99
100
100
const { focused, handleOnFocus, handleOnBlur } = useFocus ( onFocus , onBlur ) ;
101
101
102
- const file = useFile ( _file , isShownOnLoad ? 0 : throttle ) ;
102
+ const toThrottle = isShownOnLoad ? 0 : throttle ;
103
+ const [ thumbnail , thumbnailErr ] = useFileSubscribe ( file , f => f . thumbnail , 'onthumbnailchange' , toThrottle ) ;
104
+ const [ name ] = useFileSubscribe ( file , f => f . name , 'onnamechange' ) ;
103
105
104
106
const handleOnSave = ( newName : string ) => {
105
- onRename ?.( newName , file . file ) ;
106
- onEditingChange ?.( false , file . file ) ;
107
+ onRename ?.( newName , file ) ;
108
+ onEditingChange ?.( false , file ) ;
107
109
} ;
108
110
109
111
const handleOnCancel = ( ) => {
110
- onEditingChange ?.( false , file . file ) ;
112
+ onEditingChange ?.( false , file ) ;
111
113
} ;
112
114
113
115
const handleOnEdit = ( ) => {
114
- onEditingChange ?.( true , file . file ) ;
116
+ onEditingChange ?.( true , file ) ;
115
117
} ;
116
118
117
119
const thumbnailClass = classnames (
@@ -139,9 +141,9 @@ export function Thumbnail<F extends FileLike>({
139
141
>
140
142
< div className = "ui__thumbnail__image" >
141
143
< Image
142
- src = { file . thumbnail }
143
- alt = { file . name }
144
- pending = { ! file . thumbnail && ! file . errors . thumbnail }
144
+ src = { thumbnail }
145
+ alt = { name }
146
+ pending = { ! thumbnail && ! thumbnailErr }
145
147
onRenderLoading = { ( ) => < FileSkeleton className = "ui__thumbnail__image__skeleton" /> }
146
148
onRenderFallback = { ( ) => (
147
149
< FilePlaceholder className = "ui__thumbnail__image__placeholder" extension = { file . extension } />
@@ -151,15 +153,15 @@ export function Thumbnail<F extends FileLike>({
151
153
</ div >
152
154
< div className = "ui__thumbnail__controls" >
153
155
{ buttonProps ?. map ( ( { key, ...buttonPropObject } ) => (
154
- < ToolButton key = { key } disabled = { disabled } onClick = { e => buttonPropObject . onClick ( e , file . file ) } >
156
+ < ToolButton key = { key } disabled = { disabled } onClick = { e => buttonPropObject . onClick ( e , file ) } >
155
157
{ buttonPropObject . children }
156
158
</ ToolButton >
157
159
) ) }
158
160
</ div >
159
161
{ selectedIcon ? < div className = "ui__thumbnail__selectedIcon" > { selectedIcon } </ div > : undefined }
160
162
< EditableText
161
163
className = "ui__thumbnail__label"
162
- value = { label ?? file . name }
164
+ value = { label ?? name }
163
165
centerText
164
166
disabled = { disabled }
165
167
locked = { ! onRename || otherDragging }
0 commit comments