Added basic react submission confirmation notice

This commit is contained in:
Ajay Ramachandran
2020-03-11 17:50:50 -04:00
parent a02aef591e
commit a182354254
10 changed files with 307 additions and 38 deletions

View File

@@ -0,0 +1,141 @@
import * as React from "react";
import Config from "../config"
import NoticeComponent from "./NoticeComponent";
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
import SponsorTimeEditComponent from "./SponsorTimeEditComponent";
export interface SkipNoticeProps {
// Contains functions and variables from the content script needed by the skip notice
contentContainer: () => any;
callback: () => any;
}
export interface SkipNoticeState {
noticeTitle: string,
messages: string[],
idSuffix: string;
}
class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeState> {
// Contains functions and variables from the content script needed by the skip notice
contentContainer: () => any;
callback: () => any;
noticeRef: React.MutableRefObject<NoticeComponent>;
constructor(props: SkipNoticeProps) {
super(props);
this.noticeRef = React.createRef();
this.contentContainer = props.contentContainer;
this.callback = props.callback;
let noticeTitle = chrome.i18n.getMessage("confirmNoticeTitle");
// Setup state
this.state = {
noticeTitle,
messages: [],
idSuffix: "SubmissionNotice"
}
}
render() {
let noticeStyle: React.CSSProperties = {};
if (this.contentContainer().onMobileYouTube) {
noticeStyle.bottom = "4em";
noticeStyle.transform = "scale(0.8) translate(10%, 10%)";
}
return (
<NoticeComponent noticeTitle={this.state.noticeTitle}
idSuffix={this.state.idSuffix}
ref={this.noticeRef}>
{/* Text Boxes */}
{this.getMessageBoxes()}
{/* Sponsor Time List */}
<tr id={"sponsorSkipNoticeMiddleRow" + this.state.idSuffix}>
<td>
{this.getSponsorTimeMessages()}
</td>
</tr>
{/* Last Row */}
<tr id={"sponsorSkipNoticeSecondRow" + this.state.idSuffix}>
<td className="sponsorSkipNoticeRightSection"
style={{position: "relative"}}>
{/* Cancel Button */}
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
onClick={this.cancel.bind(this)}>
{chrome.i18n.getMessage("cancel")}
</button>
{/* Submit Button */}
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
onClick={this.submit.bind(this)}>
{chrome.i18n.getMessage("submit")}
</button>
</td>
</tr>
</NoticeComponent>
);
}
getSponsorTimeMessages(): JSX.Element[] | JSX.Element {
let elements: JSX.Element[] = [];
let sponsorTimes = this.props.contentContainer().sponsorTimesSubmitting;
for (let i = 0; i < sponsorTimes.length; i++) {
elements.push(
<SponsorTimeEditComponent key={i}
idSuffix={this.state.idSuffix}
index={i}
contentContainer={this.props.contentContainer}>
</SponsorTimeEditComponent>
)
}
return elements;
}
getMessageBoxes(): JSX.Element[] | JSX.Element {
let elements: JSX.Element[] = [];
for (let i = 0; i < this.state.messages.length; i++) {
elements.push(
<NoticeTextSelectionComponent idSuffix={this.state.idSuffix}
text={this.state.messages[i]}
key={i}>
</NoticeTextSelectionComponent>
)
}
return elements;
}
cancel() {
this.noticeRef.current.close();
this.contentContainer().resetSponsorSubmissionNotice();
}
submit() {
this.props.callback();
this.cancel();
}
}
export default SkipNoticeComponent;