[main] Whatever this does

This commit is contained in:
amsyarasyiq 2024-04-01 17:36:16 +08:00
parent 08c6b5ee15
commit 9bc89d4553
5 changed files with 102 additions and 65 deletions

View file

@ -1,4 +1,5 @@
import { getAssetIDByName } from "@lib/api/assets";
import { settings } from "@lib/settings";
import { FormRow } from "@lib/ui/components/discord/Forms";
import { FormCheckbox, FormSwitch, IconButton } from "@lib/ui/components/discord/Redesign";
import { createStyles, TextStyleSheet } from "@lib/ui/styles";
@ -11,7 +12,7 @@ const { hideActionSheet } = findByProps("openLazy", "hideActionSheet");
const { showSimpleActionSheet } = findByProps("showSimpleActionSheet");
// TODO: These styles work weirdly. iOS has cramped text, Android with low DPI probably does too. Fix?
const useStyles = createStyles({
const useStyles = createStyles(() => ({
card: {
backgroundColor: semanticColors?.CARD_SECONDARY_BG,
borderRadius: 12,
@ -57,7 +58,7 @@ const useStyles = createStyles({
right: "30%",
top: "-10%"
}
});
}));
interface Action {
icon: string;
@ -89,6 +90,8 @@ interface CardProps {
overflowActions?: OverflowAction[];
}
const reverseIfNeeded = (arr: any[]) => settings.__unfunnyJoke24 !== false ? arr.reverse() : arr;
export default function Card(props: CardProps) {
const styles = useStyles();
@ -99,66 +102,70 @@ export default function Card(props: CardProps) {
resizeMode="cover"
imageStyle={styles.iconStyle}
>
<FormRow
style={styles.header}
label={
<View style={styles.headerLeading}>
<RN.Text style={styles.headerLabel}>{props.headerLabel}</RN.Text>
{props.headerSublabel && (
<RN.Text style={styles.headerSubtitle}>{props.headerSublabel}</RN.Text>
)}
</View>
}
trailing={
<View style={styles.headerTrailing}>
<View style={styles.actions}>
{props.overflowActions &&
<IconButton
onPress={() => showSimpleActionSheet({
key: "CardOverflow",
header: {
title: props.overflowTitle,
icon: props.headerIcon && <FormRow.Icon style={{ marginRight: 8 }} source={getAssetIDByName(props.headerIcon)} />,
onClose: () => hideActionSheet(),
},
options: props.overflowActions?.map(i => ({ ...i, icon: getAssetIDByName(i.icon) })),
})}
size="sm"
variant="secondary"
icon={getAssetIDByName("CircleInformationIcon")}
/>}
{props.actions?.map(({ icon, onPress, disabled }) => (
<IconButton
onPress={onPress}
disabled={disabled}
size="sm"
variant="secondary"
icon={getAssetIDByName(icon)}
/>
))}
</View>
{props.toggleType && (props.toggleType === "switch" ?
<FormSwitch
value={props.toggleValue}
onValueChange={props.onToggleChange}
/>
:
<RN.Pressable onPress={() => {
props.onToggleChange?.(!props.toggleValue);
}}>
<FormCheckbox checked={props.toggleValue} />
</RN.Pressable>
)}
</View>
}
/>
<FormRow
label={
<RN.View>
<RN.Text style={styles.descriptionLabel}>{props.descriptionLabel}</RN.Text>
</RN.View>
}
/>
{
reverseIfNeeded([
<FormRow
style={styles.header}
label={
<View style={styles.headerLeading}>
<RN.Text style={styles.headerLabel}>{props.headerLabel}</RN.Text>
{props.headerSublabel && (
<RN.Text style={styles.headerSubtitle}>{props.headerSublabel}</RN.Text>
)}
</View>
}
trailing={
<View style={styles.headerTrailing}>
<View style={styles.actions}>
{props.overflowActions &&
<IconButton
onPress={() => showSimpleActionSheet({
key: "CardOverflow",
header: {
title: props.overflowTitle,
icon: props.headerIcon && <FormRow.Icon style={{ marginRight: 8 }} source={getAssetIDByName(props.headerIcon)} />,
onClose: () => hideActionSheet(),
},
options: props.overflowActions?.map(i => ({ ...i, icon: getAssetIDByName(i.icon) })),
})}
size="sm"
variant="secondary"
icon={getAssetIDByName("CircleInformationIcon")}
/>}
{props.actions?.map(({ icon, onPress, disabled }) => (
<IconButton
onPress={onPress}
disabled={disabled}
size="sm"
variant="secondary"
icon={getAssetIDByName(icon)}
/>
))}
</View>
{props.toggleType && (props.toggleType === "switch" ?
<FormSwitch
value={props.toggleValue}
onValueChange={props.onToggleChange}
/>
:
<RN.Pressable onPress={() => {
props.onToggleChange?.(!props.toggleValue);
}}>
<FormCheckbox checked={props.toggleValue} />
</RN.Pressable>
)}
</View>
}
/>,
<FormRow
label={
<RN.View>
<RN.Text style={styles.descriptionLabel}>{props.descriptionLabel}</RN.Text>
</RN.View>
}
/>,
])
}
</ImageBackground>
</RN.View>
);

View file

@ -63,6 +63,17 @@ export default function General() {
onPress={() => url.openURL(GITHUB)}
/>
</TableRowGroup>
<TableRowGroup title={"???"}>
<TableSwitchRow
label={"Whatever this does"}
subLabel={"A mystery toggle with a calendar icon, hmm..."}
icon={<TableRow.Icon source={getAssetIDByName("CalendarIcon")} />}
value={settings.__unfunnyJoke24 !== false}
onValueChange={(v: boolean) => {
settings.__unfunnyJoke24 = v;
}}
/>
</TableRowGroup>
<TableRowGroup title={Strings.ACTIONS}>
<TableRow
label={Strings.RELOAD_DISCORD}

View file

@ -5,6 +5,7 @@ export interface Settings {
debuggerUrl: string;
developerSettings: boolean;
enableDiscordDeveloperSettings: boolean;
__unfunnyJoke24?: boolean;
safeMode?: {
enabled: boolean;
currentThemeId?: string;

View file

@ -1,4 +1,5 @@
import { find, findByProps } from "@lib/metro";
import { settings } from "@lib/settings";
import { RedesignModuleKeys } from "@lib/ui/types";
const findSingular = (prop: string) => find(m => m[prop] && Object.keys(m).length === 1)?.[prop];
@ -14,6 +15,20 @@ export const FormSwitch = findSingular("FormSwitch");
export const FormRadio = findSingular("FormRadio");
export const FormCheckbox = findSingular("FormCheckbox");
export function TableRowGroup(...args: any[]) {
if (settings.__unfunnyJoke24 !== false && Array.isArray(args[0]?.children)) {
args[0].children = args[0].children.reverse();
}
return Redesign.TableRowGroup(...args);
}
export function Stack(...args: any[]) {
if (settings.__unfunnyJoke24 !== false && Array.isArray(args[0]?.children)) {
args[0].children = args[0].children.reverse();
}
return Redesign.Stack(...args);
}
export const {
AlertActionButton,
AlertModal,
@ -60,7 +75,7 @@ export const {
SegmentedControl,
SegmentedControlPages,
Slider,
Stack,
// Stack,
StepModal,
StickyContext,
StickyHeader,
@ -69,7 +84,7 @@ export const {
TableRadioGroup,
TableRadioRow,
TableRow,
TableRowGroup,
// TableRowGroup,
TableRowGroupTitle,
TableRowIcon,
TableSwitchRow,

View file

@ -1,5 +1,6 @@
import { findByName, findByProps } from "@lib/metro";
import { i18n } from "@lib/metro/common";
import { settings } from "@lib/settings";
import { registeredSections } from "@lib/ui/settings";
import { findInReactTree } from "@lib/utils";
import { after } from "spitroast";
@ -57,10 +58,12 @@ export function patchTabsUI(unpatches: (() => void | boolean)[]) {
const { sections } = findInReactTree(ret, i => i.props?.sections).props;
let index = -~sections.findIndex((i: any) => i.label === i18n.Messages.ACCOUNT_SETTINGS) || 1;
const reverseIfNeeded = (arr: any[]) => settings.__unfunnyJoke24 !== false ? arr.reverse() : arr;
Object.keys(registeredSections).forEach(sect => {
sections.splice(index++, 0, {
label: sect,
settings: registeredSections[sect].map(a => a.key)
settings: reverseIfNeeded(registeredSections[sect].map(a => a.key))
});
});
}));