this repo has no description

Merge pull request #210 from MeguminSama/feat/computedSettingsPositions

Changed files
+10 -6
packages
core-extensions
src
settings
webpackModules
types
src
coreExtensions
+4
packages/core-extensions/src/settings/webpackModules/settings.ts
···
_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);
}
+6 -6
packages/types/src/coreExtensions/settings.ts
···
};
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[];
};
···
label: string,
element: React.FunctionComponent,
color?: string | null,
-
pos?: number,
+
pos?: number | ((sections: SettingsSection[]) => number),
notice?: NoticeProps
) => void;
···
* 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