forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing#3086] Enable Sidebar Drag and Drop with Multi-level Uploads Enhanced the Sketch Files sidebar to support drag-and-drop file uploads, improving accessibility and workflow. Details: • Introduced a wrapper component to handle drag-and-drop functionality. • Enabled multi-level uploads, allowing files to be uploaded into nested directories. • Updated initSidebarUpload to dynamically initialize uploads for the active folder or root directory. • Integrated drag-and-drop with <ConnectedFileNode> for seamless uploads. Improvements: • Simplified file upload process by removing the need for [+] > [Upload File]. • Enhanced user feedback with dynamic drag-over messages. This update improves user workflow and sets the foundation for future features like cross-sketch file duplication.
- Loading branch information
1 parent
9bd7c99
commit f4fd180
Showing
6 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
client/modules/IDE/components/SidebarFileDragDropUploadWrapper.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import Dropzone from 'dropzone'; | ||
import React, { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styled from 'styled-components'; | ||
import { fileExtensionsAndMimeTypes } from '../../../../server/utils/fileUtils'; | ||
import { | ||
dropzoneAcceptCallback, | ||
dropzoneCompleteCallback, | ||
dropzoneSendingCallback, | ||
s3BucketHttps | ||
} from '../actions/uploader'; | ||
import { selectActiveFile, selectRootFile } from '../selectors/files'; | ||
import { initSidebarUpload } from '../actions/ide'; | ||
|
||
Dropzone.autoDiscover = false; | ||
|
||
// Styled Components | ||
const Wrapper = styled.div` | ||
height: 100%; | ||
display: flex; | ||
position: relative; | ||
`; | ||
|
||
const HiddenInputContainer = styled.div``; | ||
|
||
const DraggingOverMessage = styled.div` | ||
position: absolute; | ||
height: 100%; | ||
width: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
color: rgba(255, 255, 255, 0.85); | ||
display: none; | ||
justify-content: center; | ||
align-items: center; | ||
text-align: center; | ||
padding: 1rem; | ||
font-weight: semibold; | ||
transition: background-color 0.3s ease; | ||
`; | ||
|
||
function SidebarFileDragDropUploadWrapper({ children }) { | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
const userId = useSelector((state) => state.user.id); | ||
|
||
const rootFile = useSelector(selectRootFile); | ||
const activeFile = useSelector(selectActiveFile); | ||
|
||
useEffect(() => { | ||
dispatch( | ||
initSidebarUpload( | ||
activeFile.fileType === 'folder' ? activeFile.id : rootFile.id | ||
) | ||
); | ||
|
||
let dragCounter = 0; | ||
|
||
const uploader = new Dropzone('div#sidebar-file-drag-drop-upload-wrapper', { | ||
url: s3BucketHttps, | ||
method: 'post', | ||
autoProcessQueue: false, | ||
clickable: false, | ||
hiddenInputContainer: '#sidebar-hidden-input-container', | ||
maxFiles: 6, | ||
parallelUploads: 1, | ||
maxFilesize: 5, // in MB | ||
maxThumbnailFilesize: 8, // in MB | ||
thumbnailWidth: 10, | ||
previewsContainer: false, | ||
thumbnailHeight: 10, | ||
acceptedFiles: fileExtensionsAndMimeTypes, | ||
dictDefaultMessage: t('FileUploader.DictDefaultMessage'), | ||
accept: (file, done) => { | ||
dropzoneAcceptCallback(userId, file, done); | ||
}, | ||
sending: dropzoneSendingCallback | ||
}); | ||
|
||
uploader.on('complete', (file) => { | ||
dispatch(dropzoneCompleteCallback(file)); | ||
}); | ||
|
||
uploader.on('dragenter', () => { | ||
dragCounter += 1; | ||
document.getElementById('dragging-over-message').style.display = 'flex'; | ||
}); | ||
|
||
uploader.on('dragleave', () => { | ||
dragCounter -= 1; | ||
|
||
if (dragCounter <= 0) { | ||
dragCounter = 0; | ||
document.getElementById('dragging-over-message').style.display = 'none'; | ||
} | ||
}); | ||
|
||
uploader.on('drop', () => { | ||
dragCounter = 0; | ||
document.getElementById('dragging-over-message').style.display = 'none'; | ||
}); | ||
|
||
return () => { | ||
uploader.off('complete'); | ||
uploader.off('dragenter'); | ||
uploader.off('dragleave'); | ||
uploader.off('drop'); | ||
uploader.destroy(); | ||
}; | ||
}, [userId, dispatch, t, activeFile]); | ||
|
||
return ( | ||
<Wrapper id="sidebar-file-drag-drop-upload-wrapper"> | ||
<HiddenInputContainer id="sidebar-hidden-input-container" /> | ||
{children} | ||
<DraggingOverMessage id="dragging-over-message"> | ||
{t('FileUploader.DictDefaultMessage')} | ||
</DraggingOverMessage> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
SidebarFileDragDropUploadWrapper.propTypes = { | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
export default SidebarFileDragDropUploadWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters