import React, { Component } from 'react'; import { FormGroup, Label, Input } from 'reactstrap'; import { convertFromBitrate, convertToBitrate } from '../bitrate'; class Throttle extends Component { constructor() { super(); this.setLimit = this.setLimit.bind(this); this.setUnit = this.setUnit.bind(this); this.state = { unit: "MiB/s" }; } setLimit(limit) { const { onChange } = this.props; const { unit } = this.state; const converted = limit <= 0 || limit === null ? limit : convertToBitrate(limit, unit); onChange && onChange(converted); } setUnit(unit) { const limit = convertFromBitrate(this.props.limit, this.state.unit); this.setState({ unit }); this.setLimit(limit); } render() { const { limit, legend, prop } = this.props; const { unit } = this.state; return (
{legend} {limit !== -1 && limit !== null &&
this.setLimit(parseFloat(e.target.value))} /> this.setUnit(e.target.value)} >
}
); } } export default class TorrentOptions extends Component { render() { const { start, startChanged, priority, priorityChanged, downloadThrottle, downloadThrottleChanged, uploadThrottle, uploadThrottleChanged, } = this.props; return (
{typeof start !== "undefined" && } priorityChanged(parseInt(e.target.value))} > downloadThrottleChanged(limit)} /> uploadThrottleChanged(limit)} />
); } }