π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
import type { RemotePullOpts } from "@/components/gallery";
import { usePhotosNavigation } from "@/components/gallery/navigation/PhotosNavigationContext";
import { downloadAndSaveFiles } from "@/services/save";
import { uploadManager } from "@/services/upload-manager";
import { fileTimelineDateString } from "@/utils/file";
import { styled } from "@mui/material";
import type { AddSaveGroup } from "ente-gallery/components/utils/save-groups";
import {
FileViewer,
type FileViewerProps,
} from "ente-gallery/components/viewer/FileViewer";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { moveToTrash } from "ente-new/photos/services/collection";
import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { usePhotosAppContext } from "ente-new/photos/types/context";
import { t } from "i18next";
import { useCallback, useEffect, useMemo, useState } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
import {
FileList,
type FileListAnnotatedFile,
type FileListProps,
} from "./FileList";
export type FileListWithViewerProps = {
files: EnteFile[];
enableDownload?: boolean;
enableImageEditing?: boolean;
onMarkTempDeleted?: (files: EnteFile[]) => void;
onSetOpenFileViewer?: (open: boolean) => void;
onRemotePull: (opts?: RemotePullOpts) => Promise<void>;
activeCollectionSummary?: CollectionSummary;
onAddSaveGroup: AddSaveGroup;
onAddFileToCollection?: (
file: EnteFile,
sourceCollectionSummaryID?: number,
) => void;
onScroll?: (scrollOffset: number) => void;
onVisibleDateChange?: (date: string | undefined) => void;
} & Pick<
FileListProps,
| "mode"
| "modePlus"
| "header"
| "footer"
| "onAddPhotos"
| "disableGrouping"
| "enableSelect"
| "enableDateScrubber"
| "selected"
| "setSelected"
| "activeCollectionID"
| "activePersonID"
| "favoriteFileIDs"
| "emailByUserID"
| "listBorderRadius"
| "gridLayout"
| "onContextMenuAction"
| "onContextMenuOpenChange"
| "showAddPersonAction"
| "showEditLocationAction"
| "suppressSelectionUI"
> &
Pick<
FileViewerProps,
| "user"
| "isInIncomingSharedCollection"
| "isInHiddenSection"
| "fileNormalCollectionIDs"
| "fileCollectionIDs"
| "hiddenCollectionIDs"
| "collectionSummaries"
| "collectionNameByID"
| "pendingFavoriteUpdates"
| "pendingVisibilityUpdates"
| "onRemoteFilesPull"
| "onVisualFeedback"
| "onToggleFavorite"
| "onFileVisibilityUpdate"
| "onSendLink"
>;
export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
mode,
modePlus,
header,
footer,
onAddPhotos,
user,
files,
enableDownload,
enableImageEditing = true,
disableGrouping,
enableSelect,
enableDateScrubber,
selected,
setSelected,
activeCollectionID,
activePersonID,
activeCollectionSummary,
favoriteFileIDs,
emailByUserID,
listBorderRadius,
gridLayout,
onContextMenuAction,
onContextMenuOpenChange,
showAddPersonAction,
showEditLocationAction,
suppressSelectionUI,
isInIncomingSharedCollection,
isInHiddenSection,
fileNormalCollectionIDs,
fileCollectionIDs,
hiddenCollectionIDs,
collectionSummaries,
collectionNameByID,
pendingFavoriteUpdates,
pendingVisibilityUpdates,
onSetOpenFileViewer,
onRemotePull,
onRemoteFilesPull,
onVisualFeedback,
onAddSaveGroup,
onToggleFavorite,
onFileVisibilityUpdate,
onSendLink,
onMarkTempDeleted,
onAddFileToCollection,
onScroll,
onVisibleDateChange,
}) => {
const {
selectCollectionFromViewer: onSelectCollection,
selectPerson: onSelectPerson,
} = usePhotosNavigation();
const [openFileViewer, setOpenFileViewer] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0);
const { showNotification, setIsFileViewerOpen } = usePhotosAppContext();
const updateOpenFileViewer = useCallback(
(open: boolean) => {
setOpenFileViewer(open);
setIsFileViewerOpen?.(open);
onSetOpenFileViewer?.(open);
},
[onSetOpenFileViewer, setIsFileViewerOpen],
);
useEffect(() => () => setIsFileViewerOpen?.(false), [setIsFileViewerOpen]);
const handleCloseFileViewerInternal = useCallback(() => {
updateOpenFileViewer(false);
}, [updateOpenFileViewer]);
const annotatedFiles = useMemo(
(): FileListAnnotatedFile[] =>
files.map((file) => ({
file,
timelineDateString: fileTimelineDateString(file),
})),
[files],
);
const handleThumbnailClick = useCallback(
(index: number) => {
setCurrentIndex(index);
updateOpenFileViewer(true);
},
[updateOpenFileViewer],
);
const handleTriggerRemotePull = useCallback(
() => void onRemotePull({ source: "file-viewer-action" }),
[onRemotePull],
);
const handleDownload = useCallback(
(file: EnteFile) =>
downloadAndSaveFiles([file], fileFileName(file), onAddSaveGroup),
[onAddSaveGroup],
);
const handleDelete = useMemo(() => {
return onMarkTempDeleted
? (file: EnteFile) =>
moveToTrash([file]).then(() => onMarkTempDeleted([file]))
: undefined;
}, [onMarkTempDeleted]);
const handleSaveEditedImageCopy = useMemo(() => {
if (!enableImageEditing) return undefined;
return (
editedFile: File,
collection: Collection,
enteFile: EnteFile,
) => {
if (uploadManager.isUploadInProgress()) {
showNotification({
color: "critical",
title: t("uploads_in_progress"),
caption: t("wait_for_active_upload_to_finish"),
});
return false;
}
uploadManager.prepareForNewUpload();
uploadManager.showUploadProgressDialog();
void uploadManager.uploadFile(editedFile, collection, enteFile);
return true;
};
}, [enableImageEditing, showNotification]);
return (
<Container>
<AutoSizer>
{({ height, width }) => (
<FileList
{...{ width, height, annotatedFiles }}
{...{
mode,
modePlus,
header,
footer,
onAddPhotos,
user,
disableGrouping,
enableSelect,
enableDateScrubber,
selected,
setSelected,
activeCollectionID,
activePersonID,
favoriteFileIDs,
emailByUserID,
listBorderRadius,
gridLayout,
onScroll,
onVisibleDateChange,
collectionSummary: activeCollectionSummary,
onContextMenuAction,
onContextMenuOpenChange,
showAddPersonAction,
showEditLocationAction,
suppressSelectionUI,
}}
onItemClick={handleThumbnailClick}
/>
)}
</AutoSizer>
<FileViewer
open={openFileViewer}
onClose={handleCloseFileViewerInternal}
initialIndex={currentIndex}
disableDownload={!enableDownload}
isInTrashSection={
activeCollectionID == PseudoCollectionID.trash
}
{...{
user,
files,
isInHiddenSection,
isInIncomingSharedCollection,
favoriteFileIDs,
fileNormalCollectionIDs,
fileCollectionIDs,
hiddenCollectionIDs,
collectionSummaries,
collectionNameByID,
pendingFavoriteUpdates,
pendingVisibilityUpdates,
onRemoteFilesPull,
onVisualFeedback,
onToggleFavorite,
onFileVisibilityUpdate,
onSendLink,
onSelectCollection,
onSelectPerson,
}}
isCommentsFeatureEnabled
onTriggerRemotePull={handleTriggerRemotePull}
onDownload={handleDownload}
onDelete={handleDelete}
onSaveEditedImageCopy={handleSaveEditedImageCopy}
onAddFileToCollection={onAddFileToCollection}
activeCollectionID={activeCollectionID}
/>
</Container>
);
};
const Container = styled("div")`
flex: 1;
width: 100%;
`;