Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move

Manav Rathie3ef1e462843
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload.tsx
similarity index 80%
rename from web/apps/photos/src/components/Upload/Uploader.tsx
rename to web/apps/photos/src/components/Upload.tsx
index 64b5bbbe02..f14c4966e8 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -1,4 +1,9 @@
import { isDesktop } from "@/base/app";
+import { SpacedRow } from "@/base/components/containers";
+import { DialogCloseIconButton } from "@/base/components/mui/DialogCloseIconButton";
+import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
+import { RowButton } from "@/base/components/RowButton";
+import { useIsTouchscreen } from "@/base/components/utils/hooks";
import { useModalVisibility } from "@/base/components/utils/modal";
import { useBaseContext } from "@/base/context";
import { basename } from "@/base/file-name";
@@ -22,11 +27,29 @@ import { redirectToCustomerPortal } from "@/new/photos/services/user-details";
import { usePhotosAppContext } from "@/new/photos/types/context";
import { firstNonEmpty } from "@/utils/array";
import { CustomError } from "@ente/shared/error";
+import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import DiscFullIcon from "@mui/icons-material/DiscFull";
+import GoogleIcon from "@mui/icons-material/Google";
+import ImageOutlinedIcon from "@mui/icons-material/ImageOutlined";
import InfoRoundedIcon from "@mui/icons-material/InfoRounded";
+import PermMediaOutlinedIcon from "@mui/icons-material/PermMediaOutlined";
+import {
+ Box,
+ Dialog,
+ DialogTitle,
+ Link,
+ Stack,
+ Typography,
+} from "@mui/material";
import { t } from "i18next";
import { GalleryContext } from "pages/gallery";
-import { useCallback, useContext, useEffect, useRef, useState } from "react";
+import React, {
+ useCallback,
+ useContext,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import { Trans } from "react-i18next";
import {
getPublicCollectionUID,
@@ -45,12 +68,10 @@ import watcher from "services/watch";
import { SetLoading } from "types/gallery";
import { getOrCreateAlbum } from "utils/collection";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
-import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
+import { SetCollectionNamerAttributes } from "./Collections/CollectionNamer";
import { UploadProgress } from "./UploadProgress";
-import {
- UploadTypeSelector,
- type UploadTypeSelectorIntent,
-} from "./UploadTypeSelector";
+
+export type UploadTypeSelectorIntent = "upload" | "import" | "collect";
enum PICKED_UPLOAD_TYPE {
FILES = "files",
@@ -58,7 +79,7 @@ enum PICKED_UPLOAD_TYPE {
ZIPS = "zips",
}
-interface Props {
+interface UploadProps {
syncWithRemote: (force?: boolean, silent?: boolean) => Promise<void>;
closeUploadTypeSelector: () => void;
/**
@@ -91,13 +112,16 @@ interface Props {
activeCollection?: Collection;
}
-export default function Uploader({
+/**
+ * Top level component that houses the infrastructure for handling uploads.
+ */
+export const Upload: React.FC<UploadProps> = ({
isFirstUpload,
dragAndDropFiles,
onUploadFile,
showSessionExpiredMessage,
...props
-}: Props) {
+}) => {
const { showMiniDialog } = useBaseContext();
const { showNotification, onGenericError, watchFolderView } =
usePhotosAppContext();
@@ -838,7 +862,7 @@ export default function Uploader({
/>
</>
);
-}
+};
type GetInputProps = () => React.HTMLAttributes<HTMLInputElement>;
@@ -1000,7 +1024,7 @@ const groupFilesBasedOnParentFolder = (
return result;
};
-export const setPendingUploads = async (
+const setPendingUploads = async (
electron: Electron,
collections: Collection[],
uploadItems: UploadItem[],
@@ -1035,3 +1059,242 @@ export const setPendingUploads = async (
await electron.setPendingUploads({ collectionName, filePaths, zipItems });
};
+
+interface UploadTypeSelectorProps {
+ /** If `true`, then the selector is shown. */
+ open: boolean;
+ /** Callback to indicate that the selector should be closed. */
+ onClose: () => void;
+ /** The particular context / scenario in which this upload is occuring. */
+ intent: UploadTypeSelectorIntent;
+ uploadFiles: () => void;
+ uploadFolders: () => void;
+ uploadGoogleTakeoutZips: () => void;
+}
+
+/**
+ * Request the user to specify which type of file / folder / zip it is that they
+ * wish to upload.
+ *
+ * This selector (and the "Upload" button) is functionally redundant, the user
+ * can just drag and drop any of these into the app to directly initiate the
+ * upload. But having an explicit easy to reach button is also necessary for new
+ * users, or for cases where drag-and-drop might not be appropriate.
+ */
+const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
+ open,
+ onClose,
+ intent,
+ uploadFiles,
+ uploadFolders,
+ uploadGoogleTakeoutZips,
+}) => {
+ const publicCollectionGalleryContext = useContext(
+ PublicCollectionGalleryContext,
+ );
+
+ // Directly show the file selector for the public albums app on likely
+ // mobile devices.
+ const directlyShowUploadFiles = useIsTouchscreen();
+
+ useEffect(() => {
+ if (
+ open &&
+ directlyShowUploadFiles &&
+ publicCollectionGalleryContext.credentials
+ ) {
+ uploadFiles();
+ onClose();
+ }
+ }, [open]);
+
+ const handleSelect = (option: UploadOptionType) => {
+ switch (option) {
+ case "files":
+ uploadFiles();
+ break;
+ case "folders":
+ uploadFolders();
+ break;
+ case "zips":
+ uploadGoogleTakeoutZips();
+ break;
+ }
+ };
+
+ return (
+ <Dialog
+ open={open}
+ fullWidth
+ slotProps={{
+ paper: {
+ sx: (theme) => ({
+ maxWidth: "375px",
+ p: 1,
+ [theme.breakpoints.down(360)]: { p: 0 },
+ }),
+ },
+ }}
+ onClose={onClose}
+ >
+ <UploadOptions
+ intent={intent}
+ onSelect={handleSelect}
+ onClose={onClose}
+ />
+ </Dialog>
+ );
+};
+
+type UploadOptionType = "files" | "folders" | "zips";
+
+interface UploadOptionsProps {
+ intent: UploadTypeSelectorIntent;
+ /** Called when the user selects one of the provided options. */
+ onSelect: (option: UploadOptionType) => void;
+ /** Called when the dialog should be closed. */
+ onClose: () => void;
+}
+
+const UploadOptions: React.FC<UploadOptionsProps> = ({
+ intent,
+ onSelect,
+ onClose,
+}) => {
+ // [Note: Dialog state remains preseved on reopening]
+ //
+ // Keep dialog content specific state here, in a separate component, so that
+ // this state is not tied to the lifetime of the dialog.
+ //
+ // If we don't do this, then a MUI dialog retains whatever it was doing when
+ // it was last closed. Sometimes that is desirable, but sometimes not, and
+ // in the latter cases moving the instance specific state to a child works.
+
+ const [showTakeoutOptions, setShowTakeoutOptions] = useState(false);
+
+ const handleTakeoutClose = () => setShowTakeoutOptions(false);
+
+ const handleSelect = (option: UploadOptionType) => {
+ switch (option) {
+ case "files":
+ onSelect("files");
+ break;
+ case "folders":
+ onSelect("folders");
+ break;
+ case "zips":
+ !showTakeoutOptions
+ ? setShowTakeoutOptions(true)
+ : onSelect("zips");
+ break;
+ }
+ };
+
+ return !showTakeoutOptions ? (
+ <DefaultOptions {...{ intent, onClose }} onSelect={handleSelect} />
+ ) : (
+ <TakeoutOptions onSelect={handleSelect} onClose={handleTakeoutClose} />
+ );
+};
+
+const DefaultOptions: React.FC<UploadOptionsProps> = ({
+ intent,
+ onClose,
+ onSelect,
+}) => {
+ return (
+ <>
+ <SpacedRow>
+ <DialogTitle variant="h5">
+ {intent == "collect"
+ ? t("select_photos")
+ : intent == "import"
+ ? t("import")
+ : t("upload")}
+ </DialogTitle>
+ <DialogCloseIconButton {...{ onClose }} />
+ </SpacedRow>
+ <Box sx={{ p: "12px", pt: "16px" }}>
+ <Stack sx={{ gap: 0.5 }}>
+ {intent != "import" && (
+ <RowButton
+ startIcon={<ImageOutlinedIcon />}
+ endIcon={<ChevronRightIcon />}
+ label={t("file")}
+ onClick={() => onSelect("files")}
+ />
+ )}
+ <RowButton
+ startIcon={<PermMediaOutlinedIcon />}
+ endIcon={<ChevronRightIcon />}
+ label={t("folder")}
+ onClick={() => onSelect("folders")}
+ />
+ {intent !== "collect" && (
+ <RowButton
+ startIcon={<GoogleIcon />}
+ endIcon={<ChevronRightIcon />}
+ label={t("google_takeout")}
+ onClick={() => onSelect("zips")}
+ />
+ )}
+ </Stack>
+ <Typography
+ sx={{
+ color: "text.muted",
+ p: "12px",
+ pt: "24px",
+ textAlign: "center",
+ }}
+ >
+ {t("drag_and_drop_hint")}
+ </Typography>
+ </Box>
+ </>
+ );
+};
+
+const TakeoutOptions: React.FC<Omit<UploadOptionsProps, "intent">> = ({
+ onSelect,
+ onClose,
+}) => {
+ return (
+ <>
+ <SpacedRow>
+ <DialogTitle variant="h5">{t("google_takeout")}</DialogTitle>
+ <DialogCloseIconButton {...{ onClose }} />
+ </SpacedRow>
+ <Stack sx={{ padding: "18px 12px 20px 12px", gap: "16px" }}>
+ <Stack sx={{ gap: "8px" }}>
+ <FocusVisibleButton
+ color="accent"
+ fullWidth
+ onClick={() => onSelect("folders")}
+ >
+ {t("select_folder")}
+ </FocusVisibleButton>
+ <FocusVisibleButton
+ color="secondary"
+ fullWidth
+ onClick={() => onSelect("zips")}
+ >
+ {t("select_zips")}
+ </FocusVisibleButton>
+ <Link
+ href="https://help.ente.io/photos/migration/from-google-photos/"
+ target="_blank"
+ rel="noopener"
+ >
+ <FocusVisibleButton color="secondary" fullWidth>
+ {t("faq")}
+ </FocusVisibleButton>
+ </Link>
+ </Stack>
+
+ <Typography variant="small" sx={{ color: "text.muted" }}>
+ {t("takeout_hint")}
+ </Typography>
+ </Stack>
+ </>
+ );
+};
diff --git a/web/apps/photos/src/components/Upload/UploadTypeSelector.tsx b/web/apps/photos/src/components/Upload/UploadTypeSelector.tsx
index fdf6f7f070..e69de29bb2 100644
--- a/web/apps/photos/src/components/Upload/UploadTypeSelector.tsx
+++ b/web/apps/photos/src/components/Upload/UploadTypeSelector.tsx
@@ -1,261 +0,0 @@
-import { SpacedRow } from "@/base/components/containers";
-import { DialogCloseIconButton } from "@/base/components/mui/DialogCloseIconButton";
-import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
-import { RowButton } from "@/base/components/RowButton";
-import { useIsTouchscreen } from "@/base/components/utils/hooks";
-import ChevronRightIcon from "@mui/icons-material/ChevronRight";
-import GoogleIcon from "@mui/icons-material/Google";
-import ImageOutlinedIcon from "@mui/icons-material/ImageOutlined";
-import PermMediaOutlinedIcon from "@mui/icons-material/PermMediaOutlined";
-import {
- Box,
- Dialog,
- DialogTitle,
- Link,
- Stack,
- Typography,
-} from "@mui/material";
-import { t } from "i18next";
-import React, { useContext, useEffect, useState } from "react";
-import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
-
-export type UploadTypeSelectorIntent = "upload" | "import" | "collect";
-
-interface UploadTypeSelectorProps {
- /** If `true`, then the selector is shown. */
- open: boolean;
- /** Callback to indicate that the selector should be closed. */
- onClose: () => void;
- /** The particular context / scenario in which this upload is occuring. */
- intent: UploadTypeSelectorIntent;
- uploadFiles: () => void;
- uploadFolders: () => void;
- uploadGoogleTakeoutZips: () => void;
-}
-
-/**
- * Request the user to specify which type of file / folder / zip it is that they
- * wish to upload.
- *
- * This selector (and the "Upload" button) is functionally redundant, the user
- * can just drag and drop any of these into the app to directly initiate the
- * upload. But having an explicit easy to reach button is also necessary for new
- * users, or for cases where drag-and-drop might not be appropriate.
- */
-export const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
- open,
- onClose,
- intent,
- uploadFiles,
- uploadFolders,
- uploadGoogleTakeoutZips,
-}) => {
- const publicCollectionGalleryContext = useContext(
- PublicCollectionGalleryContext,
- );
-
- // Directly show the file selector for the public albums app on likely
- // mobile devices.
- const directlyShowUploadFiles = useIsTouchscreen();
-
- useEffect(() => {
- if (
- open &&
- directlyShowUploadFiles &&
- publicCollectionGalleryContext.credentials
- ) {
- uploadFiles();
- onClose();
- }
- }, [open]);
-
- const handleSelect = (option: OptionType) => {
- switch (option) {
- case "files":
- uploadFiles();
- break;
- case "folders":
- uploadFolders();
- break;
- case "zips":
- uploadGoogleTakeoutZips();
- break;
- }
- };
-
- return (
- <Dialog
- open={open}
- fullWidth
- slotProps={{
- paper: {
- sx: (theme) => ({
- maxWidth: "375px",
- p: 1,
- [theme.breakpoints.down(360)]: { p: 0 },
- }),
- },
- }}
- onClose={onClose}
- >
- <Options
- intent={intent}
- onSelect={handleSelect}
- onClose={onClose}
- />
- </Dialog>
- );
-};
-
-type OptionType = "files" | "folders" | "zips";
-
-interface OptionsProps {
- intent: UploadTypeSelectorIntent;
- /** Called when the user selects one of the provided options. */
- onSelect: (option: OptionType) => void;
- /** Called when the dialog should be closed. */
- onClose: () => void;
-}
-
-export const Options: React.FC<OptionsProps> = ({
- intent,
- onSelect,
- onClose,
-}) => {
- // [Note: Dialog state remains preseved on reopening]
- //
- // Keep dialog content specific state here, in a separate component, so that
- // this state is not tied to the lifetime of the dialog.
- //
- // If we don't do this, then a MUI dialog retains whatever it was doing when
- // it was last closed. Sometimes that is desirable, but sometimes not, and
- // in the latter cases moving the instance specific state to a child works.
-
- const [showTakeoutOptions, setShowTakeoutOptions] = useState(false);
-
- const handleTakeoutClose = () => setShowTakeoutOptions(false);
-
- const handleSelect = (option: OptionType) => {
- switch (option) {
- case "files":
- onSelect("files");
- break;
- case "folders":
- onSelect("folders");
- break;
- case "zips":
- !showTakeoutOptions
- ? setShowTakeoutOptions(true)
- : onSelect("zips");
- break;
- }
- };
-
- return !showTakeoutOptions ? (
- <DefaultOptions {...{ intent, onClose }} onSelect={handleSelect} />
- ) : (
- <TakeoutOptions onSelect={handleSelect} onClose={handleTakeoutClose} />
- );
-};
-
-const DefaultOptions: React.FC<OptionsProps> = ({
- intent,
- onClose,
- onSelect,
-}) => {
- return (
- <>
- <SpacedRow>
- <DialogTitle variant="h5">
- {intent == "collect"
- ? t("select_photos")
- : intent == "import"
- ? t("import")
- : t("upload")}
- </DialogTitle>
- <DialogCloseIconButton {...{ onClose }} />
- </SpacedRow>
- <Box sx={{ p: "12px", pt: "16px" }}>
- <Stack sx={{ gap: 0.5 }}>
- {intent != "import" && (
- <RowButton
- startIcon={<ImageOutlinedIcon />}
- endIcon={<ChevronRightIcon />}
- label={t("file")}
- onClick={() => onSelect("files")}
- />
- )}
- <RowButton
- startIcon={<PermMediaOutlinedIcon />}
- endIcon={<ChevronRightIcon />}
- label={t("folder")}
- onClick={() => onSelect("folders")}
- />
- {intent !== "collect" && (
- <RowButton
- startIcon={<GoogleIcon />}
- endIcon={<ChevronRightIcon />}
- label={t("google_takeout")}
- onClick={() => onSelect("zips")}
- />
- )}
- </Stack>
- <Typography
- sx={{
- color: "text.muted",
- p: "12px",
- pt: "24px",
- textAlign: "center",
- }}
- >
- {t("drag_and_drop_hint")}
- </Typography>
- </Box>
- </>
- );
-};
-
-const TakeoutOptions: React.FC<Omit<OptionsProps, "intent">> = ({
- onSelect,
- onClose,
-}) => {
- return (
- <>
- <SpacedRow>
- <DialogTitle variant="h5">{t("google_takeout")}</DialogTitle>
- <DialogCloseIconButton {...{ onClose }} />
- </SpacedRow>
- <Stack sx={{ padding: "18px 12px 20px 12px", gap: "16px" }}>
- <Stack sx={{ gap: "8px" }}>
- <FocusVisibleButton
- color="accent"
- fullWidth
- onClick={() => onSelect("folders")}
- >
- {t("select_folder")}
- </FocusVisibleButton>
- <FocusVisibleButton
- color="secondary"
- fullWidth
- onClick={() => onSelect("zips")}
- >
- {t("select_zips")}
- </FocusVisibleButton>
- <Link
- href="https://help.ente.io/photos/migration/from-google-photos/"
- target="_blank"
- rel="noopener"
- >
- <FocusVisibleButton color="secondary" fullWidth>
- {t("faq")}
- </FocusVisibleButton>
- </Link>
- </Stack>
-
- <Typography variant="small" sx={{ color: "text.muted" }}>
- {t("takeout_hint")}
- </Typography>
- </Stack>
- </>
- );
-};
diff --git a/web/apps/photos/src/components/Upload/UploadProgress.tsx b/web/apps/photos/src/components/UploadProgress.tsx
similarity index 100%
rename from web/apps/photos/src/components/Upload/UploadProgress.tsx
rename to web/apps/photos/src/components/UploadProgress.tsx
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index c8f2d3e3d3..cfc63e03d7 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -103,8 +103,7 @@ import GalleryEmptyState from "components/GalleryEmptyState";
import PhotoFrame from "components/PhotoFrame";
import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
import { Sidebar } from "components/Sidebar";
-import { type UploadTypeSelectorIntent } from "components/Upload/UploadTypeSelector";
-import Uploader from "components/Upload/Uploader";
+import { Upload, type UploadTypeSelectorIntent } from "components/Upload";
import SelectedFileOptions from "components/pages/gallery/SelectedFileOptions";
import { t } from "i18next";
import { useRouter, type NextRouter } from "next/router";
@@ -997,7 +996,7 @@ const Page: React.FC = () => {
}}
/>
- <Uploader
+ <Upload
activeCollection={activeCollection}
syncWithRemote={syncWithRemote}
closeUploadTypeSelector={setUploadTypeSelectorView.bind(
diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx
index a6212f42a7..8e22b6af49 100644
--- a/web/apps/photos/src/pages/shared-albums.tsx
+++ b/web/apps/photos/src/pages/shared-albums.tsx
@@ -57,7 +57,7 @@ import {
} from "components/FilesDownloadProgress";
import PhotoFrame from "components/PhotoFrame";
import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
-import Uploader from "components/Upload/Uploader";
+import {Upload} from "components/Upload";
import { t } from "i18next";
import { useRouter } from "next/router";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -536,7 +536,7 @@ export default function PublicCollectionGallery() {
selectable={downloadEnabled}
/>
{blockingLoad && <TranslucentLoadingOverlay />}
- <Uploader
+ <Upload
syncWithRemote={syncWithRemote}
uploadCollection={publicCollection}
setLoading={setBlockingLoad}