This commit is contained in:
Manav Rathi
2024-06-25 14:27:33 +05:30
parent 89ee10ea57
commit c318167909
7 changed files with 32 additions and 47 deletions

View File

@@ -9,7 +9,6 @@ import { Box, Button, Stack, Typography, styled } from "@mui/material";
import { t } from "i18next";
import { Trans } from "react-i18next";
import uploadManager from "services/upload/uploadManager";
import { UploadTypeSelectorIntent } from "types/gallery";
const Wrapper = styled(Box)`
display: flex;
@@ -61,9 +60,7 @@ export default function GalleryEmptyState({ openUploader }) {
"not-allowed",
}}
color="accent"
onClick={() =>
openUploader(UploadTypeSelectorIntent.normalUpload)
}
onClick={() => openUploader("upload")}
disabled={!uploadManager.shouldAllowNewUpload()}
sx={{
mt: 1.5,
@@ -83,9 +80,7 @@ export default function GalleryEmptyState({ openUploader }) {
!uploadManager.shouldAllowNewUpload() &&
"not-allowed",
}}
onClick={() =>
openUploader(UploadTypeSelectorIntent.import)
}
onClick={() => openUploader("import")}
disabled={!uploadManager.shouldAllowNewUpload()}
sx={{
mt: 1.5,

View File

@@ -1,9 +1,8 @@
import FileUploadOutlinedIcon from "@mui/icons-material/FileUploadOutlined";
import { Button, ButtonProps, IconButton, styled } from "@mui/material";
import { type UploadTypeSelectorIntent } from "components/Upload/UploadTypeSelector";
import { t } from "i18next";
import uploadManager from "services/upload/uploadManager";
import { UploadTypeSelectorIntent } from "types/gallery";
const Wrapper = styled("div")<{ $disableShrink: boolean }>`
display: flex;

View File

