mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
combined similar code into function. More readable function names
This commit is contained in:
@@ -118,25 +118,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
this.setState({sponsorTimeEdits});
|
this.setState({sponsorTimeEdits});
|
||||||
this.saveEditTimes();
|
this.saveEditTimes();
|
||||||
}}
|
}}
|
||||||
onWheel={(e) => {
|
onWheel={(e) => {this.changeTimesWhenScrolling(0, e, sponsorTime)}}>
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
</input>
|
</input>
|
||||||
|
|
||||||
{getCategoryActionType(sponsorTime.category) === CategoryActionType.Skippable ? (
|
{getCategoryActionType(sponsorTime.category) === CategoryActionType.Skippable ? (
|
||||||
@@ -158,24 +140,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
|
|
||||||
this.saveEditTimes();
|
this.saveEditTimes();
|
||||||
}}
|
}}
|
||||||
onWheel={(e) => {
|
onWheel={(e) => {this.changeTimesWhenScrolling(1, e, sponsorTime)}}>
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
</input>
|
</input>
|
||||||
|
|
||||||
<span id={"nowButton1" + this.idSuffix}
|
<span id={"nowButton1" + this.idSuffix}
|
||||||
@@ -282,8 +247,26 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wheelUpOrDown(e: React.WheelEvent): Boolean{
|
changeTimesWhenScrolling(index: number, e: React.WheelEvent, sponsorTime: SponsorTime): void {
|
||||||
// Returns true if the wheel scrolls up and false if the wheel scrolls down
|
const step = 0.01;
|
||||||
|
const sponsorTimeEdits = this.state.sponsorTimeEdits;
|
||||||
|
let timeAsNumber = utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[index]);
|
||||||
|
if (timeAsNumber !== null) {
|
||||||
|
if (this.isWheelScrollingUp(e)){
|
||||||
|
timeAsNumber += step;
|
||||||
|
}else if (timeAsNumber >= 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")
|
console.log("wheelUpOrDown")
|
||||||
if (e.deltaY < 0)
|
if (e.deltaY < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user