From e2a6b5ee8130639cc919c7f9a2f5e8ea9901c1e1 Mon Sep 17 00:00:00 2001 From: Kyrylo Gliebov Date: Thu, 4 Oct 2018 17:45:36 +0200 Subject: [PATCH] Switch to Slider instead of ProgressBar --- package.json | 1 + src/player.jsx | 81 +++++++++++++--------- src/recordings.css | 8 ++- src/recordings.jsx | 4 +- src/slider.html | 163 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 223 insertions(+), 34 deletions(-) create mode 100644 src/slider.html diff --git a/package.json b/package.json index cfb1fc9..f7c581f 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@babel/polyfill": "^7.0.0", "bootstrap": "3.3.7", "bootstrap-datetime-picker": "2.4.4", + "bootstrap-slider": "^10.2.1", "comment-json": "^1.1.3", "fs.extra": "^1.3.2", "fs.realpath": "^1.0.0", diff --git a/src/player.jsx b/src/player.jsx index 6cd9bcf..86d1ba7 100644 --- a/src/player.jsx +++ b/src/player.jsx @@ -24,6 +24,7 @@ let Term = require("term.js-cockpit"); let Journal = require("journal"); let $ = require("jquery"); require("console.css"); +require("bootstrap-slider"); /* * Get an object field, verifying its presence and type. @@ -460,32 +461,57 @@ let PacketBuffer = class { } }; -let ProgressBar = class extends React.Component { +class Slider extends React.Component { constructor(props) { super(props); - this.jumpTo = this.jumpTo.bind(this); + this.slideStart = this.slideStart.bind(this); + this.slideStop = this.slideStop.bind(this); + this.slider = null; + this.state = { + paused: false, + }; } - jumpTo(e) { + slideStart(e) { + this.setState({paused: this.props.paused}); + this.props.pause(); + } + + slideStop(e) { if (this.props.fastForwardFunc) { - let percent = parseInt((e.nativeEvent.offsetX * 100) / e.currentTarget.clientWidth); - let ts = parseInt((this.props.length * percent) / 100); - this.props.fastForwardFunc(ts); + this.props.fastForwardFunc(e); + if (this.state.paused === false) { + this.props.play(); + } } } - render() { - let progress = { - "width": parseInt((this.props.mark * 100) / this.props.length) + "%" - }; + componentDidMount() { + this.slider = $("#slider").slider({ + value: 0, + tooltip: "hide", + enabled: false, + }); + this.slider.slider('on', 'slideStart', this.slideStart); + this.slider.slider('on', 'slideStop', this.slideStop); + } + componentDidUpdate() { + if (this.props.length) { + this.slider.slider('enable'); + this.slider.slider('setAttribute', 'max', this.props.length); + } + if (this.props.mark) { + this.slider.slider('setValue', this.props.mark); + } + } + + render () { return ( -
-
-
+ ); } -}; +} class InputPlayer extends React.Component { render() { @@ -506,6 +532,8 @@ export class Player extends React.Component { this.handleTitleChange = this.handleTitleChange.bind(this); this.rewindToStart = this.rewindToStart.bind(this); this.playPauseToggle = this.playPauseToggle.bind(this); + this.play = this.play.bind(this); + this.pause = this.pause.bind(this); this.speedUp = this.speedUp.bind(this); this.speedDown = this.speedDown.bind(this); this.speedReset = this.speedReset.bind(this); @@ -769,6 +797,14 @@ export class Player extends React.Component { this.setState({paused: !this.state.paused}); } + play() { + this.setState({paused: false}); + } + + pause() { + this.setState({paused: true}); + } + speedUp() { let speedExp = this.state.speedExp; if (speedExp < 4) { @@ -1010,17 +1046,6 @@ export class Player extends React.Component { "float": "right", }; - const progressbar_style = { - 'marginTop': '10px', - }; - - const currentTsPost = function(currentTS, bufLength) { - if (currentTS > bufLength) { - return bufLength; - } - return currentTS; - }; - let error = ""; if (this.state.error) { error = ( @@ -1047,6 +1072,7 @@ export class Player extends React.Component {
+