diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index c527651a..bb10d17f 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -38,7 +38,8 @@ class SponsorTimeEditComponent extends React.Component void; previousSkipType: ActionType; - timeBeforeChangingToPOI: number; // Initialized when first selecting POI + // Used when selecting POI or Full + timesBeforeChanging: number[] = []; fullVideoWarningShown = false; constructor(props: SponsorTimeEditProps) { @@ -207,7 +208,7 @@ class SponsorTimeEditComponent extends React.Component this.saveEditTimes()}> + onChange={(e) => this.actionTypeSelectionChange(e)}> {this.getActionTypeOptions(sponsorTime)} @@ -379,21 +380,51 @@ class SponsorTimeEditComponent extends React.Component): void { + const sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index]; + + this.handleReplacingLostTimes(sponsorTime.category, event.target.value as ActionType); + this.saveEditTimes(); + } + + private handleReplacingLostTimes(category: Category, actionType: ActionType): void { + if (CompileConfig.categorySupport[category]?.includes(ActionType.Poi)) { + if (this.previousSkipType !== ActionType.Poi) { + this.timesBeforeChanging = [null, utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[1])]; + } + this.setTimeTo(1, null); this.props.contentContainer().updateEditButtonsOnPlayer(); if (this.props.contentContainer().sponsorTimesSubmitting - .some((segment, i) => segment.category === event.target.value && i !== this.props.index)) { + .some((segment, i) => segment.category === category && i !== this.props.index)) { alert(chrome.i18n.getMessage("poiOnlyOneSegment")); } - } else if (CompileConfig.categorySupport[event.target.value].includes(ActionType.Skip) && this.previousSkipType === ActionType.Poi) { - this.setTimeTo(1, this.timeBeforeChangingToPOI); - } - this.previousSkipType = CompileConfig.categorySupport[event.target.value].includes(ActionType.Poi) ? ActionType.Poi : ActionType.Skip; - this.saveEditTimes(); + this.previousSkipType = ActionType.Poi; + } else if (CompileConfig.categorySupport[category]?.length === 1 + && CompileConfig.categorySupport[category]?.[0] === ActionType.Full) { + if (this.previousSkipType !== ActionType.Full) { + this.timesBeforeChanging = [utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[0]), utils.getFormattedTimeToSeconds(this.state.sponsorTimeEdits[1])]; + } + + this.previousSkipType = ActionType.Full; + } else if (CompileConfig.categorySupport[category]?.includes(ActionType.Skip) + && ![ActionType.Poi, ActionType.Full].includes(this.getNextActionType(category, actionType)) && this.previousSkipType !== ActionType.Skip) { + if (this.timesBeforeChanging[0]) { + this.setTimeTo(0, this.timesBeforeChanging[0]); + } + if (this.timesBeforeChanging[1]) { + this.setTimeTo(1, this.timesBeforeChanging[1]); + } + + this.previousSkipType = ActionType.Skip; + } } getActionTypeOptions(sponsorTime: SponsorTime): React.ReactElement[] { @@ -476,9 +507,7 @@ class SponsorTimeEditComponent extends React.Component