Add start of visual segment editing

This commit is contained in:
Ajay Ramachandran
2021-09-25 23:33:13 -04:00
parent 76d9a9afa9
commit 51d9edbbb4
6 changed files with 144 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import * as React from "react";
import * as CompileConfig from "../../config.json";
import Config from "../config";
import { ActionType, ActionTypes, Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
import { ActionType, Category, CategoryActionType, ContentContainer, SponsorTime } from "../types";
import Utils from "../utils";
import { getCategoryActionType } from "../utils/categoryUtils";
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";

View File

@@ -0,0 +1,116 @@
import * as React from "react";
import Config from "../config";
import { ContentContainer, VisualSegmentInfo } from "../types";
import Utils from "../utils";
const utils = new Utils();
export interface VisualSegmentEditProps {
index: number,
visual: VisualSegmentInfo,
idSuffix: string,
// Contains functions and variables from the content script needed by the skip notice
contentContainer: ContentContainer,
}
export interface VisualSegmentEditState {
}
class VisualSegmentEditComponent extends React.Component<VisualSegmentEditProps, VisualSegmentEditState> {
idSuffix: string;
configUpdateListener: () => void;
constructor(props: VisualSegmentEditProps) {
super(props);
this.idSuffix = this.props.idSuffix;
this.state = {
};
}
componentDidMount(): void {
// Add as a config listener
if (!this.configUpdateListener) {
this.configUpdateListener = () => this.configUpdate();
Config.configListeners.push(this.configUpdate.bind(this));
}
}
componentWillUnmount(): void {
if (this.configUpdateListener) {
Config.configListeners.splice(Config.configListeners.indexOf(this.configUpdate.bind(this)), 1);
}
}
render(): React.ReactElement {
return <>
<span id={`time${this.props.idSuffix}`}>
{utils.getFormattedTime(this.props.visual.time, true)}
</span>
<span>
-
</span>
{this.getBoundsElement()}
<span>
-
</span>
<input
type="checkBox"
onChange={(event) => this.colorUpdated(event)}
value={this.props.visual.color}
/>
<span>
Smooth
</span>
<span>
-
</span>
<input
className="categoryColorTextBox"
type="color"
onChange={(event) => this.colorUpdated(event)}
value={this.props.visual.color}
/>
</>
}
getBoundsElement(): React.ReactElement[] {
const elements: React.ReactElement[] = [];
for (const bound of this.props.visual.bounds) {
elements.push(
<span>
{`${bound[0] * 100}% x ${bound[0] * 100}%, `}
</span>
);
}
return elements;
}
colorUpdated(event: React.ChangeEvent<HTMLInputElement>): void {
this.props.visual.color = event.target.value;
}
configUpdate(): void {
this.forceUpdate();
}
}
export default VisualSegmentEditComponent;