From c981cdced4e55cee806e32a17d3963df2696a1d1 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Thu, 5 May 2022 22:29:15 +0530 Subject: [PATCH] feat: drag file on tab button to switch to that tab (#1013) --- .../AttachedFilesButton.tsx | 31 +++++++------------ .../AttachedFilesPopover.tsx | 8 ++--- .../AttachedFilesPopover/PopoverTabs.ts | 4 +++ 3 files changed, 18 insertions(+), 25 deletions(-) create mode 100644 app/assets/javascripts/Components/AttachedFilesPopover/PopoverTabs.ts diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx index 08ab451d0..8c878d802 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesButton.tsx @@ -13,9 +13,10 @@ import { confirmDialog } from '@/Services/AlertService' import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit' import { StreamingFileReader } from '@standardnotes/filepicker' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' -import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover' +import { AttachedFilesPopover } from './AttachedFilesPopover' import { usePremiumModal } from '@/Hooks/usePremiumModal' import { useFilePreviewModal } from '../Files/FilePreviewModalProvider' +import { PopoverTabs } from './PopoverTabs' type Props = { application: WebApplication @@ -23,21 +24,6 @@ type Props = { onClickPreprocessing?: () => Promise } -const createDragOverlay = () => { - if (document.getElementById('drag-overlay')) { - return - } - - const overlayElementTemplate = - '
' - const overlayFragment = document.createRange().createContextualFragment(overlayElementTemplate) - document.body.appendChild(overlayFragment) -} - -const removeDragOverlay = () => { - document.getElementById('drag-overlay')?.remove() -} - const isHandlingFileDrag = (event: DragEvent) => event.dataTransfer?.items && Array.from(event.dataTransfer.items).some((item) => item.kind === 'file') @@ -252,11 +238,19 @@ export const AttachedFilesButton: FunctionComponent = observer( event.preventDefault() event.stopPropagation() + switch ((event.target as HTMLElement).id) { + case PopoverTabs.AllFiles: + setCurrentTab(PopoverTabs.AllFiles) + break + case PopoverTabs.AttachedFiles: + setCurrentTab(PopoverTabs.AttachedFiles) + break + } + dragCounter.current = dragCounter.current + 1 if (event.dataTransfer?.items.length) { setIsDraggingFiles(true) - createDragOverlay() if (!open) { toggleAttachedFilesMenu().catch(console.error) } @@ -279,8 +273,6 @@ export const AttachedFilesButton: FunctionComponent = observer( return } - removeDragOverlay() - setIsDraggingFiles(false) } @@ -294,7 +286,6 @@ export const AttachedFilesButton: FunctionComponent = observer( event.stopPropagation() setIsDraggingFiles(false) - removeDragOverlay() if (event.dataTransfer?.items.length) { Array.from(event.dataTransfer.items).forEach(async (item) => { diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx index 15221a5ad..f3e471b07 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/AttachedFilesPopover.tsx @@ -10,11 +10,7 @@ import { Button } from '@/Components/Button/Button' import { Icon } from '@/Components/Icon' import { PopoverFileItem } from './PopoverFileItem' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' - -export enum PopoverTabs { - AttachedFiles, - AllFiles, -} +import { PopoverTabs } from './PopoverTabs' type Props = { application: WebApplication @@ -75,6 +71,7 @@ export const AttachedFilesPopover: FunctionComponent = observer( >