Only show selected categories when submitting and added a "show more categories" button

This commit is contained in:
Ajay Ramachandran
2020-04-13 12:43:12 -04:00
parent 2f78f31874
commit 0223aa8307
2 changed files with 32 additions and 7 deletions

View File

@@ -528,5 +528,8 @@
}, },
"bracketNow": { "bracketNow": {
"message": "(Now)" "message": "(Now)"
},
"moreCategories": {
"message": "More Categories"
} }
} }

View File

@@ -154,7 +154,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
className="sponsorTimeCategories" className="sponsorTimeCategories"
defaultValue={sponsorTime.category} defaultValue={sponsorTime.category}
ref={this.categoryOptionRef} ref={this.categoryOptionRef}
onChange={this.saveEditTimes.bind(this)}> onChange={this.categorySelectionChange.bind(this)}>
{this.getCategoryOptions()} {this.getCategoryOptions()}
</select> </select>
@@ -190,13 +190,21 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
getCategoryOptions() { getCategoryOptions() {
let elements = []; let elements = [];
//TODO: Remove this when testing server is not needed for (const category of Config.config.categorySelections) {
let categoryList = Config.config.testingServer ? CompileConfig.categoryList : ["sponsor"];
for (const category of categoryList) {
elements.push( elements.push(
<option value={category} <option value={category.name}
key={category}> key={category.name}>
{chrome.i18n.getMessage("category_" + category)} {chrome.i18n.getMessage("category_" + category.name)}
</option>
);
}
if (elements.length < CompileConfig.categoryList.length) {
// Add show more button
elements.push(
<option value={"moreCategories"}
key={"moreCategories"}>
{chrome.i18n.getMessage("moreCategories")}
</option> </option>
); );
} }
@@ -204,6 +212,20 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
return elements; return elements;
} }
categorySelectionChange(event: React.ChangeEvent<HTMLSelectElement>) {
// See if show more categories was pressed
if (event.target.value === "moreCategories") {
// Open options page
chrome.runtime.sendMessage({"message": "openConfig"});
// Reset option to previous
event.target.value = this.props.contentContainer().sponsorTimesSubmitting[this.props.index].category;
return;
}
this.saveEditTimes();
}
setTimeToNow(index: number) { setTimeToNow(index: number) {
let sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index]; let sponsorTime = this.props.contentContainer().sponsorTimesSubmitting[this.props.index];