From 42d68bddf9cb65ede4af3e860039e023f82b4644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 17 Sep 2022 09:29:36 +0200 Subject: [PATCH] handleDrop changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/features/ui/index.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/ui/index.tsx b/app/soapbox/features/ui/index.tsx index def4186f65..08d96e9205 100644 --- a/app/soapbox/features/ui/index.tsx +++ b/app/soapbox/features/ui/index.tsx @@ -4,7 +4,6 @@ import debounce from 'lodash/debounce'; import React, { useState, useEffect, useRef, useCallback } from 'react'; import { HotKeys } from 'react-hotkeys'; import { defineMessages, useIntl } from 'react-intl'; -import { useDispatch } from 'react-redux'; import { Switch, useHistory, useLocation, Redirect } from 'react-router-dom'; import { fetchFollowRequests } from 'soapbox/actions/accounts'; @@ -26,7 +25,7 @@ import Icon from 'soapbox/components/icon'; import SidebarNavigation from 'soapbox/components/sidebar-navigation'; import ThumbNavigation from 'soapbox/components/thumb_navigation'; import { Layout } from 'soapbox/components/ui'; -import { useAppSelector, useOwnAccount, useSoapboxConfig, useFeatures } from 'soapbox/hooks'; +import { useAppDispatch, useAppSelector, useOwnAccount, useSoapboxConfig, useFeatures } from 'soapbox/hooks'; import AdminPage from 'soapbox/pages/admin_page'; import DefaultPage from 'soapbox/pages/default_page'; // import GroupsPage from 'soapbox/pages/groups_page'; @@ -329,7 +328,7 @@ const SwitchingColumnsArea: React.FC = ({ children }) => { const UI: React.FC = ({ children }) => { const intl = useIntl(); const history = useHistory(); - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const [draggingOver, setDraggingOver] = useState(false); const [mobile, setMobile] = useState(isMobile(window.innerWidth)); @@ -386,9 +385,13 @@ const UI: React.FC = ({ children }) => { setDraggingOver(false); dragTargets.current = []; - if (e.dataTransfer && e.dataTransfer.files.length >= 1) { - dispatch(uploadCompose('home', e.dataTransfer.files, intl)); - } + dispatch((_, getState) => { + if (e.dataTransfer && e.dataTransfer.files.length >= 1) { + const modals = getState().modals; + const isModalOpen = modals.last()?.modalType === 'COMPOSE'; + dispatch(uploadCompose(isModalOpen ? 'compose-modal' : 'home', e.dataTransfer.files, intl)); + } + }); }; const handleDragLeave = (e: DragEvent) => {