|
| 1 | +import * as React from "react"; |
| 2 | +import Config from "../config"; |
| 3 | +import { ContentContainer, VisualSegmentInfo } from "../types"; |
| 4 | +import Utils from "../utils"; |
| 5 | + |
| 6 | + |
| 7 | +const utils = new Utils(); |
| 8 | + |
| 9 | +export interface VisualSegmentEditProps { |
| 10 | + index: number, |
| 11 | + |
| 12 | + visual: VisualSegmentInfo, |
| 13 | + |
| 14 | + idSuffix: string, |
| 15 | + // Contains functions and variables from the content script needed by the skip notice |
| 16 | + contentContainer: ContentContainer, |
| 17 | +} |
| 18 | + |
| 19 | +export interface VisualSegmentEditState { |
| 20 | + |
| 21 | +} |
| 22 | + |
| 23 | +class VisualSegmentEditComponent extends React.Component<VisualSegmentEditProps, VisualSegmentEditState> { |
| 24 | + |
| 25 | + idSuffix: string; |
| 26 | + |
| 27 | + configUpdateListener: () => void; |
| 28 | + |
| 29 | + constructor(props: VisualSegmentEditProps) { |
| 30 | + super(props); |
| 31 | + |
| 32 | + this.idSuffix = this.props.idSuffix; |
| 33 | + |
| 34 | + this.state = { |
| 35 | + }; |
| 36 | + } |
| 37 | + |
| 38 | + componentDidMount(): void { |
| 39 | + // Add as a config listener |
| 40 | + if (!this.configUpdateListener) { |
| 41 | + this.configUpdateListener = () => this.configUpdate(); |
| 42 | + Config.configListeners.push(this.configUpdate.bind(this)); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + componentWillUnmount(): void { |
| 47 | + if (this.configUpdateListener) { |
| 48 | + Config.configListeners.splice(Config.configListeners.indexOf(this.configUpdate.bind(this)), 1); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + render(): React.ReactElement { |
| 53 | + return <> |
| 54 | + <span id={`time${this.props.idSuffix}`}> |
| 55 | + {utils.getFormattedTime(this.props.visual.time, true)} |
| 56 | + </span> |
| 57 | + |
| 58 | + <span> |
| 59 | + - |
| 60 | + </span> |
| 61 | + |
| 62 | + {this.getBoundsElement()} |
| 63 | + |
| 64 | + <span> |
| 65 | + - |
| 66 | + </span> |
| 67 | + |
| 68 | + <input |
| 69 | + type="checkBox" |
| 70 | + onChange={(event) => this.colorUpdated(event)} |
| 71 | + value={this.props.visual.color} |
| 72 | + /> |
| 73 | + |
| 74 | + <span> |
| 75 | + Smooth |
| 76 | + </span> |
| 77 | + |
| 78 | + <span> |
| 79 | + - |
| 80 | + </span> |
| 81 | + |
| 82 | + <input |
| 83 | + className="categoryColorTextBox" |
| 84 | + type="color" |
| 85 | + onChange={(event) => this.colorUpdated(event)} |
| 86 | + value={this.props.visual.color} |
| 87 | + /> |
| 88 | + |
| 89 | + |
| 90 | + </> |
| 91 | + } |
| 92 | + |
| 93 | + getBoundsElement(): React.ReactElement[] { |
| 94 | + const elements: React.ReactElement[] = []; |
| 95 | + |
| 96 | + for (const bound of this.props.visual.bounds) { |
| 97 | + elements.push( |
| 98 | + <span> |
| 99 | + {`${bound[0] * 100}% x ${bound[0] * 100}%, `} |
| 100 | + </span> |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + return elements; |
| 105 | + } |
| 106 | + |
| 107 | + colorUpdated(event: React.ChangeEvent<HTMLInputElement>): void { |
| 108 | + this.props.visual.color = event.target.value; |
| 109 | + } |
| 110 | + |
| 111 | + configUpdate(): void { |
| 112 | + this.forceUpdate(); |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +export default VisualSegmentEditComponent; |
0 commit comments