diff options
author | Ajay Ramachandran <[email protected]> | 2020-03-11 17:50:50 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-03-11 17:50:50 -0400 |
commit | a18235425499d1ecb508652957b73056a1fe080a (patch) | |
tree | bf57fd87540777b5fea52b8e74a095fb798878b0 /src/components/SubmissionNoticeComponent.tsx | |
parent | a02aef591e8b9b890d7af5f6c259a65569d5e694 (diff) | |
download | SponsorBlock-a18235425499d1ecb508652957b73056a1fe080a.tar.gz SponsorBlock-a18235425499d1ecb508652957b73056a1fe080a.zip |
Added basic react submission confirmation notice
Diffstat (limited to 'src/components/SubmissionNoticeComponent.tsx')
-rw-r--r-- | src/components/SubmissionNoticeComponent.tsx | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/src/components/SubmissionNoticeComponent.tsx b/src/components/SubmissionNoticeComponent.tsx new file mode 100644 index 00000000..69c57c0f --- /dev/null +++ b/src/components/SubmissionNoticeComponent.tsx @@ -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;
\ No newline at end of file |