@@ -5,6 +5,7 @@ import { fs } from '@internxt-mobile/services/FileSystemService';
55import { notifications } from '@internxt-mobile/services/NotificationsService' ;
66import { FileExtension } from '@internxt-mobile/types/drive' ;
77import { RootStackScreenProps } from '@internxt-mobile/types/navigation' ;
8+ import { Thumbnail } from '@internxt/sdk/dist/drive/storage/types' ;
89import strings from 'assets/lang/strings' ;
910import { WarningCircle } from 'phosphor-react-native' ;
1011import React , { useEffect , useRef , useState } from 'react' ;
@@ -16,6 +17,7 @@ import AppScreen from 'src/components/AppScreen';
1617import AppText from 'src/components/AppText' ;
1718import { DEFAULT_EASING } from 'src/components/modals/SharedLinkSettingsModal/animations' ;
1819import { getFileTypeIcon } from 'src/helpers' ;
20+ import { useDrive } from 'src/hooks/drive' ;
1921import { useAppDispatch , useAppSelector } from 'src/store/hooks' ;
2022import { uiActions } from 'src/store/slices/ui' ;
2123import { getLineHeight } from 'src/styles/global' ;
@@ -25,6 +27,7 @@ import { DriveImagePreview } from './DriveImagePreview';
2527import { DrivePdfPreview } from './DrivePdfPreview' ;
2628import { DRIVE_PREVIEW_HEADER_HEIGHT , DrivePreviewScreenHeader } from './DrivePreviewScreenHeader' ;
2729import { DriveVideoPreview } from './DriveVideoPreview' ;
30+ import { useThumbnailRegeneration } from './hooks/useThumbnailRegeneration' ;
2831import AnimatedLoadingDots from './LoadingDots' ;
2932
3033const IMAGE_PREVIEW_TYPES = [ FileExtension . PNG , FileExtension . JPG , FileExtension . JPEG , FileExtension . HEIC ] ;
@@ -40,6 +43,7 @@ export const DrivePreviewScreen: React.FC<RootStackScreenProps<'DrivePreview'>>
4043 // REDUX USAGE STARTS
4144 const insets = useSafeAreaInsets ( ) ;
4245 const dispatch = useAppDispatch ( ) ;
46+ const driveCtx = useDrive ( ) ;
4347 // REDUX USAGE ENDS
4448 const { downloadingFile } = useAppSelector ( ( state ) => state . drive ) ;
4549 // Use this in order to listen for state changes
@@ -63,6 +67,32 @@ export const DrivePreviewScreen: React.FC<RootStackScreenProps<'DrivePreview'>>
6367 }
6468 } , [ downloadingFile ?. downloadedFilePath ] ) ;
6569
70+ const updateItemWithNewThumbnail = ( thumbnail : Thumbnail ) => {
71+ if ( ! focusedItem ?. folderUuid ) return ;
72+
73+ driveCtx . updateItemInTree ( focusedItem . folderUuid , focusedItem . id , {
74+ thumbnails : [ thumbnail ] ,
75+ } ) ;
76+ dispatch (
77+ driveActions . setFocusedItem ( {
78+ ...focusedItem ,
79+ thumbnails : [ thumbnail ] ,
80+ } ) ,
81+ ) ;
82+ } ;
83+
84+ useThumbnailRegeneration (
85+ {
86+ downloadedFilePath : downloadingFile ?. downloadedFilePath ,
87+ fileExtension : focusedItem ?. type ,
88+ fileUuid : focusedItem ?. uuid ,
89+ hasThumbnails : ! ! ( focusedItem ?. thumbnails && focusedItem . thumbnails . length > 0 ) ,
90+ } ,
91+ {
92+ onSuccess : updateItemWithNewThumbnail ,
93+ } ,
94+ ) ;
95+
6696 useEffect ( ( ) => {
6797 Animated . timing ( topbarYPosition , {
6898 toValue : topbarVisible ? 0 : - totalHeaderHeight ,
0 commit comments