aboutsummaryrefslogtreecommitdiff
path: root/src/components/PluginSettings
diff options
context:
space:
mode:
authorVen <vendicated@riseup.net>2022-11-01 01:49:41 +0100
committerGitHub <noreply@github.com>2022-11-01 01:49:41 +0100
commit04d6f341ee3122e36044739d533a69e4312dd116 (patch)
tree971e61d6ee490ec02a682b7d6fa68bb08cffe68a /src/components/PluginSettings
parent0c25278c5923ff7fdc22730557da00601b8cf1d3 (diff)
downloadVencord-04d6f341ee3122e36044739d533a69e4312dd116.tar.gz
Vencord-04d6f341ee3122e36044739d533a69e4312dd116.tar.bz2
Vencord-04d6f341ee3122e36044739d533a69e4312dd116.zip
PatchHelper, a tool to help you write patches (#182)
Diffstat (limited to 'src/components/PluginSettings')
-rw-r--r--src/components/PluginSettings/PluginModal.tsx68
-rw-r--r--src/components/PluginSettings/components/SettingTextComponent.tsx2
-rw-r--r--src/components/PluginSettings/index.tsx7
3 files changed, 34 insertions, 43 deletions
diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx
index 4c14d61..9e13f63 100644
--- a/src/components/PluginSettings/PluginModal.tsx
+++ b/src/components/PluginSettings/PluginModal.tsx
@@ -29,12 +29,13 @@ import { Button, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUti
import ErrorBoundary from "../ErrorBoundary";
import { Flex } from "../Flex";
import {
+ ISettingElementProps,
SettingBooleanComponent,
SettingCustomComponent,
- SettingInputComponent,
SettingNumericComponent,
SettingSelectComponent,
- SettingSliderComponent
+ SettingSliderComponent,
+ SettingTextComponent
} from "./components";
const UserSummaryItem = lazyWebpack(filters.byCode("defaultRenderUser", "showDefaultAvatarsForNullUsers"));
@@ -60,6 +61,16 @@ function makeDummyUser(user: { name: string, id: BigInt; }) {
return newUser;
}
+const Components: Record<OptionType, React.ComponentType<ISettingElementProps<any>>> = {
+ [OptionType.STRING]: SettingTextComponent,
+ [OptionType.NUMBER]: SettingNumericComponent,
+ [OptionType.BIGINT]: SettingNumericComponent,
+ [OptionType.BOOLEAN]: SettingBooleanComponent,
+ [OptionType.SELECT]: SettingSelectComponent,
+ [OptionType.SLIDER]: SettingSliderComponent,
+ [OptionType.COMPONENT]: SettingCustomComponent
+};
+
export default function PluginModal({ plugin, onRestartNeeded, onClose, transitionState }: PluginModalProps) {
const [authors, setAuthors] = React.useState<Partial<User>[]>([]);
@@ -75,8 +86,10 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti
React.useEffect(() => {
(async () => {
for (const user of plugin.authors.slice(0, 6)) {
- const author = user.id ? await UserUtils.fetchUser(`${user.id}`).catch(() => null) : makeDummyUser(user);
- setAuthors(a => [...a, author || makeDummyUser(user)]);
+ const author = user.id
+ ? await UserUtils.fetchUser(`${user.id}`).catch(() => makeDummyUser(user))
+ : makeDummyUser(user);
+ setAuthors(a => [...a, author]);
}
})();
}, []);
@@ -111,9 +124,8 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti
return <Forms.FormText>There are no settings for this plugin.</Forms.FormText>;
}
- const options: JSX.Element[] = [];
- for (const [key, setting] of Object.entries(plugin.options)) {
- function onChange(newValue) {
+ const options = Object.entries(plugin.options).map(([key, setting]) => {
+ function onChange(newValue: any) {
setTempSettings(s => ({ ...s, [key]: newValue }));
}
@@ -121,35 +133,19 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti
setErrors(e => ({ ...e, [key]: hasError }));
}
- const props = { onChange, pluginSettings, id: key, onError };
- switch (setting.type) {
- case OptionType.SELECT: {
- options.push(<SettingSelectComponent key={key} option={setting} {...props} />);
- break;
- }
- case OptionType.STRING: {
- options.push(<SettingInputComponent key={key} option={setting} {...props} />);
- break;
- }
- case OptionType.NUMBER:
- case OptionType.BIGINT: {
- options.push(<SettingNumericComponent key={key} option={setting} {...props} />);
- break;
- }
- case OptionType.BOOLEAN: {
- options.push(<SettingBooleanComponent key={key} option={setting} {...props} />);
- break;
- }
- case OptionType.SLIDER: {
- options.push(<SettingSliderComponent key={key} option={setting} {...props} />);
- break;
- }
- case OptionType.COMPONENT: {
- options.push(<SettingCustomComponent key={key} option={setting} {...props} />);
- break;
- }
- }
- }
+ const Component = Components[setting.type];
+ return (
+ <Component
+ id={key}
+ key={key}
+ option={setting}
+ onChange={onChange}
+ onError={onError}
+ pluginSettings={pluginSettings}
+ />
+ );
+ });
+
return <Flex flexDirection="column" style={{ gap: 12 }}>{options}</Flex>;
}
diff --git a/src/components/PluginSettings/components/SettingTextComponent.tsx b/src/components/PluginSettings/components/SettingTextComponent.tsx
index 216a2a1..f76bd58 100644
--- a/src/components/PluginSettings/components/SettingTextComponent.tsx
+++ b/src/components/PluginSettings/components/SettingTextComponent.tsx
@@ -20,7 +20,7 @@ import { PluginOptionString } from "../../../utils/types";
import { Forms, React, TextInput } from "../../../webpack/common";
import { ISettingElementProps } from ".";
-export function SettingInputComponent({ option, pluginSettings, id, onChange, onError }: ISettingElementProps<PluginOptionString>) {
+export function SettingTextComponent({ option, pluginSettings, id, onChange, onError }: ISettingElementProps<PluginOptionString>) {
const [state, setState] = React.useState(pluginSettings[id] ?? option.default ?? null);
const [error, setError] = React.useState<string | null>(null);
diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx
index 9ab1396..a5116c4 100644
--- a/src/components/PluginSettings/index.tsx
+++ b/src/components/PluginSettings/index.tsx
@@ -220,11 +220,6 @@ export default ErrorBoundary.wrap(function Settings() {
return o;
}, []);
- function hasDependents(plugin: Plugin) {
- const enabledDependants = depMap[plugin.name]?.filter(d => settings.plugins[d].enabled);
- return !!enabledDependants?.length;
- }
-
const sortedPlugins = React.useMemo(() => Object.values(Plugins)
.sort((a, b) => a.name.localeCompare(b.name)), []);
@@ -264,7 +259,7 @@ export default ErrorBoundary.wrap(function Settings() {
{ label: "Show Enabled", value: "enabled" },
{ label: "Show Disabled", value: "disabled" }
]}
- serialize={v => String(v)}
+ serialize={String}
select={onStatusChange}
isSelected={v => v === searchValue.status}
closeOnSelect={true}