@@ -6,7 +6,7 @@ import { run, runEffect } from "@filen/utils"
66import Image from "@/components/ui/image"
77import { FileIcon , DirectoryIcon } from "@/components/itemIcons"
88import { DirColor } from "@filen/sdk-rs"
9- import { useRecyclingState } from "@shopify/flash-list"
9+ import { type RenderTarget , useRecyclingState } from "@shopify/flash-list"
1010import { AppState } from "react-native"
1111import useHttpStore from "@/stores/useHttp.store"
1212import { useFocusEffect } from "expo-router"
@@ -38,12 +38,14 @@ const FileThumbnailWithGenerate = memo(
3838 item,
3939 size,
4040 className,
41- contentFit
41+ contentFit,
42+ target = "Cell"
4243 } : {
4344 item : DriveItemFileExtracted
4445 size : ThumbnailSize
4546 className ?: string
4647 contentFit ?: React . ComponentProps < typeof Image > [ "contentFit" ]
48+ target ?: RenderTarget
4749 } ) => {
4850 const abortControllerRef = useRef < AbortController | null > ( null )
4951 const errorRetryCountRef = useRef < number > ( 0 )
@@ -69,13 +71,11 @@ const FileThumbnailWithGenerate = memo(
6971 }
7072 )
7173
72- const localPathRef = useRef ( localPath )
73-
74- useEffect ( ( ) => {
75- localPathRef . current = localPath
76- } , [ localPath ] )
77-
7874 const generate = useCallback ( async ( ) => {
75+ if ( target !== "Cell" || localPath || ! thumbnails . canGenerate ( item ) || AppState . currentState !== "active" ) {
76+ return
77+ }
78+
7979 const result = await run ( async defer => {
8080 if ( isGeneratingRef . current ) {
8181 return
@@ -87,7 +87,7 @@ const FileThumbnailWithGenerate = memo(
8787 isGeneratingRef . current = false
8888 } )
8989
90- if ( localPathRef . current || ! thumbnails . canGenerate ( item ) || AppState . currentState !== "active" ) {
90+ if ( target !== "Cell" || localPath || ! thumbnails . canGenerate ( item ) || AppState . currentState !== "active" ) {
9191 return
9292 }
9393
@@ -137,13 +137,7 @@ const FileThumbnailWithGenerate = memo(
137137
138138 return
139139 }
140- } , [ item , setLocalPath ] )
141-
142- const generateRef = useRef ( generate )
143-
144- useEffect ( ( ) => {
145- generateRef . current = generate
146- } , [ generate ] )
140+ } , [ item , setLocalPath , target , localPath ] )
147141
148142 const onFailure = ( ) => {
149143 cache . availableThumbnails . delete ( item . data . uuid )
@@ -158,20 +152,29 @@ const FileThumbnailWithGenerate = memo(
158152
159153 thumbnails . remove ( item )
160154
161- localPathRef . current = null
162-
163155 setLocalPath ( null )
164156
165- generateRef . current ?.( )
157+ generate ( )
158+ }
159+
160+ const source = ! localPath
161+ ? null
162+ : {
163+ uri : localPath
164+ }
165+
166+ const imageStyle = {
167+ width : size . thumbnail ,
168+ height : size . thumbnail
166169 }
167170
168171 useEffect ( ( ) => {
169172 errorRetryCountRef . current = 0
170173
171- if ( ! localPathRef . current ) {
174+ if ( ! localPath ) {
172175 generate ( )
173176 }
174- } , [ generate ] )
177+ } , [ target , generate , localPath ] )
175178
176179 useEffect ( ( ) => {
177180 const { cleanup } = runEffect ( defer => {
@@ -234,17 +237,6 @@ const FileThumbnailWithGenerate = memo(
234237 } , [ ] )
235238 )
236239
237- const source = ! localPath
238- ? null
239- : {
240- uri : localPath
241- }
242-
243- const imageStyle = {
244- width : size . thumbnail ,
245- height : size . thumbnail
246- }
247-
248240 if ( ! localPath || ! source ) {
249241 return (
250242 < FileIcon
@@ -275,12 +267,14 @@ const FileThumbnail = memo(
275267 item,
276268 size,
277269 className,
278- contentFit
270+ contentFit,
271+ target
279272 } : {
280273 item : DriveItemFileExtracted
281274 size : ThumbnailSize
282275 className ?: string
283276 contentFit ?: React . ComponentProps < typeof Image > [ "contentFit" ]
277+ target ?: RenderTarget
284278 } ) => {
285279 const [ localPath ] = useRecyclingState < string | null > ( ( ) => {
286280 const available = cache . availableThumbnails . get ( item . data . uuid )
@@ -325,6 +319,7 @@ const FileThumbnail = memo(
325319 size = { size }
326320 className = { className }
327321 contentFit = { contentFit }
322+ target = { target }
328323 />
329324 )
330325 }
@@ -335,12 +330,14 @@ const Thumbnail = memo(
335330 item,
336331 size,
337332 className,
338- contentFit
333+ contentFit,
334+ target
339335 } : {
340336 item : DriveItem
341337 size : ThumbnailSize
342338 className ?: string
343339 contentFit ?: React . ComponentProps < typeof Image > [ "contentFit" ]
340+ target ?: RenderTarget
344341 } ) => {
345342 if ( item . type === "file" || item . type === "sharedFile" || item . type === "sharedRootFile" ) {
346343 return (
@@ -349,6 +346,7 @@ const Thumbnail = memo(
349346 size = { size }
350347 className = { className }
351348 contentFit = { contentFit }
349+ target = { target }
352350 />
353351 )
354352 }
0 commit comments