From f3f598d6c75f6e33dc1d9e0a1839de5d7419706c Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sun, 3 Oct 2021 21:48:12 +0200 Subject: [PATCH] combined similar code into function. More readable function names --- src/components/SponsorTimeEditComponent.tsx | 61 ++++++++------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 0790e24f..7bafb9c9 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -118,25 +118,7 @@ class SponsorTimeEditComponent extends React.Component { - // Using mousewheel will increment the number in the edit box - const step = 0.01; - const sponsorTimeEdits = this.state.sponsorTimeEdits; - var timeAsNumber = utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[0]); - if (timeAsNumber !== null) { - if (this.wheelUpOrDown(e)){ - timeAsNumber += step; - }else if (timeAsNumber >= step){ - timeAsNumber -= step; - } else { - timeAsNumber = 0; - } - sponsorTimeEdits[0] = utils.getFormattedTime(timeAsNumber, true); - if (getCategoryActionType(sponsorTime.category) === CategoryActionType.POI) sponsorTimeEdits[1] = sponsorTimeEdits[0]; - this.setState({sponsorTimeEdits}); - this.saveEditTimes(); - } - }}> + onWheel={(e) => {this.changeTimesWhenScrolling(0, e, sponsorTime)}}> {getCategoryActionType(sponsorTime.category) === CategoryActionType.Skippable ? ( @@ -158,24 +140,7 @@ class SponsorTimeEditComponent extends React.Component { - // Using mousewheel will decrement the number in the edit box - const step = 0.01; - const sponsorTimeEdits = this.state.sponsorTimeEdits; - var timeAsNumber = utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[1]); - if (timeAsNumber !== null) { - if (this.wheelUpOrDown(e)){ - timeAsNumber += step; - }else if (timeAsNumber >= step){ - timeAsNumber -= step; - } else { - timeAsNumber = 0; - } - sponsorTimeEdits[1] = utils.getFormattedTime(timeAsNumber, true); - this.setState({sponsorTimeEdits}); - this.saveEditTimes(); - } - }}> + onWheel={(e) => {this.changeTimesWhenScrolling(1, e, sponsorTime)}}> = step){ + timeAsNumber -= step; + } else { + timeAsNumber = 0; + } + sponsorTimeEdits[index] = utils.getFormattedTime(timeAsNumber, true); + if (getCategoryActionType(sponsorTime.category) === CategoryActionType.POI) sponsorTimeEdits[1] = sponsorTimeEdits[0]; + this.setState({sponsorTimeEdits}); + this.saveEditTimes(); + } + } + + isWheelScrollingUp(e: React.WheelEvent): boolean { console.log("wheelUpOrDown") if (e.deltaY < 0) {