feat: drag file on tab button to switch to that tab (#1013)
This commit is contained in:
@@ -13,9 +13,10 @@ import { confirmDialog } from '@/Services/AlertService'
|
|||||||
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
|
import { addToast, dismissToast, ToastType } from '@standardnotes/stylekit'
|
||||||
import { StreamingFileReader } from '@standardnotes/filepicker'
|
import { StreamingFileReader } from '@standardnotes/filepicker'
|
||||||
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
import { AttachedFilesPopover, PopoverTabs } from './AttachedFilesPopover'
|
import { AttachedFilesPopover } from './AttachedFilesPopover'
|
||||||
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
||||||
import { useFilePreviewModal } from '../Files/FilePreviewModalProvider'
|
import { useFilePreviewModal } from '../Files/FilePreviewModalProvider'
|
||||||
|
import { PopoverTabs } from './PopoverTabs'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -23,21 +24,6 @@ type Props = {
|
|||||||
onClickPreprocessing?: () => Promise<void>
|
onClickPreprocessing?: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const createDragOverlay = () => {
|
|
||||||
if (document.getElementById('drag-overlay')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const overlayElementTemplate =
|
|
||||||
'<div class="sn-component" id="drag-overlay"><div class="absolute top-0 left-0 w-full h-full z-index-1001"></div></div>'
|
|
||||||
const overlayFragment = document.createRange().createContextualFragment(overlayElementTemplate)
|
|
||||||
document.body.appendChild(overlayFragment)
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeDragOverlay = () => {
|
|
||||||
document.getElementById('drag-overlay')?.remove()
|
|
||||||
}
|
|
||||||
|
|
||||||
const isHandlingFileDrag = (event: DragEvent) =>
|
const isHandlingFileDrag = (event: DragEvent) =>
|
||||||
event.dataTransfer?.items && Array.from(event.dataTransfer.items).some((item) => item.kind === 'file')
|
event.dataTransfer?.items && Array.from(event.dataTransfer.items).some((item) => item.kind === 'file')
|
||||||
|
|
||||||
@@ -252,11 +238,19 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
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
|
dragCounter.current = dragCounter.current + 1
|
||||||
|
|
||||||
if (event.dataTransfer?.items.length) {
|
if (event.dataTransfer?.items.length) {
|
||||||
setIsDraggingFiles(true)
|
setIsDraggingFiles(true)
|
||||||
createDragOverlay()
|
|
||||||
if (!open) {
|
if (!open) {
|
||||||
toggleAttachedFilesMenu().catch(console.error)
|
toggleAttachedFilesMenu().catch(console.error)
|
||||||
}
|
}
|
||||||
@@ -279,8 +273,6 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
removeDragOverlay()
|
|
||||||
|
|
||||||
setIsDraggingFiles(false)
|
setIsDraggingFiles(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +286,6 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
|
|||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
setIsDraggingFiles(false)
|
setIsDraggingFiles(false)
|
||||||
removeDragOverlay()
|
|
||||||
|
|
||||||
if (event.dataTransfer?.items.length) {
|
if (event.dataTransfer?.items.length) {
|
||||||
Array.from(event.dataTransfer.items).forEach(async (item) => {
|
Array.from(event.dataTransfer.items).forEach(async (item) => {
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ import { Button } from '@/Components/Button/Button'
|
|||||||
import { Icon } from '@/Components/Icon'
|
import { Icon } from '@/Components/Icon'
|
||||||
import { PopoverFileItem } from './PopoverFileItem'
|
import { PopoverFileItem } from './PopoverFileItem'
|
||||||
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction'
|
||||||
|
import { PopoverTabs } from './PopoverTabs'
|
||||||
export enum PopoverTabs {
|
|
||||||
AttachedFiles,
|
|
||||||
AllFiles,
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -75,6 +71,7 @@ export const AttachedFilesPopover: FunctionComponent<Props> = observer(
|
|||||||
>
|
>
|
||||||
<div className="flex border-0 border-b-1 border-solid border-main">
|
<div className="flex border-0 border-b-1 border-solid border-main">
|
||||||
<button
|
<button
|
||||||
|
id={PopoverTabs.AttachedFiles}
|
||||||
className={`bg-default border-0 cursor-pointer px-3 py-2.5 relative focus:bg-info-backdrop focus:shadow-bottom ${
|
className={`bg-default border-0 cursor-pointer px-3 py-2.5 relative focus:bg-info-backdrop focus:shadow-bottom ${
|
||||||
currentTab === PopoverTabs.AttachedFiles ? 'color-info font-medium shadow-bottom' : 'color-text'
|
currentTab === PopoverTabs.AttachedFiles ? 'color-info font-medium shadow-bottom' : 'color-text'
|
||||||
}`}
|
}`}
|
||||||
@@ -86,6 +83,7 @@ export const AttachedFilesPopover: FunctionComponent<Props> = observer(
|
|||||||
Attached
|
Attached
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
id={PopoverTabs.AllFiles}
|
||||||
className={`bg-default border-0 cursor-pointer px-3 py-2.5 relative focus:bg-info-backdrop focus:shadow-bottom ${
|
className={`bg-default border-0 cursor-pointer px-3 py-2.5 relative focus:bg-info-backdrop focus:shadow-bottom ${
|
||||||
currentTab === PopoverTabs.AllFiles ? 'color-info font-medium shadow-bottom' : 'color-text'
|
currentTab === PopoverTabs.AllFiles ? 'color-info font-medium shadow-bottom' : 'color-text'
|
||||||
}`}
|
}`}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum PopoverTabs {
|
||||||
|
AttachedFiles = 'attached-files-tab',
|
||||||
|
AllFiles = 'all-files-tab',
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user