From 7b1a89ca90bc8c9b65887d08f9ee06519a33b8da Mon Sep 17 00:00:00 2001 From: Luminarys Date: Tue, 13 Mar 2018 17:40:46 -0700 Subject: [PATCH] Improve throttle UX Closes #9 --- src/ui/throttle.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ui/throttle.js b/src/ui/throttle.js index 720a343..b4ac4ce 100644 --- a/src/ui/throttle.js +++ b/src/ui/throttle.js @@ -11,26 +11,34 @@ export default class Throttle extends Component { super(); this.setLimit = this.setLimit.bind(this); this.setUnit = this.setUnit.bind(this); - this.state = { unit: "MiB/s" }; + this.state = { custom: 1024 * 1024, unit: "MiB/s" }; } setLimit(limit) { const { onChange } = this.props; const { unit } = this.state; + let custom = this.props.limit; + if (custom <= 0 || custom === null) { + custom = this.state.custom; + } + if (isNaN(limit)) { + limit = 0; + } const converted = limit <= 0 || limit === null ? limit : convertToBitrate(limit, unit); onChange && onChange(converted); + this.setState({ unit, custom }); } setUnit(unit) { const limit = convertFromBitrate(this.props.limit, this.state.unit); - this.setState({ unit }); + this.setState({ unit, custom: this.state.custom }); this.setLimit(limit); } render() { const { global, limit, legend, prop } = this.props; - const { unit } = this.state; + const { unit, custom } = this.state; return (
@@ -65,7 +73,7 @@ export default class Throttle extends Component { type="radio" name={prop} id={`${prop}-custom`} - onChange={e => this.setLimit(1)} + onChange={e => this.setLimit(convertFromBitrate(custom, unit))} checked={limit !== -1 && limit !== null} /> Custom