From a67db11dc2554c9360d1ef8e97b4b558b71045af Mon Sep 17 00:00:00 2001 From: A user Date: Tue, 13 Dec 2022 20:44:57 -0300 Subject: Improve Settings UI & View Raw Modal (#332) very cool --- src/components/PluginSettings/PluginModal.tsx | 69 ++++++++++++++------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'src/components') diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index 7cff58f..4656850 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -21,7 +21,7 @@ import { useSettings } from "@api/settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { LazyComponent } from "@utils/misc"; -import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; +import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; import { proxyLazy } from "@utils/proxyLazy"; import { OptionType, Plugin } from "@utils/types"; import { findByCode, findByPropsLazy } from "@webpack"; @@ -84,6 +84,8 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti const canSubmit = () => Object.values(errors).every(e => !e); + const hasSettings = Boolean(pluginSettings && plugin.options); + React.useEffect(() => { (async () => { for (const user of plugin.authors.slice(0, 6)) { @@ -121,33 +123,33 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti } function renderSettings() { - if (!pluginSettings || !plugin.options) { + if (!hasSettings || !plugin.options) { return There are no settings for this plugin.; + } else { + const options = Object.entries(plugin.options).map(([key, setting]) => { + function onChange(newValue: any) { + setTempSettings(s => ({ ...s, [key]: newValue })); + } + + function onError(hasError: boolean) { + setErrors(e => ({ ...e, [key]: hasError })); + } + + const Component = Components[setting.type]; + return ( + + ); + }); + + return {options}; } - - const options = Object.entries(plugin.options).map(([key, setting]) => { - function onChange(newValue: any) { - setTempSettings(s => ({ ...s, [key]: newValue })); - } - - function onError(hasError: boolean) { - setErrors(e => ({ ...e, [key]: hasError })); - } - - const Component = Components[setting.type]; - return ( - - ); - }); - - return {options}; } function renderMoreUsers(_label: string, count: number) { @@ -172,14 +174,16 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti return ( - - {plugin.name} + + {plugin.name} + About {plugin.name} {plugin.description} -
+ Authors +
- + {hasSettings && @@ -233,7 +238,7 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti {saveError && Error while saving: {saveError}} - + } ); } -- cgit