Scroll down when new segment added to notice

This commit is contained in:
Ajay
2023-11-01 16:08:52 -04:00
parent 9c2007e0cf
commit 4ffa019c68

View File

@@ -38,6 +38,8 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
guidelinesReminder: GenericNotice; guidelinesReminder: GenericNotice;
lastSegmentCount: number;
constructor(props: SubmissionNoticeProps) { constructor(props: SubmissionNoticeProps) {
super(props); super(props);
this.noticeRef = React.createRef(); this.noticeRef = React.createRef();
@@ -47,12 +49,14 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
const noticeTitle = chrome.i18n.getMessage("confirmNoticeTitle"); const noticeTitle = chrome.i18n.getMessage("confirmNoticeTitle");
this.lastSegmentCount = this.props.contentContainer().sponsorTimesSubmitting.length;
// Setup state // Setup state
this.state = { this.state = {
noticeTitle, noticeTitle,
messages: [], messages: [],
idSuffix: "SubmissionNotice" idSuffix: "SubmissionNotice"
} };
} }
componentDidMount(): void { componentDidMount(): void {
@@ -73,6 +77,18 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
} }
} }
componentDidUpdate() {
const currentSegmentCount = this.props.contentContainer().sponsorTimesSubmitting.length;
if (currentSegmentCount > this.lastSegmentCount) {
this.lastSegmentCount = currentSegmentCount;
const scrollElement = this.noticeRef.current.getElement().current.querySelector("#sponsorSkipNoticeMiddleRowSubmissionNotice");
scrollElement.scrollTo({
top: scrollElement.scrollHeight + 1000
});
}
}
render(): React.ReactElement { render(): React.ReactElement {
const sortButton = const sortButton =
<img id={"sponsorSkipSortButton" + this.state.idSuffix} <img id={"sponsorSkipSortButton" + this.state.idSuffix}