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({
hideChapter: !allowed
});
})
});
}
render(): React.ReactElement {
if (this.state.hideChapter) {
// Ensure force update refreshes this
fetchingChaptersAllowed().then((allowed) => {
if (allowed) {
this.setState({
hideChapter: !allowed
});
}
});
}
let defaultOption = "disable";
// Set the default opton properly
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 { showDonationLink } from "./utils/configUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { StorageChangesObject } from "./types";
const utils = new Utils();
let embed = false;
const categoryChoosers: CategoryChooser[] = [];
const unsubmittedVideos: UnsubmittedVideos[] = [];
window.addEventListener('DOMContentLoaded', init);
async function init() {
@ -291,10 +295,10 @@ async function init() {
break;
}
case "react-CategoryChooserComponent":
new CategoryChooser(optionsElements[i]);
categoryChoosers.push(new CategoryChooser(optionsElements[i]));
break;
case "react-UnsubmittedVideosComponent":
new UnsubmittedVideos(optionsElements[i])
unsubmittedVideos.push(new UnsubmittedVideos(optionsElements[i]));
break;
}
}
@ -352,10 +356,8 @@ async function shouldHideOption(element: Element): Promise<boolean> {
/**
* Called when the config is updated
*
* @param {String} element
*/
function optionsConfigUpdateListener() {
function optionsConfigUpdateListener(changes: StorageChangesObject) {
const optionsContainer = document.getElementById("options");
const optionsElements = optionsContainer.querySelectorAll("*");
@ -364,9 +366,16 @@ function optionsConfigUpdateListener() {
case "display":
updateDisplayElement(<HTMLElement> optionsElements[i])
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> {
return new Promise((resolve) => chrome.extension.isAllowedIncognitoAccess(resolve));
}
}

View file

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

View file

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