π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web] Add direct uploads to empty Photos albums (#14349)
Aswin Asok6074388536cd
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsxindex 70a0401c31..427a95b298 100644--- a/web/apps/photos/src/components/FileList.tsx+++ b/web/apps/photos/src/components/FileList.tsx@@ -108,6 +108,7 @@ export interface FileListProps {modePlus?: GalleryBarMode | "search";header?: FileListHeaderOrFooter;footer?: FileListHeaderOrFooter;+ onAddPhotos?: () => void;user?: LocalUser;disableGrouping?: boolean;enableSelect?: boolean;@@ -143,6 +144,7 @@ export const FileList: React.FC<FileListProps> = ({modePlus,header,footer,+ onAddPhotos,user,annotatedFiles,disableGrouping,@@ -309,13 +311,13 @@ export const FileList: React.FC<FileListProps> = ({if (!annotatedFiles.length) {items.push({height: Math.max(- 340,+ onAddPhotos ? 412 : 340,height - (header?.height ?? 0) - (footer?.height ?? 0),),type: "span",component: (<NoFilesListItem>- <AlbumEmptyState />+ <AlbumEmptyState onAddPhotos={onAddPhotos} /></NoFilesListItem>),});@@ -342,6 +344,7 @@ export const FileList: React.FC<FileListProps> = ({height,header,footer,+ onAddPhotos,annotatedFiles,disableGrouping,layoutParams,diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex ca13189411..298db30ddb 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -47,6 +47,7 @@ export type FileListWithViewerProps = {| "modePlus"| "header"| "footer"+ | "onAddPhotos"| "disableGrouping"| "enableSelect"| "selected"@@ -87,6 +88,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({modePlus,header,footer,+ onAddPhotos,user,files,enableDownload,@@ -219,6 +221,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({modePlus,header,footer,+ onAddPhotos,user,disableGrouping,enableSelect,diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex d08daa364d..3012060551 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -104,6 +104,7 @@ interface UploadProps {dragAndDropFiles: File[];uploadTypeSelectorIntent: UploadTypeSelectorIntent;activeCollection?: Collection;+ uploadTargetCollection?: Collection;closeUploadTypeSelector: () => void;setLoading: (loading: boolean) => void;setShouldDisableDropzone: (value: boolean) => void;@@ -532,6 +533,14 @@ export const Upload: React.FC<UploadProps> = ({return;}+ if (props.uploadTargetCollection) {+ void uploadFilesToExistingCollection(+ props.uploadTargetCollection,+ prunedItemAndPaths,+ );+ return;+ }+if (electron && _selectedUploadType == "zips") {void uploadFilesToNewCollections("parent");return;diff --git a/web/apps/photos/src/components/gallery/hooks/use-gallery-uploads.ts b/web/apps/photos/src/components/gallery/hooks/use-gallery-uploads.tsindex b8a7cc4354..79bb3de838 100644--- a/web/apps/photos/src/components/gallery/hooks/use-gallery-uploads.ts+++ b/web/apps/photos/src/components/gallery/hooks/use-gallery-uploads.ts@@ -1,10 +1,11 @@import type { Upload } from "@/components/Upload";import { uploadManager } from "@/services/upload-manager";import type { UploadTypeSelectorIntent } from "ente-gallery/components/Upload";+import type { Collection } from "ente-media/collection";import { usePhotosAppContext } from "ente-new/photos/types/context";import { t } from "i18next";import type { ComponentProps } from "react";-import { useState } from "react";+import { useCallback, useState } from "react";import type { FileWithPath } from "react-dropzone";type UploadInputs = Pick<ComponentProps<typeof Upload>,@@ -42,10 +43,20 @@ export const useGalleryUploads = ({const [uploadTypeSelectorView, setUploadTypeSelectorView] = useState(false);const [uploadTypeSelectorIntent, setUploadTypeSelectorIntent] =useState<UploadTypeSelectorIntent>("upload");- const openUploader = (intent?: UploadTypeSelectorIntent) => {- if (uploadManager.isUploadInProgress()) return;- setUploadTypeSelectorView(true);- setUploadTypeSelectorIntent(intent ?? "upload");+ const [uploadTargetCollection, setUploadTargetCollection] =+ useState<Collection>();+ const openUploader = useCallback(+ (intent?: UploadTypeSelectorIntent, target?: Collection) => {+ if (uploadManager.isUploadInProgress()) return;+ setUploadTargetCollection(target);+ setUploadTypeSelectorIntent(intent ?? "upload");+ setUploadTypeSelectorView(true);+ },+ [],+ );+ const closeUploadTypeSelector = () => {+ setUploadTypeSelectorView(false);+ setUploadTargetCollection(undefined);};const uploadProps: ComponentProps<typeof Upload> | undefined = user? {@@ -55,10 +66,8 @@ export const useGalleryUploads = ({uploadTypeSelectorView,isFirstUpload,activeCollection,- closeUploadTypeSelector: setUploadTypeSelectorView.bind(- null,- false,- ),+ uploadTargetCollection,+ closeUploadTypeSelector,setLoading: setBlockingLoad,setShouldDisableDropzone,onRemotePull: remotePull,diff --git a/web/apps/photos/src/components/gallery/media/GalleryMedia.tsx b/web/apps/photos/src/components/gallery/media/GalleryMedia.tsxindex 70716a014d..2c95f6b377 100644--- a/web/apps/photos/src/components/gallery/media/GalleryMedia.tsx+++ b/web/apps/photos/src/components/gallery/media/GalleryMedia.tsx@@ -34,6 +34,7 @@ type GalleryMediaProps = Pick<> & {source: GalleryMediaSource;header?: FileListHeaderOrFooter;+ onAddPhotos?: () => void;children?: (hasSelection: boolean) => ReactNode;};@@ -57,6 +58,7 @@ const GalleryMediaContent = ({navigation,source,header,+ onAddPhotos,children,}: GalleryMediaProps) => {const { selected, setSelected, clearSelection } = useGallerySelection(@@ -223,6 +225,7 @@ const GalleryMediaContent = ({}user={library.user}header={header}+ onAddPhotos={onAddPhotos}footer={footer}enableDownloadenableSelectdiff --git a/web/apps/photos/src/components/gallery/sections/albums/AlbumEmptyState.tsx b/web/apps/photos/src/components/gallery/sections/albums/AlbumEmptyState.tsxindex f28194b52a..5aea3bc443 100644--- a/web/apps/photos/src/components/gallery/sections/albums/AlbumEmptyState.tsx+++ b/web/apps/photos/src/components/gallery/sections/albums/AlbumEmptyState.tsx@@ -1,7 +1,10 @@+import { ImageAdd02Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";import { Box, Stack, Typography } from "@mui/material";+import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";import { t } from "i18next";-export function AlbumEmptyState() {+export function AlbumEmptyState({ onAddPhotos }: { onAddPhotos?: () => void }) {return (<Stacksx={{@@ -47,18 +50,47 @@ export function AlbumEmptyState() {}}/></Box>- <Typography- sx={{- fontFamily: "'Outfit Variable', sans-serif",- fontWeight: 600,- fontSize: { xs: 28, sm: "36.372px" },- lineHeight: "1.333333",- color: "text.base",- textAlign: "center",- }}- >- {t("nothing_to_see_here")}- </Typography>+ <Stack sx={{ alignItems: "center", gap: 1.5 }}>+ <Typography+ sx={{+ fontFamily: "'Outfit Variable', sans-serif",+ fontWeight: 600,+ fontSize: { xs: 28, sm: "36.372px" },+ lineHeight: "1.333333",+ color: "text.base",+ textAlign: "center",+ }}+ >+ {t("nothing_to_see_here")}+ </Typography>+ {onAddPhotos && (+ <FocusVisibleButton+ color="secondary"+ onClick={onAddPhotos}+ startIcon={+ <HugeiconsIcon+ icon={ImageAdd02Icon}+ size={20}+ strokeWidth={1.8}+ />+ }+ sx={{+ minWidth: 140,+ height: 52,+ px: 3,+ borderRadius: "20px",+ border: 0,+ fontSize: "14px",+ fontWeight: 600,+ lineHeight: "20px",+ gap: 1,+ "& .MuiButton-startIcon": { m: 0 },+ }}+ >+ {t("add_photos")}+ </FocusVisibleButton>+ )}+ </Stack></Stack>);}diff --git a/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx b/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsxindex 4367d4e9b7..76b3a21c4d 100644--- a/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx+++ b/web/apps/photos/src/components/gallery/sections/albums/AlbumsSection.tsx@@ -18,6 +18,7 @@ import {} from "ente-gallery/components/utils/save-groups";import { ItemVisibility } from "ente-media/file-metadata";import {+ canAddFilesToCollection,renameCollection,updateCollectionDetails,} from "ente-new/photos/services/collection";@@ -106,6 +107,17 @@ export const AlbumsSection = ({view.type == "archive-albums"? view.activeCollectionSummary: undefined;+ const { onUpload } = operations;+ const handleAddPhotos = useCallback(+ () => onUpload("upload", activeCollection),+ [onUpload, activeCollection],+ );+ const canAddPhotos =+ !library.isFirstLoad &&+ user &&+ (activeCollection?.type == "album" ||+ activeCollection?.type == "folder") &&+ canAddFilesToCollection(activeCollection, user.id);const [fileListHeader, setFileListHeader] =useState<FileListHeaderOrFooter>();const {@@ -336,6 +348,7 @@ export const AlbumsSection = ({<GalleryMedia{...{ library, operations, navigation }}header={fileListHeader}+ onAddPhotos={canAddPhotos ? handleAddPhotos : undefined}source={{mode: barMode,modePlus: barMode,diff --git a/web/apps/photos/src/components/gallery/sections/types.ts b/web/apps/photos/src/components/gallery/sections/types.tsindex 6c4d26f01d..c6945e3640 100644--- a/web/apps/photos/src/components/gallery/sections/types.ts+++ b/web/apps/photos/src/components/gallery/sections/types.ts@@ -39,7 +39,10 @@ export type GallerySectionOperations = Pick<onToggleFavorite: (file: EnteFile) => Promise<void>;onSendLink: (file: EnteFile) => Promise<void>;setBlockingLoad: Dispatch<SetStateAction<boolean>>;- onUpload: (intent?: UploadTypeSelectorIntent) => void;+ onUpload: (+ intent?: UploadTypeSelectorIntent,+ uploadTargetCollection?: Collection,+ ) => void;saveGroups: ReturnType<typeof useSaveGroups>["saveGroups"];setSectionActivity: Dispatch<SetStateAction<{ selection: boolean; drop: boolean }>diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex 6aa8a67021..a8444b05ef 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -372,14 +372,19 @@ const CopyFilesResponse = z.object({oldToNewFileIDMap: z.record(z.string(), z.number()),});-const currentUserRoleInCollection = (collection: Collection) => {- const userID = ensureLocalUser().id;+const currentUserRoleInCollection = (+ collection: Collection,+ userID = ensureLocalUser().id,+) => {if (collection.owner.id == userID) return "OWNER";return collection.sharees.find((sharee) => sharee.id == userID)?.role;};-export const canAddFilesToCollection = (collection: Collection) => {- const role = currentUserRoleInCollection(collection);+export const canAddFilesToCollection = (+ collection: Collection,+ userID?: number,+) => {+ const role = currentUserRoleInCollection(collection, userID);return role == "OWNER" || role == "ADMIN" || role == "COLLABORATOR";};