From 52ed4f73f4e252ea517ca4f1a8e0b0ff41c855f3 Mon Sep 17 00:00:00 2001 From: FlorianZahn Date: Sat, 9 Oct 2021 08:08:46 +0200 Subject: [PATCH] SkipNotice now remembers what has already been voted. Also nicer highlighting of current selection. --- src/components/SkipNoticeComponent.tsx | 142 +++++++++++++++++-------- src/utils.ts | 6 +- 2 files changed, 102 insertions(+), 46 deletions(-) diff --git a/src/components/SkipNoticeComponent.tsx b/src/components/SkipNoticeComponent.tsx index db0aca15..4fadcfb7 100644 --- a/src/components/SkipNoticeComponent.tsx +++ b/src/components/SkipNoticeComponent.tsx @@ -5,6 +5,8 @@ import { Category, ContentContainer, CategoryActionType, SponsorHideType, Sponso import NoticeComponent from "./NoticeComponent"; import NoticeTextSelectionComponent from "./NoticeTextSectionComponent"; import SubmissionNotice from "../render/SubmissionNotice"; +import Utils from "../utils"; +const utils = new Utils(); import { getCategoryActionType, getSkippingText } from "../utils/categoryUtils"; @@ -58,6 +60,10 @@ export interface SkipNoticeState { showKeybindHint?: boolean; smaller?: boolean; + + voted?: SkipNoticeAction[]; + copied?: SkipNoticeAction[]; + } class SkipNoticeComponent extends React.Component { @@ -75,6 +81,9 @@ class SkipNoticeComponent extends React.Component; categoryOptionRef: React.RefObject; + selectedColor: string; + unselectedColor: string; + // Used to update on config change configListener: () => void; @@ -106,6 +115,9 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.Upvote)}> - + {/* Report Button */} @@ -211,17 +227,18 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.Downvote)}> - + {/* Copy and Downvote Button */}
this.adjustEditingState(true)}> + onClick={() => this.openEditingOptions()}> + this.state.actionState === SkipNoticeAction.CopyDownvote || + this.state.choosingCategory === true) + ? this.selectedColor : this.unselectedColor} />
@@ -240,7 +257,7 @@ class SkipNoticeComponent extends React.Component this.continueVoting()}> + onClick={() => this.resetStateToStart()}> {chrome.i18n.getMessage("ContinueVoting")} @@ -270,6 +287,7 @@ class SkipNoticeComponent extends React.Component this.prepAction(SkipNoticeAction.CopyDownvote)}> {chrome.i18n.getMessage("CopyAndDownvote")} @@ -277,6 +295,7 @@ class SkipNoticeComponent extends React.Component this.openCategoryChooser()}> {chrome.i18n.getMessage("incorrectCategory")} @@ -285,8 +304,6 @@ class SkipNoticeComponent extends React.Component ), - - /* Category Chooser Row */ (this.state.choosingCategory && @@ -348,8 +366,13 @@ class SkipNoticeComponent extends React.Component this.performAction(i)} key={"submission" + i + this.segments[i].category + this.idSuffix}> {(i + 1) + ". " + chrome.i18n.getMessage("category_" + this.segments[i].category)} @@ -399,15 +422,29 @@ class SkipNoticeComponent extends React.Component { if (this.segments.length > 1) { // Use the action selectors as a submit button @@ -538,15 +578,6 @@ class SkipNoticeComponent extends React.Component window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); - this.setState({ - editing: false, - choosingCategory: false, - actionState: SkipNoticeAction.None - }); + const index = this.segments.findIndex(x => x.UUID === segment.UUID); + switch (type) { + case 0: + const wikiLinkText = Config.config.wikiPages.get(segment.category); + this.setNoticeInfoMessageWithOnClick(() => window.open(wikiLinkText), chrome.i18n.getMessage("OpenCategoryWikiPage")); + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Downvote, index) + }); + break; + case 1: + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.Upvote, index) + }); + break; + case 20: + this.setState({ + voted: utils.replaceArrayElement(this.state.voted, SkipNoticeAction.CopyDownvote, index) + }); + break; } + this.addVoteButtonInfo(chrome.i18n.getMessage("voted")); // Change the sponsor locally if (segment) { @@ -639,7 +679,6 @@ class SkipNoticeComponent extends React.Component(array: Type[], value: Type, index: number): Type[] { + array[index] = value; + return array; + } }