Skip to content

Commit

Permalink
fix: Fix old settings menu and make some improvements to it (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
notmarek authored Sep 22, 2024
1 parent 32afc78 commit e240509
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib/ui/settings/patches/panel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { after } from "@lib/api/patcher";
import { findInReactTree } from "@lib/utils";
import { i18n, NavigationNative } from "@metro/common";
import { LegacyFormIcon, LegacyFormRow, LegacyFormSection } from "@metro/common/components";
import { LegacyFormIcon, LegacyFormRow, LegacyFormSection, LegacyFormDivider } from "@metro/common/components";
import { findByNameLazy } from "@metro/wrappers";
import { registeredSections } from "@ui/settings";

Expand All @@ -11,17 +11,20 @@ function SettingsSection() {
const navigation = NavigationNative.useNavigation();

return <>
{Object.keys(registeredSections).map(sect => (
{Object.keys(registeredSections).map(sect => registeredSections[sect].length > 0 && (
<LegacyFormSection key={sect} title={sect}>
{ /** Is usePredicate here safe? */}
{registeredSections[sect].filter(r => r.usePredicate?.() ?? true).map(row => (
{ /** Is usePredicate here safe? */}
{registeredSections[sect].filter(r => r.usePredicate?.() ?? true).map((row, i, arr) => (
<>
<LegacyFormRow
label={row.title()}
leading={<LegacyFormIcon source={row.icon} />}
trailing={LegacyFormRow.Arrow}
trailing={<LegacyFormRow.Arrow label={row.rawTabsConfig?.useTrailing?.() || undefined} />}
onPress={wrapOnPress(row.onPress, navigation, row.render, row.title())}
/>
))}
{i !== arr.length - 1 && <LegacyFormDivider />}
</>
))}
</LegacyFormSection>
))}
</>;
Expand Down Expand Up @@ -54,7 +57,7 @@ export function patchPanelUI(unpatches: (() => void | boolean)[]) {
const sections = findInReactTree(
res.props.children,
n => n?.children?.[1]?.type === LegacyFormSection
)?.children;
)?.children || res.props.children;

if (sections) {
const index = sections.findIndex((c: any) => titles.includes(c?.props.label));
Expand Down

0 comments on commit e240509

Please sign in to comment.