Lock category order and show all categories

This commit is contained in:
Ajay Ramachandran
2020-12-15 16:13:56 -05:00
parent b6b109b226
commit fd9116c81c
2 changed files with 21 additions and 22 deletions

View File

@@ -581,6 +581,10 @@
"chooseACategory": { "chooseACategory": {
"message": "Choose a Category" "message": "Choose a Category"
}, },
"enableThisCategoryFirst": {
"message": "To submit segments with the category of \"{0}\", you must enable it in the options. You will be redirected to the options now.",
"description": "Used when submitting segments to only let them select a certain category if they have it enabled in the options."
},
"youMustSelectACategory": { "youMustSelectACategory": {
"message": "You must select a category for all segments you are submitting!" "message": "You must select a category for all segments you are submitting!"
}, },

View File

@@ -23,6 +23,8 @@ export interface SponsorTimeEditState {
sponsorTimeEdits: [string, string]; sponsorTimeEdits: [string, string];
} }
const DEFAULT_CATEGORY = "chooseACategory";
class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> { class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, SponsorTimeEditState> {
idSuffix: string; idSuffix: string;
@@ -217,27 +219,17 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
getCategoryOptions(): React.ReactElement[] { getCategoryOptions(): React.ReactElement[] {
const elements = [( const elements = [(
<option value={"chooseACategory"} <option value={DEFAULT_CATEGORY}
key={"chooseACategory"}> key={DEFAULT_CATEGORY}>
{chrome.i18n.getMessage("chooseACategory")} {chrome.i18n.getMessage(DEFAULT_CATEGORY)}
</option> </option>
)]; )];
for (const category of Config.config.categorySelections) { for (const category of CompileConfig.categoryList) {
elements.push( elements.push(
<option value={category.name} <option value={category}
key={category.name}> key={category}>
{chrome.i18n.getMessage("category_" + category.name)} {chrome.i18n.getMessage("category_" + category)}
</option>
);
}
if (elements.length < CompileConfig.categoryList.length) {
// Add show more button
elements.push(
<option value={"moreCategories"}
key={"moreCategories"}>
{chrome.i18n.getMessage("moreCategories")}
</option> </option>
); );
} }
@@ -247,12 +239,15 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
categorySelectionChange(event: React.ChangeEvent<HTMLSelectElement>): void { categorySelectionChange(event: React.ChangeEvent<HTMLSelectElement>): void {
// See if show more categories was pressed // See if show more categories was pressed
if (event.target.value === "moreCategories") { if (!Config.config.categorySelections.some((category) => category.name === event.target.value)) {
const chosenCategory = event.target.value;
event.target.value = DEFAULT_CATEGORY;
// Alert that they have to enable this category first
alert(chrome.i18n.getMessage("enableThisCategoryFirst").replace("{0}", chosenCategory));
// Open options page // Open options page
chrome.runtime.sendMessage({"message": "openConfig"}); chrome.runtime.sendMessage({"message": "openConfig"});
// Reset option to previous
event.target.value = this.props.contentContainer().sponsorTimesSubmitting[this.props.index].category;
return; return;
} }