Fix segments disapearing when changing skip options

This commit is contained in:
Ajay
2022-07-03 22:44:32 -04:00
parent efec6a113f
commit e48d956577

View File

@@ -111,8 +111,6 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
skipOptionSelected(event: React.ChangeEvent<HTMLSelectElement>): void { skipOptionSelected(event: React.ChangeEvent<HTMLSelectElement>): void {
let option: CategorySkipOption; let option: CategorySkipOption;
this.removeCurrentCategorySelection();
switch (event.target.value) { switch (event.target.value) {
case "disable": case "disable":
return; return;
@@ -130,28 +128,17 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
break; break;
} }
Config.config.categorySelections.push({ const existingSelection = Config.config.categorySelections.find(selection => selection.name === this.props.category);
name: this.props.category, if (existingSelection) {
option: option existingSelection.option = option;
}); } else {
Config.config.categorySelections.push({
// Forces the Proxy to send this to the chrome storage API name: this.props.category,
Config.config.categorySelections = Config.config.categorySelections; option: option
} });
/** 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;
}
} }
Config.forceSyncUpdate("categorySelections");
} }
getCategorySkipOptions(): JSX.Element[] { getCategorySkipOptions(): JSX.Element[] {