π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[desktop] Fix drag and drop on watch folders dialog
Manav Rathife16c0128e02
diff --git a/web/apps/photos/src/components/FullScreenDropZone.tsx b/web/apps/photos/src/components/FullScreenDropZone.tsxindex 97c7275259..173e666bfa 100644--- a/web/apps/photos/src/components/FullScreenDropZone.tsx+++ b/web/apps/photos/src/components/FullScreenDropZone.tsx@@ -57,26 +57,6 @@ export default function FullScreenDropZone(props: Props) {});}, []);- useEffect(() => {- const handleWatchFolderDrop = (e: DragEvent) => {- if (!appContext.watchFolderView) {- return;- }-- e.preventDefault();- e.stopPropagation();- const files = e.dataTransfer.files;- if (files.length > 0) {- appContext.setWatchFolderFiles(files);- }- };-- addEventListener("drop", handleWatchFolderDrop);- return () => {- removeEventListener("drop", handleWatchFolderDrop);- };- }, [appContext.watchFolderView]);-return (<DropDiv{...props.getDragAndDropRootProps({diff --git a/web/apps/photos/src/components/WatchFolder.tsx b/web/apps/photos/src/components/WatchFolder.tsxindex 7d24fac833..fb8f089c27 100644--- a/web/apps/photos/src/components/WatchFolder.tsx+++ b/web/apps/photos/src/components/WatchFolder.tsx@@ -12,7 +12,7 @@ import { basename, dirname } from "@/base/file-name";import type { CollectionMapping, FolderWatch } from "@/base/types/ipc";import { CollectionMappingChoice } from "@/new/photos/components/CollectionMappingChoice";import { DialogCloseIconButton } from "@/new/photos/components/mui/Dialog";-import { AppContext, useAppContext } from "@/new/photos/types/context";+import { useAppContext } from "@/new/photos/types/context";import {FlexWrapper,SpaceBetweenFlex,@@ -34,7 +34,7 @@ import {styled,} from "@mui/material";import { t } from "i18next";-import React, { useContext, useEffect, useState } from "react";+import React, { useEffect, useState } from "react";import watcher from "services/watch";/**@@ -56,30 +56,35 @@ export const WatchFolder: React.FC<ModalVisibilityProps> = ({const { show: showMappingChoice, props: mappingChoiceVisibilityProps } =useModalVisibility();- const appContext = useContext(AppContext);-useEffect(() => {watcher.getWatches().then((ws) => setWatches(ws));}, []);useEffect(() => {- if (- appContext.watchFolderFiles &&- appContext.watchFolderFiles.length > 0- ) {- handleFolderDrop(appContext.watchFolderFiles);- appContext.setWatchFolderFiles(null);- }- }, [appContext.watchFolderFiles]);+ const handleWatchFolderDrop = (e: DragEvent) => {+ if (!open) return;++ e.preventDefault();+ e.stopPropagation();- const handleFolderDrop = async (folders: FileList) => {- // eslint-disable-next-line @typescript-eslint/prefer-for-of- for (let i = 0; i < folders.length; i++) {- const folder: any = folders[i];- const path = (folder.path as string).replace(/\\/g, "/");- if (await ensureElectron().fs.isDir(path)) {- await selectCollectionMappingAndAddWatch(path);+ for (const file of e.dataTransfer.files) {+ void selectCollectionMappingAndAddWatchIfDirectory(file);}+ };++ addEventListener("drop", handleWatchFolderDrop);+ return () => {+ removeEventListener("drop", handleWatchFolderDrop);+ };+ }, [open]);++ const selectCollectionMappingAndAddWatchIfDirectory = async (+ file: File,+ ) => {+ const electron = ensureElectron();+ const path = electron.pathForFile(file);+ if (await electron.fs.isDir(path)) {+ await selectCollectionMappingAndAddWatch(path);}};diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 97471a2b9b..238cf02dcc 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -61,7 +61,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {const [loading, setLoading] = useState(false);const [watchFolderView, setWatchFolderView] = useState(false);- const [watchFolderFiles, setWatchFolderFiles] = useState<FileList>(null);useEffect(() => {const user = getData(LS_KEYS.USER) as User | undefined | null;@@ -165,8 +164,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {hideLoadingBar,watchFolderView,setWatchFolderView,- watchFolderFiles,- setWatchFolderFiles,themeColor,setThemeColor,showMiniDialog,@@ -178,7 +175,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {showLoadingBar,hideLoadingBar,watchFolderView,- watchFolderFiles,themeColor,showMiniDialog,showNotification,diff --git a/web/packages/new/photos/types/context.ts b/web/packages/new/photos/types/context.tsindex 90eef58794..5a9e21816d 100644--- a/web/packages/new/photos/types/context.ts+++ b/web/packages/new/photos/types/context.ts@@ -27,8 +27,6 @@ export type AppContextT = AccountsContextT & {onGenericError: (error: unknown) => void;watchFolderView: boolean;setWatchFolderView: (isOpen: boolean) => void;- watchFolderFiles: FileList;- setWatchFolderFiles: (files: FileList) => void;themeColor: THEME_COLOR;setThemeColor: (themeColor: THEME_COLOR) => void;};