feat: multiple files selected view (#1062)

This commit is contained in:
Aman Harwara
2022-06-03 12:19:22 +05:30
committed by GitHub
parent 462199406c
commit 4caf958659
17 changed files with 399 additions and 298 deletions

View File

@@ -193,7 +193,10 @@ const ApplicationView: FunctionComponent<Props> = ({ application, mainApplicatio
<> <>
<NotesContextMenu application={application} viewControllerManager={viewControllerManager} /> <NotesContextMenu application={application} viewControllerManager={viewControllerManager} />
<TagsContextMenuWrapper viewControllerManager={viewControllerManager} /> <TagsContextMenuWrapper viewControllerManager={viewControllerManager} />
<FileContextMenuWrapper viewControllerManager={viewControllerManager} /> <FileContextMenuWrapper
filesController={viewControllerManager.filesController}
selectionController={viewControllerManager.selectionController}
/>
<PurchaseFlowWrapper application={application} viewControllerManager={viewControllerManager} /> <PurchaseFlowWrapper application={application} viewControllerManager={viewControllerManager} />
<ConfirmSignoutContainer <ConfirmSignoutContainer
applicationGroup={mainApplicationGroup} applicationGroup={mainApplicationGroup}

View File

@@ -7,11 +7,9 @@ import { observer } from 'mobx-react-lite'
import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur' import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
import { ChallengeReason, ContentType, FileItem, SNNote } from '@standardnotes/snjs' import { ContentType, FileItem, SNNote } from '@standardnotes/snjs'
import { confirmDialog } from '@/Services/AlertService' import { addToast, 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 AttachedFilesPopover from './AttachedFilesPopover' import AttachedFilesPopover from './AttachedFilesPopover'
import { usePremiumModal } from '@/Hooks/usePremiumModal' import { usePremiumModal } from '@/Hooks/usePremiumModal'
import { PopoverTabs } from './PopoverTabs' import { PopoverTabs } from './PopoverTabs'
@@ -105,29 +103,6 @@ const AttachedFilesButton: FunctionComponent<Props> = ({
await toggleAttachedFilesMenu() await toggleAttachedFilesMenu()
}, [toggleAttachedFilesMenu, prospectivelyShowFilesPremiumModal]) }, [toggleAttachedFilesMenu, prospectivelyShowFilesPremiumModal])
const deleteFile = async (file: FileItem) => {
const shouldDelete = await confirmDialog({
text: `Are you sure you want to permanently delete "${file.name}"?`,
confirmButtonStyle: 'danger',
})
if (shouldDelete) {
const deletingToastId = addToast({
type: ToastType.Loading,
message: `Deleting file "${file.name}"...`,
})
await application.files.deleteFile(file)
addToast({
type: ToastType.Success,
message: `Deleted file "${file.name}"`,
})
dismissToast(deletingToastId)
}
}
const downloadFile = async (file: FileItem) => {
viewControllerManager.filesController.downloadFile(file).catch(console.error)
}
const attachFileToNote = useCallback( const attachFileToNote = useCallback(
async (file: FileItem) => { async (file: FileItem) => {
if (!note) { if (!note) {
@@ -143,98 +118,6 @@ const AttachedFilesButton: FunctionComponent<Props> = ({
[application.items, note], [application.items, note],
) )
const detachFileFromNote = async (file: FileItem) => {
if (!note) {
addToast({
type: ToastType.Error,
message: 'Could not attach file because selected note was deleted',
})
return
}
await application.items.disassociateFileWithNote(file, note)
}
const toggleFileProtection = async (file: FileItem) => {
let result: FileItem | undefined
if (file.protected) {
keepMenuOpen(true)
result = await application.mutator.unprotectFile(file)
keepMenuOpen(false)
buttonRef.current?.focus()
} else {
result = await application.mutator.protectFile(file)
}
const isProtected = result ? result.protected : file.protected
return isProtected
}
const authorizeProtectedActionForFile = async (file: FileItem, challengeReason: ChallengeReason) => {
const authorizedFiles = await application.protections.authorizeProtectedActionForItems([file], challengeReason)
const isAuthorized = authorizedFiles.length > 0 && authorizedFiles.includes(file)
return isAuthorized
}
const renameFile = async (file: FileItem, fileName: string) => {
await application.items.renameFile(file, fileName)
}
const handleFileAction = async (action: PopoverFileItemAction) => {
const file = action.type !== PopoverFileItemActionType.RenameFile ? action.payload : action.payload.file
let isAuthorizedForAction = true
if (file.protected && action.type !== PopoverFileItemActionType.ToggleFileProtection) {
keepMenuOpen(true)
isAuthorizedForAction = await authorizeProtectedActionForFile(file, ChallengeReason.AccessProtectedFile)
keepMenuOpen(false)
buttonRef.current?.focus()
}
if (!isAuthorizedForAction) {
return false
}
switch (action.type) {
case PopoverFileItemActionType.AttachFileToNote:
await attachFileToNote(file)
break
case PopoverFileItemActionType.DetachFileToNote:
await detachFileFromNote(file)
break
case PopoverFileItemActionType.DeleteFile:
await deleteFile(file)
break
case PopoverFileItemActionType.DownloadFile:
await downloadFile(file)
break
case PopoverFileItemActionType.ToggleFileProtection: {
const isProtected = await toggleFileProtection(file)
action.callback(isProtected)
break
}
case PopoverFileItemActionType.RenameFile:
await renameFile(file, action.payload.name)
break
case PopoverFileItemActionType.PreviewFile: {
keepMenuOpen(true)
const otherFiles = currentTab === PopoverTabs.AllFiles ? allFiles : attachedFiles
viewControllerManager.filePreviewModalController.activate(
file,
otherFiles.filter((file) => !file.protected),
)
break
}
}
if (
action.type !== PopoverFileItemActionType.DownloadFile &&
action.type !== PopoverFileItemActionType.PreviewFile
) {
application.sync.sync().catch(console.error)
}
return true
}
const [isDraggingFiles, setIsDraggingFiles] = useState(false) const [isDraggingFiles, setIsDraggingFiles] = useState(false)
const dragCounter = useRef(0) const dragCounter = useRef(0)
@@ -400,12 +283,11 @@ const AttachedFilesButton: FunctionComponent<Props> = ({
{open && ( {open && (
<AttachedFilesPopover <AttachedFilesPopover
application={application} application={application}
viewControllerManager={viewControllerManager} filesController={viewControllerManager.filesController}
attachedFiles={attachedFiles} attachedFiles={attachedFiles}
allFiles={allFiles} allFiles={allFiles}
closeOnBlur={closeOnBlur} closeOnBlur={closeOnBlur}
currentTab={currentTab} currentTab={currentTab}
handleFileAction={handleFileAction}
isDraggingFiles={isDraggingFiles} isDraggingFiles={isDraggingFiles}
setCurrentTab={setCurrentTab} setCurrentTab={setCurrentTab}
/> />

View File

@@ -1,6 +1,5 @@
import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants' import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants'
import { WebApplication } from '@/Application/Application' import { WebApplication } from '@/Application/Application'
import { ViewControllerManager } from '@/Services/ViewControllerManager'
import { FileItem } from '@standardnotes/snjs' import { FileItem } from '@standardnotes/snjs'
import { FilesIllustration } from '@standardnotes/icons' import { FilesIllustration } from '@standardnotes/icons'
import { observer } from 'mobx-react-lite' import { observer } from 'mobx-react-lite'
@@ -8,29 +7,28 @@ import { Dispatch, FunctionComponent, SetStateAction, useRef, useState } from 'r
import Button from '@/Components/Button/Button' import Button from '@/Components/Button/Button'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import PopoverFileItem from './PopoverFileItem' import PopoverFileItem from './PopoverFileItem'
import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverFileItemActionType } from './PopoverFileItemAction'
import { PopoverTabs } from './PopoverTabs' import { PopoverTabs } from './PopoverTabs'
import { FilesController } from '@/Controllers/FilesController'
type Props = { type Props = {
application: WebApplication application: WebApplication
viewControllerManager: ViewControllerManager filesController: FilesController
allFiles: FileItem[] allFiles: FileItem[]
attachedFiles: FileItem[] attachedFiles: FileItem[]
closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void
currentTab: PopoverTabs currentTab: PopoverTabs
handleFileAction: (action: PopoverFileItemAction) => Promise<boolean>
isDraggingFiles: boolean isDraggingFiles: boolean
setCurrentTab: Dispatch<SetStateAction<PopoverTabs>> setCurrentTab: Dispatch<SetStateAction<PopoverTabs>>
} }
const AttachedFilesPopover: FunctionComponent<Props> = ({ const AttachedFilesPopover: FunctionComponent<Props> = ({
application, application,
viewControllerManager, filesController,
allFiles, allFiles,
attachedFiles, attachedFiles,
closeOnBlur, closeOnBlur,
currentTab, currentTab,
handleFileAction,
isDraggingFiles, isDraggingFiles,
setCurrentTab, setCurrentTab,
}) => { }) => {
@@ -45,20 +43,31 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
: filesList : filesList
const handleAttachFilesClick = async () => { const handleAttachFilesClick = async () => {
const uploadedFiles = await viewControllerManager.filesController.uploadNewFile() const uploadedFiles = await filesController.uploadNewFile()
if (!uploadedFiles) { if (!uploadedFiles) {
return return
} }
if (currentTab === PopoverTabs.AttachedFiles) { if (currentTab === PopoverTabs.AttachedFiles) {
uploadedFiles.forEach((file) => { uploadedFiles.forEach((file) => {
handleFileAction({ filesController
type: PopoverFileItemActionType.AttachFileToNote, .handleFileAction({
payload: file, type: PopoverFileItemActionType.AttachFileToNote,
}).catch(console.error) payload: { file },
})
.catch(console.error)
}) })
} }
} }
const previewHandler = (file: FileItem) => {
filesController
.handleFileAction({
type: PopoverFileItemActionType.PreviewFile,
payload: { file, otherFiles: currentTab === PopoverTabs.AllFiles ? allFiles : attachedFiles },
})
.catch(console.error)
}
return ( return (
<div <div
className="flex flex-col" className="flex flex-col"
@@ -130,9 +139,10 @@ const AttachedFilesPopover: FunctionComponent<Props> = ({
key={file.uuid} key={file.uuid}
file={file} file={file}
isAttachedToNote={attachedFiles.includes(file)} isAttachedToNote={attachedFiles.includes(file)}
handleFileAction={handleFileAction} handleFileAction={filesController.handleFileAction}
getIconType={application.iconsController.getIconForFileType} getIconType={application.iconsController.getIconForFileType}
closeOnBlur={closeOnBlur} closeOnBlur={closeOnBlur}
previewHandler={previewHandler}
/> />
) )
}) })

View File

@@ -2,7 +2,15 @@ import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants'
import { KeyboardKey } from '@/Services/IOService' import { KeyboardKey } from '@/Services/IOService'
import { formatSizeToReadableString } from '@standardnotes/filepicker' import { formatSizeToReadableString } from '@standardnotes/filepicker'
import { FileItem } from '@standardnotes/snjs' import { FileItem } from '@standardnotes/snjs'
import { FormEventHandler, FunctionComponent, KeyboardEventHandler, useEffect, useRef, useState } from 'react' import {
FormEventHandler,
FunctionComponent,
KeyboardEventHandler,
useCallback,
useEffect,
useRef,
useState,
} from 'react'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import { PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverFileItemActionType } from './PopoverFileItemAction'
import PopoverFileSubmenu from './PopoverFileSubmenu' import PopoverFileSubmenu from './PopoverFileSubmenu'
@@ -15,6 +23,7 @@ const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
handleFileAction, handleFileAction,
getIconType, getIconType,
closeOnBlur, closeOnBlur,
previewHandler,
}) => { }) => {
const [fileName, setFileName] = useState(file.name) const [fileName, setFileName] = useState(file.name)
const [isRenamingFile, setIsRenamingFile] = useState(false) const [isRenamingFile, setIsRenamingFile] = useState(false)
@@ -27,37 +36,48 @@ const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
} }
}, [isRenamingFile]) }, [isRenamingFile])
const renameFile = async (file: FileItem, name: string) => { const renameFile = useCallback(
await handleFileAction({ async (file: FileItem, name: string) => {
type: PopoverFileItemActionType.RenameFile, if (name.length < 1) {
payload: { return
file, }
name,
},
})
setIsRenamingFile(false)
}
const handleFileNameInput: FormEventHandler<HTMLInputElement> = (event) => { await handleFileAction({
type: PopoverFileItemActionType.RenameFile,
payload: {
file,
name,
},
})
setIsRenamingFile(false)
},
[handleFileAction],
)
const handleFileNameInput: FormEventHandler<HTMLInputElement> = useCallback((event) => {
setFileName((event.target as HTMLInputElement).value) setFileName((event.target as HTMLInputElement).value)
} }, [])
const handleFileNameInputKeyDown: KeyboardEventHandler = (event) => { const handleFileNameInputKeyDown: KeyboardEventHandler = useCallback(
if (event.key === KeyboardKey.Enter) { (event) => {
itemRef.current?.focus() if (fileName.length > 0 && event.key === KeyboardKey.Enter) {
} itemRef.current?.focus()
} }
},
[fileName.length],
)
const handleFileNameInputBlur = () => { const handleFileNameInputBlur = useCallback(() => {
renameFile(file, fileName).catch(console.error) renameFile(file, fileName).catch(console.error)
} }, [file, fileName, renameFile])
const clickPreviewHandler = () => { const handleClick = useCallback(() => {
handleFileAction({ if (isRenamingFile) {
type: PopoverFileItemActionType.PreviewFile, return
payload: file, }
}).catch(console.error)
} previewHandler(file)
}, [file, isRenamingFile, previewHandler])
return ( return (
<div <div
@@ -65,7 +85,7 @@ const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
className="flex items-center justify-between p-3 focus:shadow-none" className="flex items-center justify-between p-3 focus:shadow-none"
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE} tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
> >
<div onClick={clickPreviewHandler} className="flex items-center cursor-pointer"> <div onClick={handleClick} className="flex items-center cursor-pointer">
{getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')} {getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')}
<div className="flex flex-col mx-4"> <div className="flex flex-col mx-4">
{isRenamingFile ? ( {isRenamingFile ? (
@@ -97,7 +117,7 @@ const PopoverFileItem: FunctionComponent<PopoverFileItemProps> = ({
handleFileAction={handleFileAction} handleFileAction={handleFileAction}
setIsRenamingFile={setIsRenamingFile} setIsRenamingFile={setIsRenamingFile}
closeOnBlur={closeOnBlur} closeOnBlur={closeOnBlur}
previewHandler={clickPreviewHandler} previewHandler={previewHandler}
/> />
</div> </div>
) )

View File

@@ -14,13 +14,19 @@ export type PopoverFileItemAction =
| { | {
type: Exclude< type: Exclude<
PopoverFileItemActionType, PopoverFileItemActionType,
PopoverFileItemActionType.RenameFile | PopoverFileItemActionType.ToggleFileProtection | PopoverFileItemActionType.RenameFile
| PopoverFileItemActionType.ToggleFileProtection
| PopoverFileItemActionType.PreviewFile
> >
payload: FileItem payload: {
file: FileItem
}
} }
| { | {
type: PopoverFileItemActionType.ToggleFileProtection type: PopoverFileItemActionType.ToggleFileProtection
payload: FileItem payload: {
file: FileItem
}
callback: (isProtected: boolean) => void callback: (isProtected: boolean) => void
} }
| { | {
@@ -30,3 +36,10 @@ export type PopoverFileItemAction =
name: string name: string
} }
} }
| {
type: PopoverFileItemActionType.PreviewFile
payload: {
file: FileItem
otherFiles: FileItem[]
}
}

View File

@@ -1,10 +1,21 @@
import { IconType, FileItem } from '@standardnotes/snjs' import { IconType, FileItem } from '@standardnotes/snjs'
import { Dispatch, SetStateAction } from 'react'
import { PopoverFileItemAction } from './PopoverFileItemAction' import { PopoverFileItemAction } from './PopoverFileItemAction'
export type PopoverFileItemProps = { type CommonProps = {
file: FileItem file: FileItem
isAttachedToNote: boolean isAttachedToNote: boolean
handleFileAction: (action: PopoverFileItemAction) => Promise<boolean> handleFileAction: (action: PopoverFileItemAction) => Promise<{
getIconType(type: string): IconType didHandleAction: boolean
}>
closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void
previewHandler: (file: FileItem) => void
}
export type PopoverFileItemProps = CommonProps & {
getIconType(type: string): IconType
}
export type PopoverFileSubmenuProps = CommonProps & {
setIsRenamingFile: Dispatch<SetStateAction<boolean>>
} }

View File

@@ -1,19 +1,14 @@
import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants' import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants'
import { calculateSubmenuStyle, SubmenuStyle } from '@/Utils/CalculateSubmenuStyle' import { calculateSubmenuStyle, SubmenuStyle } from '@/Utils/CalculateSubmenuStyle'
import { Disclosure, DisclosureButton, DisclosurePanel } from '@reach/disclosure' import { Disclosure, DisclosureButton, DisclosurePanel } from '@reach/disclosure'
import { Dispatch, FunctionComponent, SetStateAction, useCallback, useEffect, useRef, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import Switch from '@/Components/Switch/Switch' import Switch from '@/Components/Switch/Switch'
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur' import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
import { PopoverFileItemProps } from './PopoverFileItemProps' import { PopoverFileSubmenuProps } from './PopoverFileItemProps'
import { PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverFileItemActionType } from './PopoverFileItemAction'
type Props = Omit<PopoverFileItemProps, 'renameFile' | 'getIconType'> & { const PopoverFileSubmenu: FunctionComponent<PopoverFileSubmenuProps> = ({
setIsRenamingFile: Dispatch<SetStateAction<boolean>>
previewHandler: () => void
}
const PopoverFileSubmenu: FunctionComponent<Props> = ({
file, file,
isAttachedToNote, isAttachedToNote,
handleFileAction, handleFileAction,
@@ -88,7 +83,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onBlur={closeOnBlur} onBlur={closeOnBlur}
className="sn-dropdown-item focus:bg-info-backdrop" className="sn-dropdown-item focus:bg-info-backdrop"
onClick={() => { onClick={() => {
previewHandler() previewHandler(file)
closeMenu() closeMenu()
}} }}
> >
@@ -102,7 +97,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onClick={() => { onClick={() => {
handleFileAction({ handleFileAction({
type: PopoverFileItemActionType.DetachFileToNote, type: PopoverFileItemActionType.DetachFileToNote,
payload: file, payload: { file },
}).catch(console.error) }).catch(console.error)
closeMenu() closeMenu()
}} }}
@@ -117,7 +112,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onClick={() => { onClick={() => {
handleFileAction({ handleFileAction({
type: PopoverFileItemActionType.AttachFileToNote, type: PopoverFileItemActionType.AttachFileToNote,
payload: file, payload: { file },
}).catch(console.error) }).catch(console.error)
closeMenu() closeMenu()
}} }}
@@ -132,7 +127,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onClick={() => { onClick={() => {
handleFileAction({ handleFileAction({
type: PopoverFileItemActionType.ToggleFileProtection, type: PopoverFileItemActionType.ToggleFileProtection,
payload: file, payload: { file },
callback: (isProtected: boolean) => { callback: (isProtected: boolean) => {
setIsFileProtected(isProtected) setIsFileProtected(isProtected)
}, },
@@ -157,7 +152,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onClick={() => { onClick={() => {
handleFileAction({ handleFileAction({
type: PopoverFileItemActionType.DownloadFile, type: PopoverFileItemActionType.DownloadFile,
payload: file, payload: { file },
}).catch(console.error) }).catch(console.error)
closeMenu() closeMenu()
}} }}
@@ -181,7 +176,7 @@ const PopoverFileSubmenu: FunctionComponent<Props> = ({
onClick={() => { onClick={() => {
handleFileAction({ handleFileAction({
type: PopoverFileItemActionType.DeleteFile, type: PopoverFileItemActionType.DeleteFile,
payload: file, payload: { file },
}).catch(console.error) }).catch(console.error)
closeMenu() closeMenu()
}} }}

View File

@@ -1,20 +1,19 @@
import { MAX_MENU_SIZE_MULTIPLIER, MENU_MARGIN_FROM_APP_BORDER } from '@/Constants/Constants' import { MAX_MENU_SIZE_MULTIPLIER, MENU_MARGIN_FROM_APP_BORDER } from '@/Constants/Constants'
import { FilesController } from '@/Controllers/FilesController'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur' import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
import { useCloseOnClickOutside } from '@/Hooks/useCloseOnClickOutside' import { useCloseOnClickOutside } from '@/Hooks/useCloseOnClickOutside'
import { ViewControllerManager } from '@/Services/ViewControllerManager'
import { observer } from 'mobx-react-lite' import { observer } from 'mobx-react-lite'
import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import { PopoverFileItemAction } from '../AttachedFilesPopover/PopoverFileItemAction'
import { PopoverTabs } from '../AttachedFilesPopover/PopoverTabs'
import FileMenuOptions from './FileMenuOptions' import FileMenuOptions from './FileMenuOptions'
type Props = { type Props = {
viewControllerManager: ViewControllerManager filesController: FilesController
selectionController: SelectedItemsController
} }
const FileContextMenu: FunctionComponent<Props> = observer(({ viewControllerManager }) => { const FileContextMenu: FunctionComponent<Props> = observer(({ filesController, selectionController }) => {
const { selectedFiles, showFileContextMenu, setShowFileContextMenu, fileContextMenuLocation } = const { showFileContextMenu, setShowFileContextMenu, fileContextMenuLocation } = filesController
viewControllerManager.filesController
const [contextMenuStyle, setContextMenuStyle] = useState<React.CSSProperties>({ const [contextMenuStyle, setContextMenuStyle] = useState<React.CSSProperties>({
top: 0, top: 0,
@@ -24,9 +23,7 @@ const FileContextMenu: FunctionComponent<Props> = observer(({ viewControllerMana
const [contextMenuMaxHeight, setContextMenuMaxHeight] = useState<number | 'auto'>('auto') const [contextMenuMaxHeight, setContextMenuMaxHeight] = useState<number | 'auto'>('auto')
const contextMenuRef = useRef<HTMLDivElement>(null) const contextMenuRef = useRef<HTMLDivElement>(null)
const [closeOnBlur] = useCloseOnBlur(contextMenuRef, (open: boolean) => setShowFileContextMenu(open)) const [closeOnBlur] = useCloseOnBlur(contextMenuRef, (open: boolean) => setShowFileContextMenu(open))
useCloseOnClickOutside(contextMenuRef, () => viewControllerManager.filesController.setShowFileContextMenu(false)) useCloseOnClickOutside(contextMenuRef, () => filesController.setShowFileContextMenu(false))
const selectedFile = selectedFiles[0]
const reloadContextMenuLayout = useCallback(() => { const reloadContextMenuLayout = useCallback(() => {
const { clientHeight } = document.documentElement const { clientHeight } = document.documentElement
@@ -86,17 +83,6 @@ const FileContextMenu: FunctionComponent<Props> = observer(({ viewControllerMana
} }
}, [reloadContextMenuLayout]) }, [reloadContextMenuLayout])
const handleFileAction = useCallback(
async (action: PopoverFileItemAction) => {
const { didHandleAction } = await viewControllerManager.filesController.handleFileAction(
action,
PopoverTabs.AllFiles,
)
return didHandleAction
},
[viewControllerManager.filesController],
)
return ( return (
<div <div
ref={contextMenuRef} ref={contextMenuRef}
@@ -107,8 +93,8 @@ const FileContextMenu: FunctionComponent<Props> = observer(({ viewControllerMana
}} }}
> >
<FileMenuOptions <FileMenuOptions
file={selectedFile} filesController={filesController}
handleFileAction={handleFileAction} selectionController={selectionController}
closeOnBlur={closeOnBlur} closeOnBlur={closeOnBlur}
closeMenu={() => setShowFileContextMenu(false)} closeMenu={() => setShowFileContextMenu(false)}
shouldShowRenameOption={false} shouldShowRenameOption={false}
@@ -120,8 +106,9 @@ const FileContextMenu: FunctionComponent<Props> = observer(({ viewControllerMana
FileContextMenu.displayName = 'FileContextMenu' FileContextMenu.displayName = 'FileContextMenu'
const FileContextMenuWrapper: FunctionComponent<Props> = ({ viewControllerManager }) => { const FileContextMenuWrapper: FunctionComponent<Props> = ({ filesController, selectionController }) => {
const { selectedFiles, showFileContextMenu } = viewControllerManager.filesController const { showFileContextMenu } = filesController
const { selectedFiles } = selectionController
const selectedFile = selectedFiles[0] const selectedFile = selectedFiles[0]
@@ -129,7 +116,7 @@ const FileContextMenuWrapper: FunctionComponent<Props> = ({ viewControllerManage
return null return null
} }
return <FileContextMenu viewControllerManager={viewControllerManager} /> return <FileContextMenu filesController={filesController} selectionController={selectionController} />
} }
export default observer(FileContextMenuWrapper) export default observer(FileContextMenuWrapper)

View File

@@ -1,16 +1,17 @@
import { FunctionComponent, useCallback, useMemo } from 'react'
import { PopoverFileItemActionType } from '../AttachedFilesPopover/PopoverFileItemAction'
import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants' import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants'
import { FileItem } from '@standardnotes/snjs'
import { FunctionComponent } from 'react'
import { PopoverFileItemAction, PopoverFileItemActionType } from '../AttachedFilesPopover/PopoverFileItemAction'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import Switch from '@/Components/Switch/Switch' import Switch from '@/Components/Switch/Switch'
import { observer } from 'mobx-react-lite'
import { FilesController } from '@/Controllers/FilesController'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'
type Props = { type Props = {
closeMenu: () => void closeMenu: () => void
closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void
file: FileItem filesController: FilesController
fileProtectionToggleCallback?: (isProtected: boolean) => void selectionController: SelectedItemsController
handleFileAction: (action: PopoverFileItemAction) => Promise<boolean>
isFileAttachedToNote?: boolean isFileAttachedToNote?: boolean
renameToggleCallback?: (isRenamingFile: boolean) => void renameToggleCallback?: (isRenamingFile: boolean) => void
shouldShowRenameOption: boolean shouldShowRenameOption: boolean
@@ -20,72 +21,73 @@ type Props = {
const FileMenuOptions: FunctionComponent<Props> = ({ const FileMenuOptions: FunctionComponent<Props> = ({
closeMenu, closeMenu,
closeOnBlur, closeOnBlur,
file, filesController,
fileProtectionToggleCallback, selectionController,
handleFileAction,
isFileAttachedToNote, isFileAttachedToNote,
renameToggleCallback, renameToggleCallback,
shouldShowRenameOption, shouldShowRenameOption,
shouldShowAttachOption, shouldShowAttachOption,
}) => { }) => {
const { selectedFiles } = selectionController
const { handleFileAction } = filesController
const hasProtectedFiles = useMemo(() => selectedFiles.some((file) => file.protected), [selectedFiles])
const onPreview = useCallback(() => {
void handleFileAction({
type: PopoverFileItemActionType.PreviewFile,
payload: {
file: selectedFiles[0],
otherFiles: selectedFiles.length > 1 ? selectedFiles : filesController.allFiles,
},
})
closeMenu()
}, [closeMenu, filesController.allFiles, handleFileAction, selectedFiles])
const onDetach = useCallback(() => {
const file = selectedFiles[0]
void handleFileAction({
type: PopoverFileItemActionType.DetachFileToNote,
payload: { file },
})
closeMenu()
}, [closeMenu, handleFileAction, selectedFiles])
const onAttach = useCallback(() => {
const file = selectedFiles[0]
void handleFileAction({
type: PopoverFileItemActionType.AttachFileToNote,
payload: { file },
})
closeMenu()
}, [closeMenu, handleFileAction, selectedFiles])
return ( return (
<> <>
<button <button onBlur={closeOnBlur} className="sn-dropdown-item focus:bg-info-backdrop" onClick={onPreview}>
onBlur={closeOnBlur}
className="sn-dropdown-item focus:bg-info-backdrop"
onClick={() => {
handleFileAction({
type: PopoverFileItemActionType.PreviewFile,
payload: file,
}).catch(console.error)
closeMenu()
}}
>
<Icon type="file" className="mr-2 color-neutral" /> <Icon type="file" className="mr-2 color-neutral" />
Preview file Preview file
</button> </button>
{isFileAttachedToNote ? ( {selectedFiles.length === 1 && (
<button <>
onBlur={closeOnBlur} {isFileAttachedToNote ? (
className="sn-dropdown-item focus:bg-info-backdrop" <button onBlur={closeOnBlur} className="sn-dropdown-item focus:bg-info-backdrop" onClick={onDetach}>
onClick={() => { <Icon type="link-off" className="mr-2 color-neutral" />
handleFileAction({ Detach from note
type: PopoverFileItemActionType.DetachFileToNote, </button>
payload: file, ) : shouldShowAttachOption ? (
}).catch(console.error) <button onBlur={closeOnBlur} className="sn-dropdown-item focus:bg-info-backdrop" onClick={onAttach}>
closeMenu() <Icon type="link" className="mr-2 color-neutral" />
}} Attach to note
> </button>
<Icon type="link-off" className="mr-2 color-neutral" /> ) : null}
Detach from note </>
</button> )}
) : shouldShowAttachOption ? (
<button
onBlur={closeOnBlur}
className="sn-dropdown-item focus:bg-info-backdrop"
onClick={() => {
handleFileAction({
type: PopoverFileItemActionType.AttachFileToNote,
payload: file,
}).catch(console.error)
closeMenu()
}}
>
<Icon type="link" className="mr-2 color-neutral" />
Attach to note
</button>
) : null}
<div className="min-h-1px my-1 bg-border"></div> <div className="min-h-1px my-1 bg-border"></div>
<button <button
className="sn-dropdown-item justify-between focus:bg-info-backdrop" className="sn-dropdown-item justify-between focus:bg-info-backdrop"
onClick={() => { onClick={() => {
handleFileAction({ void filesController.setProtectionForFiles(!hasProtectedFiles, selectionController.selectedFiles)
type: PopoverFileItemActionType.ToggleFileProtection,
payload: file,
callback: (isProtected: boolean) => {
fileProtectionToggleCallback?.(isProtected)
},
}).catch(console.error)
}} }}
onBlur={closeOnBlur} onBlur={closeOnBlur}
> >
@@ -93,18 +95,18 @@ const FileMenuOptions: FunctionComponent<Props> = ({
<Icon type="password" className="mr-2 color-neutral" /> <Icon type="password" className="mr-2 color-neutral" />
Password protection Password protection
</span> </span>
<Switch className="px-0 pointer-events-none" tabIndex={FOCUSABLE_BUT_NOT_TABBABLE} checked={file.protected} /> <Switch
className="px-0 pointer-events-none"
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
checked={hasProtectedFiles}
/>
</button> </button>
<div className="min-h-1px my-1 bg-border"></div> <div className="min-h-1px my-1 bg-border"></div>
<button <button
onBlur={closeOnBlur} onBlur={closeOnBlur}
className="sn-dropdown-item focus:bg-info-backdrop" className="sn-dropdown-item focus:bg-info-backdrop"
onClick={() => { onClick={() => {
handleFileAction({ void filesController.downloadFiles(selectionController.selectedFiles)
type: PopoverFileItemActionType.DownloadFile,
payload: file,
}).catch(console.error)
closeMenu()
}} }}
> >
<Icon type="download" className="mr-2 color-neutral" /> <Icon type="download" className="mr-2 color-neutral" />
@@ -126,11 +128,7 @@ const FileMenuOptions: FunctionComponent<Props> = ({
onBlur={closeOnBlur} onBlur={closeOnBlur}
className="sn-dropdown-item focus:bg-info-backdrop" className="sn-dropdown-item focus:bg-info-backdrop"
onClick={() => { onClick={() => {
handleFileAction({ void filesController.deleteFilesPermanently(selectionController.selectedFiles)
type: PopoverFileItemActionType.DeleteFile,
payload: file,
}).catch(console.error)
closeMenu()
}} }}
> >
<Icon type="trash" className="mr-2 color-danger" /> <Icon type="trash" className="mr-2 color-danger" />
@@ -140,4 +138,4 @@ const FileMenuOptions: FunctionComponent<Props> = ({
) )
} }
export default FileMenuOptions export default observer(FileMenuOptions)

View File

@@ -0,0 +1,93 @@
import Icon from '@/Components/Icon/Icon'
import VisuallyHidden from '@reach/visually-hidden'
import { useCloseOnBlur } from '@/Hooks/useCloseOnBlur'
import { Disclosure, DisclosureButton, DisclosurePanel } from '@reach/disclosure'
import { useCallback, useRef, useState } from 'react'
import { observer } from 'mobx-react-lite'
import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants'
import FileMenuOptions from './FileMenuOptions'
import { FilesController } from '@/Controllers/FilesController'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'
type Props = {
filesController: FilesController
selectionController: SelectedItemsController
}
const FilesOptionsPanel = ({ filesController, selectionController }: Props) => {
const [open, setOpen] = useState(false)
const [position, setPosition] = useState({
top: 0,
right: 0,
})
const [maxHeight, setMaxHeight] = useState<number | 'auto'>('auto')
const buttonRef = useRef<HTMLButtonElement>(null)
const panelRef = useRef<HTMLDivElement>(null)
const [closeOnBlur] = useCloseOnBlur(panelRef, setOpen)
const onDisclosureChange = useCallback(async () => {
const rect = buttonRef.current?.getBoundingClientRect()
if (rect) {
const { clientHeight } = document.documentElement
const footerElementRect = document.getElementById('footer-bar')?.getBoundingClientRect()
const footerHeightInPx = footerElementRect?.height
if (footerHeightInPx) {
setMaxHeight(clientHeight - rect.bottom - footerHeightInPx - 2)
}
setPosition({
top: rect.bottom,
right: document.body.clientWidth - rect.right,
})
setOpen((open) => !open)
}
}, [])
return (
<Disclosure open={open} onChange={onDisclosureChange}>
<DisclosureButton
onKeyDown={(event) => {
if (event.key === 'Escape') {
setOpen(false)
}
}}
onBlur={closeOnBlur}
ref={buttonRef}
className="sn-icon-button border-contrast"
>
<VisuallyHidden>Actions</VisuallyHidden>
<Icon type="more" className="block" />
</DisclosureButton>
<DisclosurePanel
onKeyDown={(event) => {
if (event.key === 'Escape') {
setOpen(false)
buttonRef.current?.focus()
}
}}
ref={panelRef}
style={{
...position,
maxHeight,
}}
className="sn-dropdown sn-dropdown--animated min-w-80 max-h-120 max-w-xs flex flex-col py-2 overflow-y-auto fixed"
onBlur={closeOnBlur}
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
>
{open && (
<FileMenuOptions
filesController={filesController}
selectionController={selectionController}
closeOnBlur={closeOnBlur}
closeMenu={() => {
setOpen(false)
}}
shouldShowAttachOption={false}
shouldShowRenameOption={false}
/>
)}
</DisclosurePanel>
</Disclosure>
)
}
export default observer(FilesOptionsPanel)

View File

@@ -0,0 +1,41 @@
import { IlNotesIcon } from '@standardnotes/icons'
import { observer } from 'mobx-react-lite'
import Button from '../Button/Button'
import { useCallback } from 'react'
import FileOptionsPanel from '../FileContextMenu/FileOptionsPanel'
import { FilesController } from '@/Controllers/FilesController'
import { SelectedItemsController } from '@/Controllers/SelectedItemsController'
type Props = {
filesController: FilesController
selectionController: SelectedItemsController
}
const MultipleSelectedFiles = ({ filesController, selectionController }: Props) => {
const count = selectionController.selectedFilesCount
const cancelMultipleSelection = useCallback(() => {
selectionController.cancelMultipleSelection()
}, [selectionController])
return (
<div className="flex flex-col h-full items-center">
<div className="flex items-center justify-between p-4 w-full">
<h1 className="sk-h1 font-bold m-0">{count} selected files</h1>
<div className="flex">
<FileOptionsPanel filesController={filesController} selectionController={selectionController} />
</div>
</div>
<div className="flex-grow flex flex-col justify-center items-center w-full max-w-md">
<IlNotesIcon className="block" />
<h2 className="text-lg m-0 text-center mt-4">{count} selected files</h2>
<p className="text-sm mt-2 text-center max-w-60">Actions will be performed on all selected files.</p>
<Button className="mt-2.5" onClick={cancelMultipleSelection}>
Cancel multiple selection
</Button>
</div>
</div>
)
}
export default observer(MultipleSelectedFiles)

View File

@@ -3,10 +3,12 @@ import { PureComponent } from '@/Components/Abstract/PureComponent'
import { WebApplication } from '@/Application/Application' import { WebApplication } from '@/Application/Application'
import MultipleSelectedNotes from '@/Components/MultipleSelectedNotes/MultipleSelectedNotes' import MultipleSelectedNotes from '@/Components/MultipleSelectedNotes/MultipleSelectedNotes'
import NoteView from '@/Components/NoteView/NoteView' import NoteView from '@/Components/NoteView/NoteView'
import MultipleSelectedFiles from '../MultipleSelectedFiles/MultipleSelectedFiles'
import { ElementIds } from '@/Constants/ElementIDs' import { ElementIds } from '@/Constants/ElementIDs'
type State = { type State = {
showMultipleSelectedNotes: boolean showMultipleSelectedNotes: boolean
showMultipleSelectedFiles: boolean
controllers: NoteViewController[] controllers: NoteViewController[]
} }
@@ -21,6 +23,7 @@ class NoteGroupView extends PureComponent<Props, State> {
super(props, props.application) super(props, props.application)
this.state = { this.state = {
showMultipleSelectedNotes: false, showMultipleSelectedNotes: false,
showMultipleSelectedFiles: false,
controllers: [], controllers: [],
} }
} }
@@ -37,11 +40,21 @@ class NoteGroupView extends PureComponent<Props, State> {
}) })
this.autorun(() => { this.autorun(() => {
if (!this.viewControllerManager) {
return
}
if (this.viewControllerManager && this.viewControllerManager.notesController) { if (this.viewControllerManager && this.viewControllerManager.notesController) {
this.setState({ this.setState({
showMultipleSelectedNotes: this.viewControllerManager.notesController.selectedNotesCount > 1, showMultipleSelectedNotes: this.viewControllerManager.notesController.selectedNotesCount > 1,
}) })
} }
if (this.viewControllerManager.selectionController) {
this.setState({
showMultipleSelectedFiles: this.viewControllerManager.selectionController.selectedFilesCount > 1,
})
}
}) })
} }
@@ -59,6 +72,13 @@ class NoteGroupView extends PureComponent<Props, State> {
<MultipleSelectedNotes application={this.application} viewControllerManager={this.viewControllerManager} /> <MultipleSelectedNotes application={this.application} viewControllerManager={this.viewControllerManager} />
)} )}
{this.state.showMultipleSelectedFiles && (
<MultipleSelectedFiles
filesController={this.viewControllerManager.filesController}
selectionController={this.viewControllerManager.selectionController}
/>
)}
{!this.state.showMultipleSelectedNotes && ( {!this.state.showMultipleSelectedNotes && (
<> <>
{this.state.controllers.map((controller) => { {this.state.controllers.map((controller) => {

View File

@@ -106,9 +106,11 @@ export const Strings = {
protectingNoteWithoutProtectionSources: protectingNoteWithoutProtectionSources:
'Access to this note will not be restricted until you set up a passcode or account.', 'Access to this note will not be restricted until you set up a passcode or account.',
openAccountMenu: 'Open Account Menu', openAccountMenu: 'Open Account Menu',
trashNotesTitle: 'Move to Trash', trashItemsTitle: 'Move to Trash',
trashNotesText: 'Are you sure you want to move these notes to the trash?', trashNotesText: 'Are you sure you want to move these notes to the trash?',
trashFilesText: 'Are you sure you want to move these files to the trash?',
enterPasscode: 'Please enter a passcode.', enterPasscode: 'Please enter a passcode.',
deleteMultipleFiles: 'Are you sure you want to permanently delete these files?',
} }
export const StringUtils = { export const StringUtils = {
@@ -139,6 +141,9 @@ export const StringUtils = {
: 'Are you sure you want to move these notes to the trash?' : 'Are you sure you want to move these notes to the trash?'
} }
}, },
deleteFile(title: string): string {
return `Are you sure you want to permanently delete ${title}?`
},
archiveLockedNotesAttempt(archive: boolean, notesCount = 1): string { archiveLockedNotesAttempt(archive: boolean, notesCount = 1): string {
const archiveString = archive ? 'archive' : 'unarchive' const archiveString = archive ? 'archive' : 'unarchive'
return notesCount === 1 return notesCount === 1

View File

@@ -3,9 +3,9 @@ import {
PopoverFileItemAction, PopoverFileItemAction,
PopoverFileItemActionType, PopoverFileItemActionType,
} from '@/Components/AttachedFilesPopover/PopoverFileItemAction' } from '@/Components/AttachedFilesPopover/PopoverFileItemAction'
import { PopoverTabs } from '@/Components/AttachedFilesPopover/PopoverTabs'
import { BYTES_IN_ONE_MEGABYTE } from '@/Constants/Constants' import { BYTES_IN_ONE_MEGABYTE } from '@/Constants/Constants'
import { confirmDialog } from '@/Services/AlertService' import { confirmDialog } from '@/Services/AlertService'
import { Strings, StringUtils } from '@/Constants/Strings'
import { concatenateUint8Arrays } from '@/Utils/ConcatenateUint8Arrays' import { concatenateUint8Arrays } from '@/Utils/ConcatenateUint8Arrays'
import { import {
ClassicFileReader, ClassicFileReader,
@@ -16,11 +16,10 @@ import {
} from '@standardnotes/filepicker' } from '@standardnotes/filepicker'
import { ChallengeReason, ClientDisplayableError, ContentType, FileItem, InternalEventBus } from '@standardnotes/snjs' import { ChallengeReason, ClientDisplayableError, ContentType, FileItem, InternalEventBus } from '@standardnotes/snjs'
import { addToast, dismissToast, ToastType, updateToast } from '@standardnotes/stylekit' import { addToast, dismissToast, ToastType, updateToast } from '@standardnotes/stylekit'
import { action, computed, makeObservable, observable, reaction } from 'mobx' import { action, makeObservable, observable, reaction } from 'mobx'
import { WebApplication } from '../Application/Application' import { WebApplication } from '../Application/Application'
import { AbstractViewController } from './Abstract/AbstractViewController' import { AbstractViewController } from './Abstract/AbstractViewController'
import { NotesController } from './NotesController' import { NotesController } from './NotesController'
import { SelectedItemsController } from './SelectedItemsController'
const UnprotectedFileActions = [PopoverFileItemActionType.ToggleFileProtection] const UnprotectedFileActions = [PopoverFileItemActionType.ToggleFileProtection]
const NonMutatingFileActions = [PopoverFileItemActionType.DownloadFile, PopoverFileItemActionType.PreviewFile] const NonMutatingFileActions = [PopoverFileItemActionType.DownloadFile, PopoverFileItemActionType.PreviewFile]
@@ -36,14 +35,12 @@ export class FilesController extends AbstractViewController {
override deinit(): void { override deinit(): void {
super.deinit() super.deinit()
;(this.notesController as unknown) = undefined ;(this.notesController as unknown) = undefined
;(this.selectionController as unknown) = undefined
;(this.filePreviewModalController as unknown) = undefined ;(this.filePreviewModalController as unknown) = undefined
} }
constructor( constructor(
application: WebApplication, application: WebApplication,
private notesController: NotesController, private notesController: NotesController,
private selectionController: SelectedItemsController,
private filePreviewModalController: FilePreviewModalController, private filePreviewModalController: FilePreviewModalController,
eventBus: InternalEventBus, eventBus: InternalEventBus,
) { ) {
@@ -55,8 +52,6 @@ export class FilesController extends AbstractViewController {
showFileContextMenu: observable, showFileContextMenu: observable,
fileContextMenuLocation: observable, fileContextMenuLocation: observable,
selectedFiles: computed,
reloadAllFiles: action, reloadAllFiles: action,
reloadAttachedFiles: action, reloadAttachedFiles: action,
setShowFileContextMenu: action, setShowFileContextMenu: action,
@@ -80,10 +75,6 @@ export class FilesController extends AbstractViewController {
) )
} }
get selectedFiles(): FileItem[] {
return this.selectionController.getSelectedItems<FileItem>(ContentType.File)
}
setShowFileContextMenu = (enabled: boolean) => { setShowFileContextMenu = (enabled: boolean) => {
this.showFileContextMenu = enabled this.showFileContextMenu = enabled
} }
@@ -170,11 +161,10 @@ export class FilesController extends AbstractViewController {
handleFileAction = async ( handleFileAction = async (
action: PopoverFileItemAction, action: PopoverFileItemAction,
currentTab: PopoverTabs,
): Promise<{ ): Promise<{
didHandleAction: boolean didHandleAction: boolean
}> => { }> => {
const file = action.type !== PopoverFileItemActionType.RenameFile ? action.payload : action.payload.file const file = action.payload.file
let isAuthorizedForAction = true let isAuthorizedForAction = true
const requiresAuthorization = file.protected && !UnprotectedFileActions.includes(action.type) const requiresAuthorization = file.protected && !UnprotectedFileActions.includes(action.type)
@@ -211,10 +201,7 @@ export class FilesController extends AbstractViewController {
await this.renameFile(file, action.payload.name) await this.renameFile(file, action.payload.name)
break break
case PopoverFileItemActionType.PreviewFile: case PopoverFileItemActionType.PreviewFile:
this.filePreviewModalController.activate( this.filePreviewModalController.activate(file, action.payload.otherFiles)
file,
currentTab === PopoverTabs.AllFiles ? this.allFiles : this.attachedFiles,
)
break break
} }
@@ -399,4 +386,31 @@ export class FilesController extends AbstractViewController {
return undefined return undefined
} }
deleteFilesPermanently = async (files: FileItem[]) => {
const title = Strings.trashItemsTitle
const text = files.length === 1 ? StringUtils.deleteFile(files[0].name) : Strings.deleteMultipleFiles
if (
await confirmDialog({
title,
text,
confirmButtonStyle: 'danger',
})
) {
await Promise.all(files.map((file) => this.application.mutator.deleteItem(file)))
}
}
setProtectionForFiles = async (protect: boolean, files: FileItem[]) => {
if (protect) {
await this.application.mutator.protectItems(files)
} else {
await this.application.mutator.unprotectItems(files, ChallengeReason.UnprotectFile)
}
}
downloadFiles = async (files: FileItem[]) => {
await Promise.all(files.map((file) => this.downloadFile(file)))
}
} }

View File

@@ -257,7 +257,7 @@ export class NotesController extends AbstractViewController {
return false return false
} }
const title = Strings.trashNotesTitle const title = Strings.trashItemsTitle
let noteTitle = undefined let noteTitle = undefined
if (this.selectedNotesCount === 1) { if (this.selectedNotesCount === 1) {
const selectedNote = this.getSelectedNotesList()[0] const selectedNote = this.getSelectedNotesList()[0]

View File

@@ -35,6 +35,8 @@ export class SelectedItemsController extends AbstractViewController {
selectedItems: observable, selectedItems: observable,
selectedItemsCount: computed, selectedItemsCount: computed,
selectedFiles: computed,
selectedFilesCount: computed,
selectItem: action, selectItem: action,
setSelectedItems: action, setSelectedItems: action,
@@ -73,6 +75,14 @@ export class SelectedItemsController extends AbstractViewController {
return Object.keys(this.selectedItems).length return Object.keys(this.selectedItems).length
} }
get selectedFiles(): FileItem[] {
return this.getSelectedItems<FileItem>(ContentType.File)
}
get selectedFilesCount(): number {
return this.selectedFiles.length
}
getSelectedItems = <T extends ListableContentItem = ListableContentItem>(contentType?: ContentType): T[] => { getSelectedItems = <T extends ListableContentItem = ListableContentItem>(contentType?: ContentType): T[] => {
return Object.values(this.selectedItems).filter((item) => { return Object.values(this.selectedItems).filter((item) => {
return !contentType ? true : item.content_type === contentType return !contentType ? true : item.content_type === contentType

View File

@@ -97,7 +97,6 @@ export class ViewControllerManager {
this.filesController = new FilesController( this.filesController = new FilesController(
application, application,
this.notesController, this.notesController,
this.selectionController,
this.filePreviewModalController, this.filePreviewModalController,
this.eventBus, this.eventBus,
) )