Skip to content

Commit 3599512

Browse files
committed
chore: Sort command categories
1 parent b0e61d7 commit 3599512

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/globals/prototypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare global {
1515
remove(...toRemove: T[]): T[];
1616
sample(amount: number, rng?: RNGSource): T[];
1717
shuffle(rng?: RNGSource): T[];
18+
/** Default order is ascending */
1819
sortBy(getSort: ((term: T, thisArray: T[]) => unknown) | null, dir?: 'asc' | 'desc'): T[];
1920
space<S = unknown>(spacer: S): (T | S)[];
2021
sum(): T;

src/ps/commands/commands.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ export const command: PSCommand = {
3131

3232
const otherCommands: PSCommand[] = [];
3333

34-
const groupedCommands = visibleCommands.reduce<Record<string, PSCommand[]>>((grouped, command) => {
35-
if (command.categories.length > 0) {
36-
command.categories.forEach(category => (grouped[category] ??= []).push(command));
37-
} else {
38-
otherCommands.push(command);
39-
}
40-
return grouped;
41-
}, {});
34+
const groupedCommands = visibleCommands.reduce<Record<string, PSCommand[]>>(
35+
(grouped, command) => {
36+
if (command.categories.length > 0) {
37+
command.categories.forEach(category => (grouped[category] ??= []).push(command));
38+
} else {
39+
otherCommands.push(command);
40+
}
41+
return grouped;
42+
},
43+
{ utility: [], points: [], game: [], casual: [] }
44+
);
4245

4346
message.author.sendHTML(
4447
<div className="infobox">
@@ -48,16 +51,17 @@ export const command: PSCommand = {
4851
</p>
4952
<hr />
5053
{[
51-
...Object.entries(groupedCommands)
52-
.map(([key, commands]) => [titleCase(key), commands] as [string, PSCommand[]])
53-
.sortBy(([key]) => key),
54+
...Object.entries(groupedCommands).map(([key, commands]) => [titleCase(key), commands] as [string, PSCommand[]]),
5455
['Other', otherCommands] as [string, PSCommand[]],
5556
]
5657
.filter(([_key, commands]) => commands.length > 0)
5758
.map(([key, commands]) => (
5859
<details>
5960
<summary style={{ marginBottom: 4 }}>{key} Commands</summary>
60-
{commands.map(command => <b title={command.help ?? undefined}>{command.name}</b>).space(', ')}
61+
{commands
62+
.sortBy(command => command.name)
63+
.map(command => <b title={command.help ?? undefined}>{command.name}</b>)
64+
.space(', ')}
6165
</details>
6266
))
6367
.space(<hr />)}

0 commit comments

Comments
 (0)