Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update to handle isSourceLoaded and conversion failed related state update locally

Abhinav243c9a4d4930
diff --git a/apps/photos/src/components/PhotoViewer/index.tsx b/apps/photos/src/components/PhotoViewer/index.tsx
index 6278f9d889..144b06cc93 100644
--- a/apps/photos/src/components/PhotoViewer/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/index.tsx
@@ -82,18 +82,22 @@ interface Iprops {
isTrashCollection: boolean;
isInHiddenSection: boolean;
enableDownload: boolean;
- isSourceLoaded: boolean;
- conversionFailed: boolean;
fileToCollectionsMap: Map<number, number[]>;
collectionNameMap: Map<number, string>;
}
function PhotoViewer(props: Iprops) {
+ const galleryContext = useContext(GalleryContext);
+ const appContext = useContext(AppContext);
+ const publicCollectionGalleryContext = useContext(
+ PublicCollectionGalleryContext
+ );
+
+ const { isOpen, items } = props;
+
const pswpElement = useRef<HTMLDivElement>();
const [photoSwipe, setPhotoSwipe] =
useState<Photoswipe<Photoswipe.Options>>();
-
- const { isOpen, items, isSourceLoaded, conversionFailed } = props;
const [isFav, setIsFav] = useState(false);
const [showInfo, setShowInfo] = useState(false);
const [exif, setExif] =
@@ -102,21 +106,14 @@ function PhotoViewer(props: Iprops) {
const [livePhotoBtnOptions, setLivePhotoBtnOptions] = useState(
defaultLivePhotoDefaultOptions
);
- const needUpdate = useRef(false);
- const publicCollectionGalleryContext = useContext(
- PublicCollectionGalleryContext
- );
-
- const galleryContext = useContext(GalleryContext);
- const appContext = useContext(AppContext);
+ const [isOwnFile, setIsOwnFile] = useState(false);
+ const [showConvertBtn, setShowConvertBtn] = useState(false);
+ const [isSourceLoaded, setIsSourceLoaded] = useState(false);
+ const needUpdate = useRef(false);
const exifExtractionInProgress = useRef<string>(null);
const shouldShowCopyOption = useMemo(() => isClipboardItemPresent(), []);
- const [isOwnFile, setIsOwnFile] = useState(false);
-
- const [showConvertBtn, setShowConvertBtn] = useState(false);
-
const [
conversionFailedNotificationOpen,
setConversionFailedNotificationOpen,
@@ -149,11 +146,6 @@ function PhotoViewer(props: Iprops) {
};
}, [isOpen]);
- useEffect(() => {
- if (!isOpen) return;
- setConversionFailedNotificationOpen(conversionFailed);
- }, [isOpen, conversionFailed]);
-
useEffect(() => {
if (!photoSwipe) return;
function handleCopyEvent() {
@@ -273,19 +265,6 @@ function PhotoViewer(props: Iprops) {
};
}, [photoSwipe?.currItem, isOpen, isSourceLoaded]);
- useEffect(() => {
- const file = photoSwipe?.currItem as EnteFile;
- if (!file) return;
-
- const shouldShowConvertBtn =
- (file.metadata.fileType === FILE_TYPE.VIDEO ||
- file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) &&
- !file.isConverted &&
- isSourceLoaded &&
- !conversionFailed;
- setShowConvertBtn(shouldShowConvertBtn);
- }, [photoSwipe?.currItem, isSourceLoaded, conversionFailed]);
-
useEffect(() => {
exifCopy.current = exif;
}, [exif]);
@@ -301,6 +280,40 @@ function PhotoViewer(props: Iprops) {
setIsOwnFile(isOwnFile);
}
+ function updateExif(file: EnteFile) {
+ if (file.metadata.fileType !== FILE_TYPE.IMAGE) {
+ setExif({ key: file.src, value: null });
+ return;
+ }
+ if (
+ !file ||
+ !exifCopy?.current?.value === null ||
+ exifCopy?.current?.key === file.src
+ ) {
+ return;
+ }
+ setExif({ key: file.src, value: undefined });
+ checkExifAvailable(file);
+ }
+
+ function updateShowConvertBtn(file: EnteFile) {
+ const shouldShowConvertBtn =
+ (file.metadata.fileType === FILE_TYPE.VIDEO ||
+ file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) &&
+ !file.isConverted &&
+ file.isSourceLoaded &&
+ !file.conversionFailed;
+ setShowConvertBtn(shouldShowConvertBtn);
+ }
+
+ function updateConversionFailedNotification(file: EnteFile) {
+ setConversionFailedNotificationOpen(file.conversionFailed);
+ }
+
+ function updateIsSourceLoaded(file: EnteFile) {
+ setIsSourceLoaded(file.isSourceLoaded);
+ }
+
const openPhotoSwipe = () => {
const { items, currentIndex } = props;
const options = {
@@ -369,36 +382,18 @@ function PhotoViewer(props: Iprops) {
}
updateFavButton(currItem);
updateIsOwnFile(currItem);
- if (currItem.metadata.fileType !== FILE_TYPE.IMAGE) {
- setExif({ key: currItem.src, value: null });
- return;
- }
- if (
- !currItem ||
- !exifCopy?.current?.value === null ||
- exifCopy?.current?.key === currItem.src
- ) {
- return;
- }
- setExif({ key: currItem.src, value: undefined });
- checkExifAvailable(currItem);
+ updateConversionFailedNotification(currItem);
+ updateExif(currItem);
+ updateShowConvertBtn(currItem);
+ updateIsSourceLoaded(currItem);
});
photoSwipe.listen('resize', () => {
if (!photoSwipe?.currItem) return;
const currItem = photoSwipe.currItem as EnteFile;
- if (currItem.metadata.fileType !== FILE_TYPE.IMAGE) {
- setExif({ key: currItem.src, value: null });
- return;
- }
- if (
- !currItem ||
- !exifCopy?.current?.value === null ||
- exifCopy?.current?.key === currItem.src
- ) {
- return;
- }
- setExif({ key: currItem.src, value: undefined });
- checkExifAvailable(currItem);
+ updateExif(currItem);
+ updateConversionFailedNotification(currItem);
+ updateShowConvertBtn(currItem);
+ updateIsSourceLoaded(currItem);
});
photoSwipe.init();
needUpdate.current = false;