import React, { Component } from 'react'; import { findDOMNode } from 'react-dom'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import { Progress, Collapse, Card, CardBlock } from 'reactstrap'; import FontAwesome from 'react-fontawesome'; import fetch from 'isomorphic-fetch'; import ws_send from '../socket'; class AddTorrent extends Component { constructor() { super(); this.state = { loading: false, customize: false, file: null }; } async handleTransferOffer(offer, file) { const headers = new Headers(); headers.append("Authorization", "Bearer " + offer.token); try { const resp = await fetch('http://localhost:8412/', { method: 'POST', body: file, headers: headers }); } catch (ex) { // TODO: synapse borks up this response console.log(ex); } } uploadFile() { this.setState({ loading: true }); const { file } = this.state; const { dispatch } = this.props; const reader = new FileReader(); reader.onload = e => { ws_send("UPLOAD_TORRENT", { size: file.size }, async offer => { switch (offer.type) { case "TRANSFER_OFFER": return await this.handleTransferOffer(offer, file); case "RESOURCES_EXTANT": const [id] = offer.ids; dispatch(push(`/torrents/${id}`)); break; } }); }; reader.readAsArrayBuffer(file); } handleFile(e) { const file = e.target.files[0]; this.setState({ file }); } render() { const { file, loading } = this.state; return (

Add torrent

{file ? file.name : ""}

TODO
{loading ? : null}
); } } export default connect()(AddTorrent);