π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(Upload):pre-confirmation-ux-issue
Aswin Asok5932acc00574
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex e87aa0b9be..f88e9ac8bc 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -49,7 +49,12 @@ import {type ModalVisibilityProps,} from "ente-base/components/utils/modal";import { useBaseContext } from "ente-base/context";-import { basename, dirname, joinPath } from "ente-base/file-name";+import {+ basename,+ dirname,+ joinPath,+ lowercaseExtension,+} from "ente-base/file-name";import log from "ente-base/log";import type {CollectionMapping,@@ -213,6 +218,13 @@ interface UploadConfirmation {includePartnerSharedFiles: boolean;}+type UploadConfirmationState =+ | { phase: "counting"; isTakeout: boolean }+ | ({ phase: "ready" } & UploadConfirmation);++const containsJSONFiles = (uploadItemAndPaths: UploadItemAndPath[]) =>+ uploadItemAndPaths.some(([, path]) => lowercaseExtension(path) == "json");+/*** Top level component that houses the infrastructure for handling uploads.*/@@ -251,8 +263,9 @@ export const Upload: React.FC<UploadProps> = ({const [percentComplete, setPercentComplete] = useState(0);const [hasLivePhotos, setHasLivePhotos] = useState(false);const [prefilledNewAlbumName, setPrefilledNewAlbumName] = useState("");- const [uploadConfirmation, setUploadConfirmation] =- useState<UploadConfirmation>();+ const [uploadConfirmation, setUploadConfirmation] = useState<+ UploadConfirmationState | undefined+ >();const [openCollectionMappingChoice, setOpenCollectionMappingChoice] =useState(false);@@ -865,12 +878,20 @@ export const Upload: React.FC<UploadProps> = ({return;}+ const isTakeoutHint = containsJSONFiles(uploadItemAndPaths);+ if (uploadItemAndPaths.length > 1 || isTakeoutHint)+ setUploadConfirmation({+ phase: "counting",+ isTakeout: isTakeoutHint,+ });+try {const { count: fileCount, isTakeout } = await uploadableMediaCount([uploadItemAndPaths,]);if (uploadItemsAndPaths.current !== uploadItemAndPaths) return;if (fileCount == 1 && !isTakeout) {+ setUploadConfirmation(undefined);void commitUploadToExistingCollection(collection,uploadItemAndPaths,@@ -879,6 +900,7 @@ export const Upload: React.FC<UploadProps> = ({return;}setUploadConfirmation({+ phase: "ready",pendingUpload: {type: "existing-collection",collection,@@ -959,6 +981,17 @@ export const Upload: React.FC<UploadProps> = ({}: NewCollectionsOptions = {},) => {const uploadItemAndPaths = uploadItemsAndPaths.current;+ const isTakeoutHint = containsJSONFiles(uploadItemAndPaths);+ if (+ enableV2 &&+ !skipConfirmation &&+ (uploadItemAndPaths.length > 1 || isTakeoutHint)+ )+ setUploadConfirmation({+ phase: "counting",+ isTakeout: isTakeoutHint,+ });+let collectionNameToUploadItems = new Map<string,UploadItemAndPath[]@@ -1004,6 +1037,7 @@ export const Upload: React.FC<UploadProps> = ({]);if (uploadItemsAndPaths.current !== uploadItemAndPaths) return;if (fileCount == 1 && !isTakeout) {+ setUploadConfirmation(undefined);void commitUploadToNewCollections(uploadItemAndPaths,collectionNameToUploadItems,@@ -1014,6 +1048,7 @@ export const Upload: React.FC<UploadProps> = ({return;}setUploadConfirmation({+ phase: "ready",pendingUpload: {type: "new-collections",uploadItemAndPaths,@@ -1102,7 +1137,7 @@ export const Upload: React.FC<UploadProps> = ({const handleUploadConfirm = () => {const confirmation = uploadConfirmation;- if (!confirmation) return;+ if (confirmation?.phase != "ready") return;setUploadConfirmation(undefined);const { pendingUpload, importFavorites, includePartnerSharedFiles } =@@ -1140,20 +1175,18 @@ export const Upload: React.FC<UploadProps> = ({_event: React.ChangeEvent<HTMLInputElement>,checked: boolean,) =>- setUploadConfirmation((confirmation) =>- confirmation- ? { ...confirmation, importFavorites: checked }- : undefined,+ setUploadConfirmation((c) =>+ c?.phase == "ready" ? { ...c, importFavorites: checked } : c,);const handleIncludePartnerSharedFilesChange = (_event: React.ChangeEvent<HTMLInputElement>,checked: boolean,) =>- setUploadConfirmation((confirmation) =>- confirmation- ? { ...confirmation, includePartnerSharedFiles: checked }- : undefined,+ setUploadConfirmation((c) =>+ c?.phase == "ready"+ ? { ...c, includePartnerSharedFiles: checked }+ : c,);const waitInQueueAndUploadFiles = async (@@ -1370,6 +1403,9 @@ export const Upload: React.FC<UploadProps> = ({createHidden: props.isInHiddenSection,});+ const readyConfirmation =+ uploadConfirmation?.phase == "ready" ? uploadConfirmation : undefined;+return (<><Inputs@@ -1431,15 +1467,14 @@ export const Upload: React.FC<UploadProps> = ({{enableV2 && (<UploadConfirmationDialogopen={!!uploadConfirmation}+ loading={uploadConfirmation?.phase == "counting"}isTakeout={uploadConfirmation?.isTakeout ?? false}- fileCount={uploadConfirmation?.fileCount ?? 0}- albumCount={uploadConfirmation?.albumCount ?? 0}- importFavorites={- uploadConfirmation?.importFavorites ?? true- }+ fileCount={readyConfirmation?.fileCount ?? 0}+ albumCount={readyConfirmation?.albumCount ?? 0}+ importFavorites={readyConfirmation?.importFavorites ?? true}onImportFavoritesChange={handleImportFavoritesChange}includePartnerSharedFiles={- uploadConfirmation?.includePartnerSharedFiles ?? true+ readyConfirmation?.includePartnerSharedFiles ?? true}onIncludePartnerSharedFilesChange={handleIncludePartnerSharedFilesChangediff --git a/web/apps/photos/src/components/UploadConfirmationDialog.tsx b/web/apps/photos/src/components/UploadConfirmationDialog.tsxindex eb6783e60c..bab7e10aef 100644--- a/web/apps/photos/src/components/UploadConfirmationDialog.tsx+++ b/web/apps/photos/src/components/UploadConfirmationDialog.tsx@@ -1,5 +1,6 @@import {Cancel01Icon,+ Loading03Icon,StarIcon,Tick02Icon,UserMultipleIcon,@@ -20,6 +21,7 @@ import type { ChangeEvent, ReactElement } from "react";interface UploadConfirmationDialogProps {open: boolean;+ loading: boolean;/*** `true` if the items being uploaded were detected to be a Google Takeout* import (Takeout metadata JSONs were found amongst them).@@ -43,6 +45,7 @@ interface UploadConfirmationDialogProps {export function UploadConfirmationDialog({open,+ loading,isTakeout,fileCount,albumCount,@@ -59,6 +62,7 @@ export function UploadConfirmationDialog({onClose={onCancel}maxWidth={false}aria-labelledby="upload-confirmation-title"+ aria-busy={loading}slotProps={{ paper: { sx: paperSx } }}><Stack sx={contentSx}>@@ -83,33 +87,62 @@ export function UploadConfirmationDialog({<Stack sx={{ gap: "20px" }}><Stack sx={readySx}><Box aria-hidden sx={successIllustrationSx}>- <Box sx={successIconSx}>- <HugeiconsIcon- icon={Tick02Icon}- size={26}- strokeWidth={2.5}- />- </Box>+ {loading ? (+ <Box sx={loadingIconSx}>+ <Box sx={loadingSpinnerSx}>+ <HugeiconsIcon+ icon={Loading03Icon}+ size={26}+ />+ </Box>+ </Box>+ ) : (+ <Box sx={successIconSx}>+ <HugeiconsIcon+ icon={Tick02Icon}+ size={26}+ strokeWidth={2.5}+ />+ </Box>+ )}</Box><Typographyid="upload-confirmation-title"component="h2"sx={displayTitleSx}>- {isTakeout- ? t("ready_to_import")- : t("ready_to_upload")}+ {loading+ ? t("calculating_title")+ : t(+ isTakeout+ ? "ready_to_import"+ : "ready_to_upload",+ )}</Typography>+ {loading && (+ <Typography sx={calculatingDescriptionSx}>+ {t(+ isTakeout+ ? "calculating_takeout_description"+ : "calculating_upload_description",+ )}+ </Typography>+ )}</Stack>- <Stack direction="row" sx={statsSx}>+ <Stack+ direction="row"+ sx={[statsSx, loading && { opacity: 0.4 }]}+ ><StatCard+ loading={loading}value={fileCount}label={t("preupload_media_found", {count: fileCount,})}/><StatCard+ loading={loading}value={albumCount}label={t("preupload_album_found", {count: albumCount,@@ -119,7 +152,12 @@ export function UploadConfirmationDialog({</Stack>{isTakeout && (- <Stack sx={{ gap: "20px" }}>+ <Stack+ sx={{+ gap: "20px",+ ...(loading && { opacity: 0.4 }),+ }}+ ><Typography component="h3" sx={sectionTitleSx}>{t("more_options")}</Typography>@@ -138,6 +176,7 @@ export function UploadConfirmationDialog({<EnteSwitchcolor="accent"checked={importFavorites}+ disabled={loading}onChange={onImportFavoritesChange}slotProps={{input: { "aria-label": t("favorites") },@@ -163,6 +202,7 @@ export function UploadConfirmationDialog({<EnteSwitchcolor="accent"checked={includePartnerSharedFiles}+ disabled={loading}onChange={onIncludePartnerSharedFilesChange}slotProps={{input: {@@ -181,20 +221,38 @@ export function UploadConfirmationDialog({<FocusVisibleButtonfullWidthcolor="accent"+ disabled={loading}onClick={onConfirm}sx={confirmButtonSx}>- {t(isTakeout ? "start_import" : "start_upload")}+ {loading ? (+ <>+ <Box component="span" sx={buttonSpinnerSx} />+ {t("calculating_title")}+ </>+ ) : (+ t(isTakeout ? "start_import" : "start_upload")+ )}</FocusVisibleButton></Stack></Dialog>);}-function StatCard({ value, label }: { value: number; label: string }) {+function StatCard({+ value,+ label,+ loading,+}: {+ value: number;+ label: string;+ loading: boolean;+}) {return (<Stack sx={statCardSx}>- <Typography sx={statValueSx}>{value.toLocaleString()}</Typography>+ <Typography sx={statValueSx}>+ {loading ? "β" : value.toLocaleString()}+ </Typography><Typography sx={captionSx}>{label}</Typography></Stack>);@@ -266,6 +324,14 @@ const successIllustrationSx = (theme: Theme) => ({...theme.applyStyles("dark", { backgroundColor: "rgba(8 194 37 / 0.16)" }),});+const calculatingDescriptionSx = {+ maxWidth: 420,+ color: "text.muted",+ fontSize: 14,+ fontWeight: 500,+ lineHeight: "20px",+};+const successIconSx = {display: "flex",width: 40,@@ -277,6 +343,24 @@ const successIconSx = {backgroundColor: green,};+const loadingIconSx = {+ ...successIconSx,+ animation: "upload-confirmation-fade-in 0.5s ease-out forwards",+ "@keyframes upload-confirmation-fade-in": {+ "0%": { opacity: 0 },+ "100%": { opacity: 1 },+ },+};++const loadingSpinnerSx = {+ display: "inline-flex",+ animation: "upload-confirmation-spin 3s linear infinite",+ "@keyframes upload-confirmation-spin": {+ from: { transform: "rotate(0deg)" },+ to: { transform: "rotate(360deg)" },+ },+};+const statsSx = { gap: "10px", minWidth: 0 };const statCardSx = (theme: Theme) => ({@@ -343,10 +427,11 @@ const switchSx = {const bodySx = { fontSize: 14, fontWeight: 500, lineHeight: "20px" };-const confirmButtonSx = {+const confirmButtonSx = (theme: Theme) => ({minHeight: 52,px: 3,py: "14px",+ gap: "10px",borderRadius: "20px",color: "#fff",backgroundColor: green,@@ -356,4 +441,29 @@ const confirmButtonSx = {lineHeight: "20px",textTransform: "none","&:hover": { backgroundColor: "#07ad21", boxShadow: "none" },-};+ "&.Mui-disabled": {+ color: "rgba(0 0 0 / 0.6)",+ backgroundColor: "rgba(0 0 0 / 0.12)",+ ...theme.applyStyles("dark", {+ color: "rgba(255 255 255 / 0.7)",+ backgroundColor: "rgba(255 255 255 / 0.12)",+ }),+ },+});++const buttonSpinnerSx = (theme: Theme) => ({+ display: "block",+ width: 16,+ height: 16,+ borderRadius: "50%",+ border: "2px solid rgba(0 0 0 / 0.2)",+ borderTopColor: "rgba(0 0 0 / 0.6)",+ animation: "upload-confirmation-spin 0.9s linear infinite",+ "@keyframes upload-confirmation-spin": {+ to: { transform: "rotate(360deg)" },+ },+ ...theme.applyStyles("dark", {+ borderColor: "rgba(255 255 255 / 0.24)",+ borderTopColor: "rgba(255 255 255 / 0.7)",+ }),+});diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 073858b096..515d9e0da1 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -89,12 +89,15 @@"takeout_help_prompt": "Still have questions?","takeout_help_action": "We're here to help","upload_to_ente": "Upload to Ente",+ "calculating_title": "Calculating Files",+ "calculating_takeout_description": "We're scanning your files to count what can be imported. This usually takes under a minute.",+ "calculating_upload_description": "We're counting the photos and videos in your selection. This usually takes under a minute.","ready_to_import": "Ready to import!","ready_to_upload": "Ready to upload!","preupload_media_found_one": "photo or video found","preupload_media_found": "photos and videos found",- "preupload_album_found_one": "album found",- "preupload_album_found": "albums found",+ "preupload_album_found_one": "album for this upload",+ "preupload_album_found": "albums for this upload","more_options": "More options","import_favorites_hint": "Carry over your favorites from Google Photos","partner_shared_photos": "Partner shared photos",