Manav Rathi 1 年之前
父節點
當前提交
49b5bff042

+ 17 - 9
web/apps/photos/src/components/Upload/Uploader.tsx

@@ -1,15 +1,8 @@
-import { useContext, useEffect, useRef, useState } from "react";
-
-import { t } from "i18next";
-import { Trans } from "react-i18next";
-import { getLatestCollections } from "services/collectionService";
-
-import UploadProgress from "./UploadProgress";
-
 import ElectronAPIs from "@ente/shared/electron";
 import ElectronAPIs from "@ente/shared/electron";
 import { CustomError } from "@ente/shared/error";
 import { CustomError } from "@ente/shared/error";
 import { addLogLine } from "@ente/shared/logging";
 import { addLogLine } from "@ente/shared/logging";
 import { logError } from "@ente/shared/sentry";
 import { logError } from "@ente/shared/sentry";
+import { isPromise } from "@ente/shared/utils";
 import DiscFullIcon from "@mui/icons-material/DiscFull";
 import DiscFullIcon from "@mui/icons-material/DiscFull";
 import UserNameInputDialog from "components/UserNameInputDialog";
 import UserNameInputDialog from "components/UserNameInputDialog";
 import {
 import {
@@ -18,10 +11,14 @@ import {
     UPLOAD_STAGES,
     UPLOAD_STAGES,
     UPLOAD_STRATEGY,
     UPLOAD_STRATEGY,
 } from "constants/upload";
 } from "constants/upload";
+import { t } from "i18next";
 import isElectron from "is-electron";
 import isElectron from "is-electron";
 import { AppContext } from "pages/_app";
 import { AppContext } from "pages/_app";
 import { GalleryContext } from "pages/gallery";
 import { GalleryContext } from "pages/gallery";
+import { useContext, useEffect, useRef, useState } from "react";
+import { Trans } from "react-i18next";
 import billingService from "services/billingService";
 import billingService from "services/billingService";
+import { getLatestCollections } from "services/collectionService";
 import ImportService from "services/importService";
 import ImportService from "services/importService";
 import {
 import {
     getPublicCollectionUID,
     getPublicCollectionUID,
@@ -52,7 +49,7 @@ import {
     UploadFileNames,
     UploadFileNames,
 } from "types/upload/ui";
 } from "types/upload/ui";
 import { getOrCreateAlbum } from "utils/collection";
 import { getOrCreateAlbum } from "utils/collection";
-import { downloadApp, waitAndRun } from "utils/common";
+import { downloadApp } from "utils/common";
 import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
 import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
 import {
 import {
     getDownloadAppMessage,
     getDownloadAppMessage,
@@ -65,6 +62,7 @@ import {
 } from "utils/upload";
 } from "utils/upload";
 import { isCanvasBlocked } from "utils/upload/isCanvasBlocked";
 import { isCanvasBlocked } from "utils/upload/isCanvasBlocked";
 import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
 import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
+import UploadProgress from "./UploadProgress";
 import UploadStrategyChoiceModal from "./UploadStrategyChoiceModal";
 import UploadStrategyChoiceModal from "./UploadStrategyChoiceModal";
 import UploadTypeSelector from "./UploadTypeSelector";
 import UploadTypeSelector from "./UploadTypeSelector";
 
 
@@ -844,3 +842,13 @@ export default function Uploader(props: Props) {
         </>
         </>
     );
     );
 }
 }
+
+async function waitAndRun(
+    waitPromise: Promise<void>,
+    task: () => Promise<void>,
+) {
+    if (waitPromise && isPromise(waitPromise)) {
+        await waitPromise;
+    }
+    await task();
+}

+ 10 - 5
web/apps/photos/src/pages/gallery/index.tsx

@@ -49,7 +49,7 @@ import {
     syncMapEnabled,
     syncMapEnabled,
     validateKey,
     validateKey,
 } from "services/userService";
 } from "services/userService";
