π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip re
Manav Rathi0b7aa97db169
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsxindex 0f29e50c09..5d164c9ad3 100644--- a/web/apps/photos/src/components/PhotoFrame.tsx+++ b/web/apps/photos/src/components/PhotoFrame.tsx@@ -1,12 +1,10 @@import { isSameDay } from "@/base/date";import { formattedDate } from "@/base/i18n-date";-import log from "@/base/log";import type { FileInfoProps } from "@/gallery/components/FileInfo";import { FileViewer } from "@/gallery/components/viewer/FileViewer";import { type RenderableSourceURLs } from "@/gallery/services/download";import type { Collection } from "@/media/collection";import { EnteFile } from "@/media/file";-import { FileType } from "@/media/file-type";import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";import { moveToTrash, TRASH_SECTION } from "@/new/photos/services/collection";import { styled } from "@mui/material";@@ -25,7 +23,7 @@ import {} from "types/gallery";import { downloadSingleFile } from "utils/file";import { handleSelectCreator } from "utils/photoFrame";-import { PhotoList } from "./PhotoList";+import { PhotoList, type FileListAnnotatedFile } from "./PhotoList";import PreviewCard from "./pages/gallery/PreviewCard";const Container = styled("div")`@@ -179,20 +177,12 @@ const PhotoFrame = ({const [rangeStart, setRangeStart] = useState(null);const [currentHover, setCurrentHover] = useState(null);const [isShiftKeyPressed, setIsShiftKeyPressed] = useState(false);- const [displayFiles, setDisplayFiles] = useState<DisplayFile[] | undefined>(- undefined,- );- useEffect(() => {- // TODO(PS): Audit- const result = files.map((file) => ({- ...file,- w: window.innerWidth,- h: window.innerHeight,- title: file.pubMagicMetadata?.data.caption,+ const annotatedFileListFiles = useMemo((): FileListAnnotatedFile[] => {+ return files.map((file) => ({+ file,timelineDateString: fileTimelineDateString(file),}));- setDisplayFiles(result);}, [files]);const handleThumbnailClick = useCallback((index: number) => {@@ -281,30 +271,6 @@ const PhotoFrame = ({}}, [selected]);- if (!displayFiles) {- return <div />;- }-- // Return a (curried) function which will return true if the URL was updated- // (for the given params), and false otherwise.- const updateThumbURL =- (index: number) => (id: number, url: string, forceUpdate?: boolean) => {- const file = displayFiles[index];- // This is to prevent outdated call from updating the wrong file.- if (file.id !== id) {- log.info(- `Ignoring stale updateThumbURL for display file at index ${index} (file ID ${file.id}, expected ${id})`,- );- throw Error("Update URL file id mismatch");- }- if (file.msrc && !forceUpdate) {- return false;- }- // TODO(PS): Audit- updateDisplayFileThumbnail(file, url);- return true;- };-const handleSelect = handleSelectCreator(setSelected,mode,@@ -328,16 +294,17 @@ const PhotoFrame = ({(index - i) * direction >= 0;i += direction) {- checked = checked && !!selected[displayFiles[i].id];+ checked =+ checked && !!selected[annotatedFileListFiles[i].file.id];}for (let i = rangeStart;(index - i) * direction > 0;i += direction) {- handleSelect(displayFiles[i])(!checked);+ handleSelect(annotatedFileListFiles[i].file)(!checked);}- handleSelect(displayFiles[index], index)(!checked);+ handleSelect(annotatedFileListFiles[index].file, index)(!checked);}};@@ -349,7 +316,6 @@ const PhotoFrame = ({<PreviewCardkey={`tile-${item.id}-selected-${selected[item.id] ?? false}`}file={item}- updateURL={updateThumbURL(index)}onClick={() => handleThumbnailClick(index)}selectable={selectable}onSelect={handleSelect(item, index)}@@ -403,6 +369,10 @@ const PhotoFrame = ({};*/+ if (!annotatedFileListFiles.length) {+ return <></>;+ }+return (<Container><AutoSizer>@@ -413,7 +383,7 @@ const PhotoFrame = ({getThumbnail={getThumbnail}mode={mode}modePlus={modePlus}- displayFiles={displayFiles}+ annotatedFiles={annotatedFileListFiles}activeCollectionID={activeCollectionID}activePersonID={activePersonID}showAppDownloadBanner={showAppDownloadBanner}@@ -449,24 +419,6 @@ const PhotoFrame = ({export default PhotoFrame;-const updateDisplayFileThumbnail = (file: DisplayFile, url: string) => {- file.w = window.innerWidth;- file.h = window.innerHeight;- file.msrc = url;- file.canForceConvert = false;- file.isSourceLoaded = false;- file.conversionFailed = false;- if (file.metadata.fileType === FileType.image) {- file.src = url;- } else {- file.html = `- <div class = 'pswp-item-container'>- <img src="${url}"/>- </div>- `;- }-};-/*** See: [Note: Timeline date string]*/diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsxindex 4a68fa1cfd..6a85f02b46 100644--- a/web/apps/photos/src/components/PhotoList/index.tsx+++ b/web/apps/photos/src/components/PhotoList/index.tsx@@ -175,10 +175,23 @@ const NothingContainer = styled(ListItemContainer)`justify-content: center;`;+export interface FileListAnnotatedFile {+ file: EnteFile;+ /**+ * The date string using with the associated {@link file} should be shown in+ * the timeline.+ *+ * This for used for grouping files: all files which have the same+ * {@link timelineDateString} are grouped together into a section titled+ * with that {@link timelineDateString}.+ */+ timelineDateString: string;+}+type Props = Pick<PhotoFrameProps, "mode" | "modePlus"> & {height: number;width: number;- displayFiles: (EnteFile & { timelineDateString?: string })[];+ annotatedFiles: FileListAnnotatedFile[];showAppDownloadBanner: boolean;getThumbnail: (file: EnteFile,@@ -243,7 +256,7 @@ export function PhotoList({width,mode,modePlus,- displayFiles,+ annotatedFiles,showAppDownloadBanner,getThumbnail,activeCollectionID,@@ -338,7 +351,7 @@ export function PhotoList({}, [width,height,- displayFiles,+ annotatedFiles,galleryContext.photoListHeader,publicCollectionGalleryContext.photoListHeader,galleryContext.isClipSearchResult,@@ -414,7 +427,7 @@ export function PhotoList({const groupByTime = (timeStampList: TimeStampListItem[]) => {let listItemIndex = 0;let currentDate;- displayFiles.forEach((item, index) => {+ annotatedFiles.forEach((item, index) => {if (!currentDate ||!isSameDay(diff --git a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsxindex 79ca1d167a..ad496e9d06 100644--- a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx+++ b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx@@ -22,9 +22,8 @@ import React, { useContext, useEffect, useRef, useState } from "react";import { shouldShowAvatar } from "utils/file";import Avatar from "./Avatar";-interface IProps {+interface PreviewCardProps {file: DisplayFile;- updateURL: (id: number, url: string) => void;onClick: () => void;selectable: boolean;selected: boolean;@@ -200,7 +199,21 @@ const Cont = styled("div")<{ disabled: boolean }>`border-radius: 4px;`;-export default function PreviewCard(props: IProps) {+export default function PreviewCard({+ file,+ onClick,+ selectable,+ selected,+ onSelect,+ selectOnClick,+ onHover,+ onRangeSelect,+ isRangeSelectActive,+ isInsSelectRange,+ isFav,+ activeCollectionID,+ showPlaceholder,+}: PreviewCardProps) {const galleryContext = useContext(GalleryContext);const longPressCallback = () => {@@ -209,21 +222,6 @@ export default function PreviewCard(props: IProps) {const longPress = useLongPress(longPressCallback, 500);- const {- file,- onClick,- updateURL,- selectable,- selected,- onSelect,- selectOnClick,- onHover,- onRangeSelect,- isRangeSelectActive,- isInsSelectRange,- isFav,- } = props;-const [imgSrc, setImgSrc] = useState<string>(file.msrc);const isMounted = useRef(true);@@ -243,21 +241,20 @@ export default function PreviewCard(props: IProps) {const url: string =await downloadManager.renderableThumbnailURL(file,- props.showPlaceholder,+ showPlaceholder,);if (!isMounted.current || !url) {return;}setImgSrc(url);- updateURL(file.id, url);} catch (e) {log.error("preview card useEffect failed", e);// no-op}};main();- }, [props.showPlaceholder]);+ }, [showPlaceholder]);const handleClick = () => {if (selectOnClick) {@@ -340,7 +337,7 @@ export default function PreviewCard(props: IProps) {<InSelectRangeOverlay />)}- {props?.activeCollectionID === TRASH_SECTION && file.isTrashed && (+ {activeCollectionID === TRASH_SECTION && file.isTrashed && (<TileBottomTextOverlay><Typography variant="small">{formattedDateRelative(enteFileDeletionDate(file))}