2024-03-25 21:29:55 +11:00
|
|
|
import { useRef, useCallback } from 'react';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
2016-11-19 01:36:16 +11:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
import { changeMediaOrder } from 'mastodon/actions/compose';
|
2016-11-14 05:08:52 +11:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
import { Upload } from './upload';
|
|
|
|
import { UploadProgress } from './upload_progress';
|
2017-05-12 22:44:10 +10:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
export const UploadForm = () => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const mediaIds = useSelector(state => state.getIn(['compose', 'media_attachments']).map(item => item.get('id')));
|
|
|
|
const active = useSelector(state => state.getIn(['compose', 'is_uploading']));
|
|
|
|
const progress = useSelector(state => state.getIn(['compose', 'progress']));
|
|
|
|
const isProcessing = useSelector(state => state.getIn(['compose', 'is_processing']));
|
2016-11-14 05:08:52 +11:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
const dragItem = useRef();
|
|
|
|
const dragOverItem = useRef();
|
2017-09-28 23:31:31 +10:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
const handleDragStart = useCallback(id => {
|
|
|
|
dragItem.current = id;
|
|
|
|
}, [dragItem]);
|
2016-11-14 05:08:52 +11:00
|
|
|
|
2024-03-25 21:29:55 +11:00
|
|
|
const handleDragEnter = useCallback(id => {
|
|
|
|
dragOverItem.current = id;
|
|
|
|
}, [dragOverItem]);
|
|
|
|
|
|
|
|
const handleDragEnd = useCallback(() => {
|
|
|
|
dispatch(changeMediaOrder(dragItem.current, dragOverItem.current));
|
|
|
|
dragItem.current = null;
|
|
|
|
dragOverItem.current = null;
|
|
|
|
}, [dispatch, dragItem, dragOverItem]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<UploadProgress active={active} progress={progress} isProcessing={isProcessing} />
|
|
|
|
|
|
|
|
{mediaIds.size > 0 && (
|
|
|
|
<div className='compose-form__uploads'>
|
|
|
|
{mediaIds.map(id => (
|
|
|
|
<Upload
|
|
|
|
key={id}
|
|
|
|
id={id}
|
|
|
|
onDragStart={handleDragStart}
|
|
|
|
onDragEnter={handleDragEnter}
|
|
|
|
onDragEnd={handleDragEnd}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|