Skip to content

Commit

Permalink
Merge pull request #210 from MeguminSama/feat/computedSettingsPositions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere authored Feb 3, 2025
2 parents c3e03f5 + 18e163b commit fe3b188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const Settings: SettingsType = {

_mutateSections: (sections) => {
for (const section of Settings.ourSections) {
// Discord's `pos` only supports numbers, so lets call the function to get the position.
if (typeof section.pos === "function") {
section.pos = section.pos(sections);
}
sections.splice(section.pos < 0 ? sections.length + section.pos : section.pos, 0, section);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/types/src/coreExtensions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export type NoticeProps = {
};

export type SettingsSection =
| { section: "DIVIDER"; pos: number }
| { section: "HEADER"; label: string; pos: number }
| { section: "DIVIDER"; pos: number | ((sections: SettingsSection[]) => number) }
| { section: "HEADER"; label: string; pos: number | ((sections: SettingsSection[]) => number) }
| {
section: string;
label: string;
color: string | null;
element: React.FunctionComponent;
pos: number;
pos: number | ((sections: SettingsSection[]) => number);
notice?: NoticeProps;
_moonlight_submenu?: () => ReactElement | ReactElement[];
};
Expand All @@ -38,7 +38,7 @@ export type Settings = {
label: string,
element: React.FunctionComponent,
color?: string | null,
pos?: number,
pos?: number | ((sections: SettingsSection[]) => number),
notice?: NoticeProps
) => void;

Expand All @@ -53,13 +53,13 @@ export type Settings = {
* Places a divider in the settings menu.
* @param pos The position in the settings menu to place the divider
*/
addDivider: (pos: number | null) => void;
addDivider: (pos: number | ((sections: SettingsSection[]) => number) | null) => void;

/**
* Places a header in the settings menu.
* @param pos The position in the settings menu to place the header
*/
addHeader: (label: string, pos: number | null) => void;
addHeader: (label: string, pos: number | ((sections: SettingsSection[]) => number) | null) => void;

/**
* @private
Expand Down

0 comments on commit fe3b188

Please sign in to comment.