-import { mergeMaps, preloadImage } from "utils/common";
+import { preloadImage } from "utils/common";
 import {
 import {
     FILE_OPS_TYPE,
     FILE_OPS_TYPE,
     constructFileToCollectionMap,
     constructFileToCollectionMap,
@@ -135,7 +135,6 @@ import {
 import { Search, SearchResultSummary, UpdateSearch } from "types/search";
 import { Search, SearchResultSummary, UpdateSearch } from "types/search";
 import { FamilyData } from "types/user";
 import { FamilyData } from "types/user";
 import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
 import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
-import { checkConnectivity } from "utils/common";
 import { isArchivedFile } from "utils/magicMetadata";
 import { isArchivedFile } from "utils/magicMetadata";
 import { getSessionExpiredMessage } from "utils/ui";
 import { getSessionExpiredMessage } from "utils/ui";
 import { getLocalFamilyData } from "utils/user/family";
 import { getLocalFamilyData } from "utils/user/family";
@@ -680,13 +679,13 @@ export default function Gallery() {
     };
     };
 
 
     const syncWithRemote = async (force = false, silent = false) => {
     const syncWithRemote = async (force = false, silent = false) => {
+        if (!navigator.onLine) return;
         if (syncInProgress.current && !force) {
         if (syncInProgress.current && !force) {
             resync.current = { force, silent };
             resync.current = { force, silent };
             return;
             return;
         }
         }
         syncInProgress.current = true;
         syncInProgress.current = true;
         try {
         try {
-            checkConnectivity();
             const token = getToken();
             const token = getToken();
             if (!token) {
             if (!token) {
                 return;
                 return;
@@ -719,8 +718,6 @@ export default function Gallery() {
                     clearKeys();
                     clearKeys();
                     router.push(PAGES.CREDENTIALS);
                     router.push(PAGES.CREDENTIALS);
                     break;
                     break;
-                case CustomError.NO_INTERNET_CONNECTION:
-                    break;
                 default:
                 default:
                     logError(e, "syncWithRemote failed");
                     logError(e, "syncWithRemote failed");
             }
             }
@@ -1252,3 +1249,11 @@ function useEffectSingleThreaded(
         main(deps);
         main(deps);
     }, deps);
     }, deps);
 }
 }
+
+const mergeMaps = <K, V>(map1: Map<K, V>, map2: Map<K, V>) => {
+    const mergedMap = new Map<K, V>(map1);
+    map2.forEach((value, key) => {
+        mergedMap.set(key, value);
+    });
+    return mergedMap;
+};

+ 0 - 27
web/apps/photos/src/utils/common/index.ts

@@ -1,13 +1,4 @@
 import { APP_DOWNLOAD_URL } from "@ente/shared/constants/urls";
 import { APP_DOWNLOAD_URL } from "@ente/shared/constants/urls";
-import { CustomError } from "@ente/shared/error";
-import { isPromise } from "@ente/shared/utils";
-
-export function checkConnectivity() {
-    if (navigator.onLine) {
-        return true;
-    }
-    throw new Error(CustomError.NO_INTERNET_CONNECTION);
-}
 
 
 export function downloadApp() {
 export function downloadApp() {
     openLink(APP_DOWNLOAD_URL, true);
     openLink(APP_DOWNLOAD_URL, true);
@@ -38,16 +29,6 @@ export function openLink(href: string, newTab?: boolean) {
     a.click();
     a.click();
 }
 }
 
 
-export async function waitAndRun(
-    waitPromise: Promise<void>,
-    task: () => Promise<void>,
-) {
-    if (waitPromise && isPromise(waitPromise)) {
-        await waitPromise;
-    }
-    await task();
-}
-
 export function isClipboardItemPresent() {
 export function isClipboardItemPresent() {
     return typeof ClipboardItem !== "undefined";
     return typeof ClipboardItem !== "undefined";
 }
 }
@@ -59,11 +40,3 @@ export function batch<T>(arr: T[], batchSize: number): T[][] {
     }
     }
     return batches;
     return batches;
 }
 }
-
-export const mergeMaps = <K, V>(map1: Map<K, V>, map2: Map<K, V>) => {
-    const mergedMap = new Map<K, V>(map1);
-    map2.forEach((value, key) => {
-        mergedMap.set(key, value);
-    });
-    return mergedMap;
-};

+ 0 - 1
web/packages/shared/error/index.ts

@@ -70,7 +70,6 @@ export const CustomError = {
     EXPORT_STOPPED: "export stopped",
     EXPORT_STOPPED: "export stopped",
     NO_EXPORT_FOLDER_SELECTED: "no export folder selected",
     NO_EXPORT_FOLDER_SELECTED: "no export folder selected",
     EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",
     EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",
-    NO_INTERNET_CONNECTION: "no internet connection",
     AUTH_KEY_NOT_FOUND: "auth key not found",
     AUTH_KEY_NOT_FOUND: "auth key not found",
     EXIF_DATA_NOT_FOUND: "exif data not found",
     EXIF_DATA_NOT_FOUND: "exif data not found",
     SELECT_FOLDER_ABORTED: "select folder aborted",
     SELECT_FOLDER_ABORTED: "select folder aborted",