Category selections now save

This commit is contained in:
Ajay Ramachandran
2020-04-02 22:13:36 -04:00
parent 6ea87d7cd0
commit 3afde08a6e
4 changed files with 74 additions and 14 deletions

View File

@@ -26,9 +26,11 @@ class CategoryChooserComponent extends React.Component<CategoryChooserProps, Cat
render() { render() {
return ( return (
<table id="categoryChooserTable" <table id="categoryChooserTable"
className="categoryChooserTable"> <tbody> className="categoryChooserTable">
<tbody>
{this.getCategorySkipOptions()} {this.getCategorySkipOptions()}
</tbody> </table> </tbody>
</table>
); );
} }
@@ -38,7 +40,8 @@ class CategoryChooserComponent extends React.Component<CategoryChooserProps, Cat
for (const category of CompileConfig.categoryList) { for (const category of CompileConfig.categoryList) {
elements.push( elements.push(
<CategorySkipOptionsComponent category={category} <CategorySkipOptionsComponent category={category}
defaultColor={"00d400"}> defaultColor={"00d400"}
key={category}>
</CategorySkipOptionsComponent> </CategorySkipOptionsComponent>
); );
} }

View File

@@ -1,4 +1,5 @@
import * as React from "react"; import * as React from "react";
import Config from "../config" import Config from "../config"
export interface CategorySkipOptionsProps { export interface CategorySkipOptionsProps {
@@ -22,6 +23,14 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
} }
render() { render() {
let defaultOption = "disable";
// Set the default opton properly
for (const categorySelection of Config.config.categorySelections) {
if (categorySelection.name === this.props.category) {
defaultOption = categorySelection.autoSkip ? "autoSkip" : "manualSkip";
}
}
return ( return (
<tr id={this.props.category + "OptionsRow"} <tr id={this.props.category + "OptionsRow"}
className="categoryTableElement"> className="categoryTableElement">
@@ -32,8 +41,10 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
<td id={this.props.category + "SkipOption"}> <td id={this.props.category + "SkipOption"}>
<select <select
className="categoryOptionsSelector"> className="categoryOptionsSelector"
{this.getOptions(["disable", "manualSkip", "autoSkip"])} defaultValue={defaultOption}
onChange={this.skipOptionSelected.bind(this)}>
{this.getCategorySkipOptions()}
</select> </select>
</td> </td>
@@ -42,15 +53,48 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
); );
} }
/** skipOptionSelected(event: React.ChangeEvent<HTMLSelectElement>): void {
* @param optionNames List of option names as codes that will be sent to i18n switch (event.target.value) {
*/ case "disable":
getOptions(optionNames: string[]): JSX.Element[] { this.removeCurrentCategorySelection();
break;
default:
this.removeCurrentCategorySelection();
Config.config.categorySelections.push({
name: this.props.category,
autoSkip: event.target.value === "autoSkip"
});
// Forces the Proxy to send this to the chrome storage API
Config.config.categorySelections = Config.config.categorySelections;
}
}
/** Removes this category from the config list of category selections */
removeCurrentCategorySelection(): void {
// Remove it if it exists
for (let i = 0; i < Config.config.categorySelections.length; i++) {
if (Config.config.categorySelections[i].name === this.props.category) {
Config.config.categorySelections.splice(i, 1);
// Forces the Proxy to send this to the chrome storage API
Config.config.categorySelections = Config.config.categorySelections;
break;
}
}
}
getCategorySkipOptions(): JSX.Element[] {
let elements: JSX.Element[] = []; let elements: JSX.Element[] = [];
let optionNames = ["disable", "manualSkip", "autoSkip"];
for (const optionName of optionNames) { for (const optionName of optionNames) {
elements.push( elements.push(
<option value={optionName}> <option key={optionName} value={optionName}>
{chrome.i18n.getMessage(optionName)} {chrome.i18n.getMessage(optionName)}
</option> </option>
); );

View File

@@ -1,4 +1,5 @@
import * as CompileConfig from "../config.json"; import * as CompileConfig from "../config.json";
import { CategorySelection } from "./types";
interface SBConfig { interface SBConfig {
userID: string, userID: string,
@@ -25,7 +26,10 @@ interface SBConfig {
serverAddress: string, serverAddress: string,
minDuration: number, minDuration: number,
checkForUnlistedVideos: boolean, checkForUnlistedVideos: boolean,
mobileUpdateShowCount: number mobileUpdateShowCount: number,
// What categories should be skipped
categorySelections: CategorySelection[]
} }
interface SBObject { interface SBObject {
@@ -120,7 +124,11 @@ var Config: SBObject = {
serverAddress: CompileConfig.serverAddress, serverAddress: CompileConfig.serverAddress,
minDuration: 0, minDuration: 0,
checkForUnlistedVideos: false, checkForUnlistedVideos: false,
mobileUpdateShowCount: 0 mobileUpdateShowCount: 0,
categorySelections: [{
name: "sponsor",
autoSkip: true
}]
}, },
localConfig: null, localConfig: null,
config: null, config: null,

View File

@@ -26,8 +26,13 @@ interface VideoDurationResponse {
duration: number; duration: number;
} }
interface CategorySelection {
name: string;
autoSkip: boolean;
}
export { export {
VideoDurationResponse, VideoDurationResponse,
ContentContainer ContentContainer,
CategorySelection
}; };