Auto update hidden categories when redeemed

This commit is contained in:
Ajay
2022-09-02 14:38:49 -04:00
parent 39ed7ea83c
commit c8e2bb0c13
4 changed files with 49 additions and 12 deletions

View File

@@ -38,10 +38,21 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
this.setState({ this.setState({
hideChapter: !allowed hideChapter: !allowed
}); });
}) });
} }
render(): React.ReactElement { render(): React.ReactElement {
if (this.state.hideChapter) {
// Ensure force update refreshes this
fetchingChaptersAllowed().then((allowed) => {
if (allowed) {
this.setState({
hideChapter: !allowed
});
}
});
}
let defaultOption = "disable"; let defaultOption = "disable";
// Set the default opton properly // Set the default opton properly
for (const categorySelection of Config.config.categorySelections) { for (const categorySelection of Config.config.categorySelections) {

View File

@@ -14,9 +14,13 @@ import UnsubmittedVideos from "./render/UnsubmittedVideos";
import KeybindComponent from "./components/options/KeybindComponent"; import KeybindComponent from "./components/options/KeybindComponent";
import { showDonationLink } from "./utils/configUtils"; import { showDonationLink } from "./utils/configUtils";
import { localizeHtmlPage } from "./utils/pageUtils"; import { localizeHtmlPage } from "./utils/pageUtils";
import { StorageChangesObject } from "./types";
const utils = new Utils(); const utils = new Utils();
let embed = false; let embed = false;
const categoryChoosers: CategoryChooser[] = [];
const unsubmittedVideos: UnsubmittedVideos[] = [];
window.addEventListener('DOMContentLoaded', init); window.addEventListener('DOMContentLoaded', init);
async function init() { async function init() {
@@ -291,10 +295,10 @@ async function init() {
break; break;
} }
case "react-CategoryChooserComponent": case "react-CategoryChooserComponent":
new CategoryChooser(optionsElements[i]); categoryChoosers.push(new CategoryChooser(optionsElements[i]));
break; break;
case "react-UnsubmittedVideosComponent": case "react-UnsubmittedVideosComponent":
new UnsubmittedVideos(optionsElements[i]) unsubmittedVideos.push(new UnsubmittedVideos(optionsElements[i]));
break; break;
} }
} }
@@ -352,10 +356,8 @@ async function shouldHideOption(element: Element): Promise<boolean> {
/** /**
* Called when the config is updated * Called when the config is updated
*
* @param {String} element
*/ */
function optionsConfigUpdateListener() { function optionsConfigUpdateListener(changes: StorageChangesObject) {
const optionsContainer = document.getElementById("options"); const optionsContainer = document.getElementById("options");
const optionsElements = optionsContainer.querySelectorAll("*"); const optionsElements = optionsContainer.querySelectorAll("*");
@@ -364,9 +366,16 @@ function optionsConfigUpdateListener() {
case "display": case "display":
updateDisplayElement(<HTMLElement> optionsElements[i]) updateDisplayElement(<HTMLElement> optionsElements[i])
break; break;
case "react-UnsubmittedVideosComponent": }
new UnsubmittedVideos(optionsElements[i]) }
break;
if (changes.categorySelections || changes.payments) {
for (const chooser of categoryChoosers) {
chooser.update();
}
} else if (changes.unsubmittedSegments) {
for (const chooser of unsubmittedVideos) {
chooser.update();
} }
} }
} }
@@ -662,4 +671,4 @@ function copyDebugOutputToClipboard() {
function isIncognitoAllowed(): Promise<boolean> { function isIncognitoAllowed(): Promise<boolean> {
return new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve)); return new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve));
} }

View File

@@ -4,12 +4,20 @@ import CategoryChooserComponent from "../components/options/CategoryChooserCompo
class CategoryChooser { class CategoryChooser {
ref: React.RefObject<CategoryChooserComponent>;
constructor(element: Element) { constructor(element: Element) {
this.ref = React.createRef();
ReactDOM.render( ReactDOM.render(
<CategoryChooserComponent/>, <CategoryChooserComponent ref={this.ref} />,
element element
); );
} }
update(): void {
this.ref.current?.forceUpdate();
}
} }
export default CategoryChooser; export default CategoryChooser;

View File

@@ -4,12 +4,21 @@ import UnsubmittedVideosComponent from "../components/options/UnsubmittedVideosC
class UnsubmittedVideos { class UnsubmittedVideos {
ref: React.RefObject<UnsubmittedVideosComponent>;
constructor(element: Element) { constructor(element: Element) {
this.ref = React.createRef();
ReactDOM.render( ReactDOM.render(
<UnsubmittedVideosComponent/>, <UnsubmittedVideosComponent ref={this.ref} />,
element element
); );
} }
update(): void {
this.ref.current?.forceUpdate();
}
} }
export default UnsubmittedVideos; export default UnsubmittedVideos;