@@ -9,17 +9,21 @@ import { default as FolderUploadIcon } from "@mui/icons-material/PermMediaOutlin
import { Box, Dialog, Stack, Typography } from "@mui/material";
import { t } from "i18next";
import React, { useContext, useEffect, useRef } from "react";
import { UploadTypeSelectorIntent } from "types/gallery";
import { isMobileOrTable } from "utils/common/deviceDetection";
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;
show: boolean;
/** The particular context / scenario in which this upload is occuring. */
intent: UploadTypeSelectorIntent;
uploadFiles: () => void;
uploadFolders: () => void;
uploadGoogleTakeoutZips: () => void;
uploadTypeSelectorIntent: UploadTypeSelectorIntent;
}
/**
@@ -31,13 +35,13 @@ interface UploadTypeSelectorProps {
* 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> = ({
export const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
open,
onClose,
show,
intent,
uploadFiles,
uploadFolders,
uploadGoogleTakeoutZips,
uploadTypeSelectorIntent,
}) => {
const publicCollectionGalleryContext = useContext(
PublicCollectionGalleryContext,
@@ -46,18 +50,18 @@ const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
useEffect(() => {
if (
show &&
open &&
directlyShowUploadFiles.current &&
publicCollectionGalleryContext.accessedThroughSharedURL
) {
uploadFiles();
onClose();
}
}, [show]);
}, [open]);
return (
<Dialog
open={show}
open={open}
PaperProps={{
sx: (theme) => ({
maxWidth: "375px",
@@ -68,18 +72,15 @@ const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
onClose={dialogCloseHandler({ onClose })}
>
<DialogTitleWithCloseButton onClose={onClose}>
{uploadTypeSelectorIntent ===
UploadTypeSelectorIntent.collectPhotos
{intent == "collect"
? t("SELECT_PHOTOS")
: uploadTypeSelectorIntent ===
UploadTypeSelectorIntent.import
: intent == "import"
? t("IMPORT")
: t("UPLOAD")}
</DialogTitleWithCloseButton>
<Box p={1.5} pt={0.5}>
<Stack spacing={0.5}>
{uploadTypeSelectorIntent !==
UploadTypeSelectorIntent.import && (
{intent != "import" && (
<EnteMenuItem
onClick={uploadFiles}
startIcon={<FileUploadIcon />}
@@ -94,8 +95,7 @@ const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
label={t("UPLOAD_DIRS")}
/>
{uploadTypeSelectorIntent !==
UploadTypeSelectorIntent.collectPhotos && (
{intent !== "collect" && (
<EnteMenuItem
onClick={uploadGoogleTakeoutZips}
startIcon={<GoogleIcon />}
@@ -111,5 +111,3 @@ const UploadTypeSelector: React.FC<UploadTypeSelectorProps> = ({
</Dialog>
);
};
export default UploadTypeSelector;

View File

@@ -39,7 +39,6 @@ import {
SetCollections,
SetFiles,
SetLoading,
UploadTypeSelectorIntent,
} from "types/gallery";
import { getOrCreateAlbum } from "utils/collection";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
@@ -50,7 +49,10 @@ import {
import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
import { CollectionMappingChoiceModal } from "./CollectionMappingChoiceModal";
import UploadProgress from "./UploadProgress";
import UploadTypeSelector from "./UploadTypeSelector";
import {
UploadTypeSelector,
type UploadTypeSelectorIntent,
} from "./UploadTypeSelector";
enum PICKED_UPLOAD_TYPE {
FILES = "files",
@@ -767,12 +769,12 @@ export default function Uploader({
didSelect={didSelectCollectionMapping}
/>
<UploadTypeSelector
show={props.uploadTypeSelectorView}
open={props.uploadTypeSelectorView}
onClose={props.closeUploadTypeSelector}
intent={props.uploadTypeSelectorIntent}
uploadFiles={handleFileUpload}
uploadFolders={handleFolderUpload}
uploadGoogleTakeoutZips={handleZipUpload}
uploadTypeSelectorIntent={props.uploadTypeSelectorIntent}
/>
<UploadProgress
open={uploadProgressView}

View File

@@ -49,6 +49,7 @@ import PhotoFrame from "components/PhotoFrame";
import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
import SearchResultInfo from "components/Search/SearchResultInfo";
import Sidebar from "components/Sidebar";
import type { UploadTypeSelectorIntent } from "components/Upload/UploadTypeSelector";
import Uploader from "components/Upload/Uploader";
import { UploadSelectorInputs } from "components/UploadSelectorInputs";
import { GalleryNavbar } from "components/pages/gallery/Navbar";
@@ -101,7 +102,6 @@ import {
SelectedState,
SetFilesDownloadProgressAttributes,
SetFilesDownloadProgressAttributesCreator,
UploadTypeSelectorIntent,
} from "types/gallery";
import { Search, SearchResultSummary, UpdateSearch } from "types/search";
import { FamilyData } from "types/user";
@@ -278,9 +278,7 @@ export default function Gallery() {
const [uploadTypeSelectorView, setUploadTypeSelectorView] = useState(false);
const [uploadTypeSelectorIntent, setUploadTypeSelectorIntent] =
useState<UploadTypeSelectorIntent>(
UploadTypeSelectorIntent.normalUpload,
);
useState<UploadTypeSelectorIntent>("upload");
const [sidebarView, setSidebarView] = useState(false);
@@ -992,12 +990,12 @@ export default function Gallery() {
}
};
const openUploader = (intent = UploadTypeSelectorIntent.normalUpload) => {
const openUploader = (intent?: UploadTypeSelectorIntent) => {
if (!uploadManager.shouldAllowNewUpload()) {
return;
}
setUploadTypeSelectorView(true);
setUploadTypeSelectorIntent(intent);
setUploadTypeSelectorIntent(intent ?? "upload");
};
const closeCollectionSelector = () => {

View File

@@ -63,7 +63,6 @@ import {
SelectedState,
SetFilesDownloadProgressAttributes,
SetFilesDownloadProgressAttributesCreator,
UploadTypeSelectorIntent,
} from "types/gallery";
import { downloadCollectionFiles, isHiddenCollection } from "utils/collection";
import {
@@ -582,9 +581,7 @@ export default function PublicCollectionGallery() {
uploadTypeSelectorView={uploadTypeSelectorView}
closeUploadTypeSelector={closeUploadTypeSelectorView}
showSessionExpiredMessage={showPublicLinkExpiredMessage}
uploadTypeSelectorIntent={
UploadTypeSelectorIntent.collectPhotos
}
uploadTypeSelectorIntent="collect"
{...{
dragAndDropFiles,
openFileSelector,

View File

@@ -38,11 +38,7 @@ export type MergedSourceURL = {
original: string;
converted: string;
};
export enum UploadTypeSelectorIntent {
normalUpload,
import,
collectPhotos,
}
export type GalleryContextType = {
showPlanSelectorModal: () => void;
setActiveCollectionID: (collectionID: number) => void;