Skip to content

Commit

Permalink
Revert "Allow multiple files upload through web UI, including drag & …
Browse files Browse the repository at this point in the history
…drop (mastodon#9856)"

This reverts commit 750c676.
  • Loading branch information
masanbol committed Feb 3, 2019
1 parent 6769f53 commit 4ed2061
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/javascript/mastodon/actions/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function clearAlert() {
};
};

export function showAlert(title = messages.unexpectedTitle, message = messages.unexpectedMessage) {
export function showAlert(title, message) {
return {
type: ALERT_SHOW,
title,
Expand All @@ -44,6 +44,6 @@ export function showAlertForError(error) {
return showAlert(title, message);
} else {
console.error(error);
return showAlert();
return showAlert(messages.unexpectedTitle, messages.unexpectedMessage);
}
}
38 changes: 10 additions & 28 deletions app/javascript/mastodon/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import resizeImage from '../utils/resize_image';
import { importFetchedAccounts } from './importer';
import { updateTimeline } from './timelines';
import { showAlertForError } from './alerts';
import { showAlert } from './alerts';
import { defineMessages } from 'react-intl';

let cancelFetchComposeSuggestionsAccounts;

Expand Down Expand Up @@ -51,10 +49,6 @@ export const COMPOSE_UPLOAD_CHANGE_REQUEST = 'COMPOSE_UPLOAD_UPDATE_REQUEST'
export const COMPOSE_UPLOAD_CHANGE_SUCCESS = 'COMPOSE_UPLOAD_UPDATE_SUCCESS';
export const COMPOSE_UPLOAD_CHANGE_FAIL = 'COMPOSE_UPLOAD_UPDATE_FAIL';

const messages = defineMessages({
uploadErrorLimit: { id: 'upload_error.limit', defaultMessage: 'File upload limit exceeded.' },
});

export function changeCompose(text) {
return {
type: COMPOSE_CHANGE,
Expand Down Expand Up @@ -190,32 +184,20 @@ export function submitComposeFail(error) {

export function uploadCompose(files) {
return function (dispatch, getState) {
const uploadLimit = 4;
const media = getState().getIn(['compose', 'media_attachments']);
const total = Array.from(files).reduce((a, v) => a + v.size, 0);
const progress = new Array(files.length).fill(0);

if (files.length + media.size > uploadLimit) {
dispatch(showAlert(undefined, messages.uploadErrorLimit));
if (getState().getIn(['compose', 'media_attachments']).size > 3) {
return;
}

dispatch(uploadComposeRequest());

for (const [i, f] of Array.from(files).entries()) {
if (media.size + i > 3) break;

resizeImage(f).then(file => {
const data = new FormData();
data.append('file', file);

return api(getState).post('/api/v1/media', data, {
onUploadProgress: function({ loaded }){
progress[i] = loaded;
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
},
}).then(({ data }) => dispatch(uploadComposeSuccess(data)));
}).catch(error => dispatch(uploadComposeFail(error)));
};
resizeImage(files[0]).then(file => {
const data = new FormData();
data.append('file', file);

return api(getState).post('/api/v1/media', data, {
onUploadProgress: ({ loaded, total }) => dispatch(uploadComposeProgress(loaded, total)),
}).then(({ data }) => dispatch(uploadComposeSuccess(data)));
}).catch(error => dispatch(uploadComposeFail(error)));
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UploadButton extends ImmutablePureComponent {
key={resetFileKey}
ref={this.setRef}
type='file'
multiple
multiple={false}
accept={acceptContentTypes.toArray().join(',')}
onChange={this.handleChange}
disabled={disabled}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/features/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class UI extends React.PureComponent {
this.setState({ draggingOver: false });
this.dragTargets = [];

if (e.dataTransfer && e.dataTransfer.files.length >= 1) {
if (e.dataTransfer && e.dataTransfer.files.length === 1) {
this.props.dispatch(uploadCompose(e.dataTransfer.files));
}
}
Expand Down
11 changes: 1 addition & 10 deletions app/javascript/mastodon/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
],
"path": "app/javascript/mastodon/actions/alerts.json"
},
{
"descriptors": [
{
"defaultMessage": "File upload limit exceeded.",
"id": "upload_error.limit"
}
],
"path": "app/javascript/mastodon/actions/compose.json"
},
{
"descriptors": [
{
Expand Down Expand Up @@ -2294,4 +2285,4 @@
],
"path": "app/javascript/mastodon/features/video/index.json"
}
]
]
1 change: 0 additions & 1 deletion app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@
"ui.beforeunload": "Your draft will be lost if you leave Mastodon.",
"upload_area.title": "Drag & drop to upload",
"upload_button.label": "Add media (JPEG, PNG, GIF, WebM, MP4, MOV)",
"upload_error.limit": "File upload limit exceeded.",
"upload_form.description": "Describe for the visually impaired",
"upload_form.focus": "Change preview",
"upload_form.undo": "Delete",
Expand Down

0 comments on commit 4ed2061

Please sign in to comment.