diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index 00653830..3594eea3 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import type { + AddTorrentByFileOptions, AddTorrentByURLOptions, CheckTorrentsOptions, DeleteTorrentsOptions, @@ -41,18 +42,18 @@ const TorrentActions = { }, ), - addTorrentsByFiles: (formData: FormData, destination: string) => + addTorrentsByFiles: (options: AddTorrentByFileOptions) => axios - .post(`${baseURI}api/client/add-files`, formData) + .post(`${baseURI}api/client/add-files`, options) .then((json) => json.data) .then( - (response) => { + (data) => { AppDispatcher.dispatchServerAction({ type: 'CLIENT_ADD_TORRENT_SUCCESS', data: { - count: formData.getAll('torrents').length, - destination, - response, + count: options.files.length, + destination: options.destination, + data, }, }); }, diff --git a/client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.js b/client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.tsx similarity index 61% rename from client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.js rename to client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.tsx index 0e06cb63..60a5af84 100644 --- a/client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.js +++ b/client/src/javascript/components/modals/add-torrents-modal/AddTorrentsByFile.tsx @@ -1,26 +1,43 @@ -import {FormattedMessage, injectIntl} from 'react-intl'; +import {FormattedMessage, injectIntl, WrappedComponentProps} from 'react-intl'; import Dropzone from 'react-dropzone'; import React from 'react'; import {Form, FormRow, FormRowItem, Textbox} from '../../../ui'; import AddTorrentsActions from './AddTorrentsActions'; -import Close from '../../icons/Close'; -import File from '../../icons/File'; -import Files from '../../icons/Files'; +import CloseIcon from '../../icons/Close'; +import FileIcon from '../../icons/File'; +import FilesIcon from '../../icons/Files'; import SettingsStore from '../../../stores/SettingsStore'; import TorrentActions from '../../../actions/TorrentActions'; import TorrentDestination from '../../general/filesystem/TorrentDestination'; -class AddTorrentsByFile extends React.Component { - formRef = null; +interface AddTorrentsByFileFormData { + destination: string; + start: boolean; + tags: string; + isBasePath: boolean; +} - constructor(props) { +interface AddTorrentsByFileStates { + errors: Record; + files: Array<{ + name: string; + data: string; + }>; + tags: string; + isAddingTorrents: boolean; +} + +class AddTorrentsByFile extends React.Component { + formRef: Form | null = null; + + constructor(props: WrappedComponentProps) { super(props); this.state = { errors: {}, - isAddingTorrents: false, files: [], tags: '', + isAddingTorrents: false, }; } @@ -31,19 +48,23 @@ class AddTorrentsByFile extends React.Component { const files = this.state.files.map((file, index) => (
  • - + {file.name} this.handleFileRemove(index)}> - +
  • )); fileContent = ( -