[Settings] Fix navigation being invalidated

This commit is contained in:
Beef 2023-01-07 17:07:45 +00:00
parent 70a60a5b33
commit f02b1d842e

View file

@ -9,11 +9,12 @@ import AssetBrowser from "@ui/settings/pages/AssetBrowser";
const screensModule = findByDisplayName("getScreens", false);
const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false);
let settingsInjected = false;
export default function initSettings() {
after("default", screensModule, (args, ret) => {
after("default", screensModule, (args, existingScreens) => {
return {
...ret,
...existingScreens,
VendettaSettings: {
title: "Vendetta",
render: General,
@ -29,19 +30,20 @@ export default function initSettings() {
}
});
after("default", settingsModule, (args, _ret) => {
const toPatch = findInReactTree(_ret.props.children, i => i.type && i.type.name === "UserSettingsOverview");
after("default", settingsModule, (args, ret) => {
const Overview = findInReactTree(ret.props.children, i => i.type && i.type.name === "UserSettingsOverview");
// Upload logs button gone
after("renderSupportAndAcknowledgements", toPatch.type.prototype, (args, { props: { children } }) => {
after("renderSupportAndAcknowledgements", Overview.type.prototype, (args, { props: { children } }) => {
const index = children.findIndex((c: any) => c?.type?.name === "UploadLogsButton");
if (index !== -1) children.splice(index, 1);
});
after("render", toPatch.type.prototype, (args, { props: { children } }) => {
after("render", Overview.type.prototype, (args, { props: { children } }) => {
const titles = [i18n.Messages["BILLING_SETTINGS"], i18n.Messages["PREMIUM_SETTINGS"]];
const index = children.findIndex((c: any) => titles.includes(c.props.title));
children.splice(index === -1 ? 4 : index, 0, <SettingsSection navigation={toPatch.props.navigation} />);
children.splice(index === -1 ? 4 : index, settingsInjected ? 1 : 0, <SettingsSection navigation={Overview.props.navigation} />);
if (!settingsInjected) settingsInjected = true;
});
});
}, true);
}