Sort addons by Enabled (#1237)

* Add sort by enabled

* Changed "Is Enabled" to "Enabled"

* Fix locales formatting
This commit is contained in:
TheGreenPig 2022-06-27 00:29:59 +02:00 committed by GitHub
parent 2341448de2
commit 87de0a8d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -218,6 +218,7 @@
"version": "Version",
"added": "Date Added",
"modified": "Date Modified",
"isEnabled": "Enabled",
"search": "Search {{type}}",
"editAddon": "Edit",
"deleteAddon": "Delete",
@ -324,4 +325,4 @@
"enabledInfo": "This option requires a transparent theme in order to work properly. On Windows this may break your aero snapping and maximizing.\n\nIn order to take effect, Discord needs to be restarted. Do you want to restart now?",
"disabledInfo": "In order to take effect, Discord needs to be restarted. Do you want to restart now?"
}
}
}

View File

@ -96,7 +96,8 @@ export default class AddonList extends React.Component {
{label: Strings.Addons.author, value: "author"},
{label: Strings.Addons.version, value: "version"},
{label: Strings.Addons.added, value: "added"},
{label: Strings.Addons.modified, value: "modified"}
{label: Strings.Addons.modified, value: "modified"},
{label: Strings.Addons.isEnabled, value: "isEnabled"}
];
}
@ -127,9 +128,12 @@ export default class AddonList extends React.Component {
const showReloadIcon = !Settings.get("settings", "addons", "autoReload");
const button = folder ? {title: Strings.Addons.openFolder.format({type: title}), onClick: this.openFolder} : null;
let sortedAddons = addonList.sort((a, b) => {
const first = a[this.state.sort];
const second = b[this.state.sort];
if (typeof(first) == "string") return first.toLocaleLowerCase().localeCompare(second.toLocaleLowerCase());
const sortByEnabled = this.state.sort === "isEnabled";
const first = sortByEnabled ? addonState[a.id] : a[this.state.sort];
const second = sortByEnabled ? addonState[b.id] : b[this.state.sort];
const stringSort = (str1, str2) => str1.toLocaleLowerCase().localeCompare(str2.toLocaleLowerCase());
if (typeof(first) == "string") return stringSort(first, second);
if (typeof(first) == "boolean") return (first === second) ? stringSort(a.name, b.name) : first ? -1 : 1;
if (first > second) return 1;
if (second > first) return -1;
return 0;