Add partial segments to upload menu

This commit is contained in:
Ajay Ramachandran
2021-05-21 15:51:58 -04:00
parent 6879e90c16
commit 9392d16617
4 changed files with 40 additions and 44 deletions

View File

@@ -340,12 +340,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
deleteTime(): void {
const sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
const index = this.props.index;
//if it is not a complete sponsor time
if (sponsorTimes[index].segment.length < 2) {
//update video player
this.props.contentContainer().updateEditButtonsOnPlayer();
}
const removingIncomplete = sponsorTimes[index].segment.length < 2;
sponsorTimes.splice(index, 1);
@@ -357,13 +352,16 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
//if they are all removed
if (sponsorTimes.length == 0) {
this.props.submissionNotice.cancel();
//update video player
this.props.contentContainer().updateEditButtonsOnPlayer();
} else {
//update display
this.props.submissionNotice.forceUpdate();
}
//if it is not a complete segment, or all are removed
if (sponsorTimes.length === 0 || removingIncomplete) {
//update video player
this.props.contentContainer().updateEditButtonsOnPlayer();
}
}
configUpdate(): void {

View File

@@ -410,7 +410,7 @@ function migrateOldFormats(config: SBConfig) {
// Otherwise junk data
if (Array.isArray(jsonData)) {
const oldMap = new Map(jsonData);
oldMap.forEach((sponsorTimes: number[][], key) => {
oldMap.forEach((sponsorTimes: [number, number][], key) => {
const segmentTimes: SponsorTime[] = [];
for (const segment of sponsorTimes) {
segmentTimes.push({

View File

@@ -1,6 +1,6 @@
import Config from "./config";
import { SponsorTime, IncompleteSponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
import { ContentContainer } from "./types";
import Utils from "./utils";
@@ -84,9 +84,6 @@ utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYo
//this only happens if there is an error
let sponsorLookupRetries = 0;
/** Currently timed segment, which will be added to the unsubmitted segments when ready. */
let currentlyTimedSegment: IncompleteSponsorTime | null = null;
/** Segments created by the user which have not yet been submitted. */
let sponsorTimesSubmitting: SponsorTime[] = [];
@@ -136,7 +133,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
startOrEndTimingNewSegment()
sendResponse({
creatingSegment: currentlyTimedSegment !== null,
creatingSegment: isSegmentCreationInProgress(),
});
break;
@@ -157,7 +154,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
case "getVideoID":
sendResponse({
videoID: sponsorVideoID,
creatingSegment: currentlyTimedSegment !== null,
creatingSegment: isSegmentCreationInProgress(),
});
break;
@@ -305,7 +302,6 @@ async function videoIDChange(id) {
// Clear unsubmitted segments from the previous video
sponsorTimesSubmitting = [];
currentlyTimedSegment = null;
updateSponsorTimesSubmitting();
}
@@ -1144,7 +1140,7 @@ function updateEditButtonsOnPlayer(): void {
// Only check if buttons should be visible if they're enabled
if (buttonsEnabled) {
creatingSegment = currentlyTimedSegment !== null;
creatingSegment = isSegmentCreationInProgress();
// Show only if there are any segments to submit
submitButtonVisible = sponsorTimesSubmitting.length > 0;
@@ -1190,41 +1186,49 @@ function getRealCurrentTime(): number {
}
function startOrEndTimingNewSegment() {
if (!currentlyTimedSegment) {
// Start a new segment
currentlyTimedSegment = {
if (!isSegmentCreationInProgress()) {
sponsorTimesSubmitting.push({
segment: [getRealCurrentTime()],
UUID: null,
category: Config.config.defaultCategory,
};
});
} else {
// Finish creating the new segment
const existingTime = currentlyTimedSegment.segment[0];
const existingSegment = getIncompleteSegment();
const existingTime = existingSegment.segment[0];
const currentTime = getRealCurrentTime();
sponsorTimesSubmitting.push({
...currentlyTimedSegment,
// Swap timestamps if the user put the segment end before the start
segment: [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)],
});
currentlyTimedSegment = null;
existingSegment.segment = [Math.min(existingTime, currentTime), Math.max(existingTime, currentTime)];
}
// Save the newly created segment
Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting);
updateEditButtonsOnPlayer();
updateSponsorTimesSubmitting(false);
}
function getIncompleteSegment(): SponsorTime {
return sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1];
}
/** Is the latest submitting segment incomplete */
function isSegmentCreationInProgress(): boolean {
const segment = getIncompleteSegment();
return segment && segment?.segment?.length !== 2;
}
function cancelCreatingSegment() {
if (isSegmentCreationInProgress()) {
sponsorTimesSubmitting.splice(sponsorTimesSubmitting.length - 1, 1);
Config.config.segmentTimes.set(sponsorVideoID, sponsorTimesSubmitting);
}
updateEditButtonsOnPlayer();
updateSponsorTimesSubmitting(false);
}
function cancelCreatingSegment() {
currentlyTimedSegment = null;
updateEditButtonsOnPlayer();
}
function updateSponsorTimesSubmitting(getFromConfig = true) {
const segmentTimes = Config.config.segmentTimes.get(sponsorVideoID);
@@ -1500,7 +1504,6 @@ async function sendSubmitMessage() {
Config.config.segmentTimes.delete(sponsorVideoID);
// Add submissions to current sponsors list
// FIXME: segments from sponsorTimesSubmitting do not contain UUIDs .-.
sponsorTimes = (sponsorTimes || []).concat(sponsorTimesSubmitting);
// Increase contribution count
@@ -1511,7 +1514,6 @@ async function sendSubmitMessage() {
Config.config.submissionCountSinceCategories = Config.config.submissionCountSinceCategories + 1;
// Empty the submitting times
currentlyTimedSegment = null;
sponsorTimesSubmitting = [];
updatePreviewBar();

View File

@@ -52,7 +52,7 @@ export enum SponsorHideType {
}
export interface SponsorTime {
segment: number[];
segment: [number] | [number, number];
UUID: string;
category: string;
@@ -60,10 +60,6 @@ export interface SponsorTime {
hidden?: SponsorHideType;
}
export type IncompleteSponsorTime = Omit<SponsorTime, 'segment'> & {
segment: [number];
};
export interface PreviewBarOption {
color: string,
opacity: string