mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Added basic react submission confirmation notice
This commit is contained in:
141
src/components/SubmissionNoticeComponent.tsx
Normal file
141
src/components/SubmissionNoticeComponent.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user