import React, { useEffect, useState } from 'react'; import tw from 'twin.macro'; import { Button } from '@/components/elements/button/index'; import Fade from '@/components/elements/Fade'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import useFileManagerSwr from '@/plugins/useFileManagerSwr'; import useFlash from '@/plugins/useFlash'; import compressFiles from '@/api/server/files/compressFiles'; import { ServerContext } from '@/state/server'; import deleteFiles from '@/api/server/files/deleteFiles'; import RenameFileModal from '@/components/server/files/RenameFileModal'; import Portal from '@/components/elements/Portal'; import { Dialog } from '@/components/elements/dialog'; const MassActionsBar = () => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const { mutate } = useFileManagerSwr(); const { clearFlashes, clearAndAddHttpError } = useFlash(); const [ loading, setLoading ] = useState(false); const [ loadingMessage, setLoadingMessage ] = useState(''); const [ showConfirm, setShowConfirm ] = useState(false); const [ showMove, setShowMove ] = useState(false); const directory = ServerContext.useStoreState(state => state.files.directory); const selectedFiles = ServerContext.useStoreState(state => state.files.selectedFiles); const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles); useEffect(() => { if (!loading) setLoadingMessage(''); }, [ loading ]); const onClickCompress = () => { setLoading(true); clearFlashes('files'); setLoadingMessage('Archiving files...'); compressFiles(uuid, directory, selectedFiles) .then(() => mutate()) .then(() => setSelectedFiles([])) .catch(error => clearAndAddHttpError({ key: 'files', error })) .then(() => setLoading(false)); }; const onClickConfirmDeletion = () => { setLoading(true); setShowConfirm(false); clearFlashes('files'); setLoadingMessage('Deleting files...'); deleteFiles(uuid, directory, selectedFiles) .then(() => { mutate(files => files.filter(f => selectedFiles.indexOf(f.name) < 0), false); setSelectedFiles([]); }) .catch(error => { mutate(); clearAndAddHttpError({ key: 'files', error }); }) .then(() => setLoading(false)); }; return ( <>
{loadingMessage} setShowConfirm(false)} onConfirmed={onClickConfirmDeletion} >

Are you sure you want to delete  {selectedFiles.length} files? This is a permanent action and the files cannot be recovered.

{selectedFiles.slice(0, 15).map(file => (
  • {file}
  • )) } {selectedFiles.length > 15 &&
  • and {selectedFiles.length - 15} others
  • }
    {showMove && setShowMove(false)} /> }
    0} unmountOnExit>
    setShowConfirm(true)}> Delete
    ); }; export default MassActionsBar;