This commit is contained in:
Manav Rathi 2024-04-07 10:24:36 +05:30
parent 7c0ab6dd8a
commit 49b5bff042
No known key found for this signature in database
4 changed files with 27 additions and 42 deletions

View file

@ -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 { CustomError } from "@ente/shared/error";
import { addLogLine } from "@ente/shared/logging";
import { logError } from "@ente/shared/sentry";
import { isPromise } from "@ente/shared/utils";
import DiscFullIcon from "@mui/icons-material/DiscFull";
import UserNameInputDialog from "components/UserNameInputDialog";
import {
@ -18,10 +11,14 @@ import {
UPLOAD_STAGES,
UPLOAD_STRATEGY,
} from "constants/upload";
import { t } from "i18next";
import isElectron from "is-electron";
import { AppContext } from "pages/_app";
import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useRef, useState } from "react";
import { Trans } from "react-i18next";
import billingService from "services/billingService";
import { getLatestCollections } from "services/collectionService";
import ImportService from "services/importService";
import {
getPublicCollectionUID,
@ -52,7 +49,7 @@ import {
UploadFileNames,
} from "types/upload/ui";
import { getOrCreateAlbum } from "utils/collection";
import { downloadApp, waitAndRun } from "utils/common";
import { downloadApp } from "utils/common";
import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
import {
getDownloadAppMessage,
@ -65,6 +62,7 @@ import {
} from "utils/upload";
import { isCanvasBlocked } from "utils/upload/isCanvasBlocked";
import { SetCollectionNamerAttributes } from "../Collections/CollectionNamer";
import UploadProgress from "./UploadProgress";
import UploadStrategyChoiceModal from "./UploadStrategyChoiceModal";
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();
}

View file

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

View file

@ -1,13 +1,4 @@
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() {
openLink(APP_DOWNLOAD_URL, true);
@ -38,16 +29,6 @@ export function openLink(href: string, newTab?: boolean) {
a.click();
}
export async function waitAndRun(
waitPromise: Promise<void>,
task: () => Promise<void>,
) {
if (waitPromise && isPromise(waitPromise)) {
await waitPromise;
}
await task();
}
export function isClipboardItemPresent() {
return typeof ClipboardItem !== "undefined";
}
@ -59,11 +40,3 @@ export function batch<T>(arr: T[], batchSize: number): T[][] {
}
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;
};

View file

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