Fix unnecessarily re-renders

This commit is contained in:
Henry Hiles 2022-04-26 14:45:44 -04:00
parent d75d00fb39
commit 7636cafd91

View file

@ -26,13 +26,7 @@ export default new (class PackageDownloader {
? args[0].children.at(-1).props ? args[0].children.at(-1).props
: null : null
if ( const Button = () => {
props?.message &&
props.channel &&
props.channel.id == "899717501120806963"
)
args[0].children.unshift(
React.createElement(() => {
const [disabled, setDisabled] = React.useState(false) const [disabled, setDisabled] = React.useState(false)
const gitURL = props.message.content const gitURL = props.message.content
@ -42,12 +36,12 @@ export default new (class PackageDownloader {
) )
if (!disabled) if (!disabled)
Object.values( Object.values(kernel.packages.getPackages()).forEach(
kernel.packages.getPackages() (pkg) => {
).forEach((pkg) => {
if (pkg.path.split("/").at(-1) == gitURL[7]) if (pkg.path.split("/").at(-1) == gitURL[7])
setDisabled(true) setDisabled(true)
}) }
)
return [ return [
React.createElement( React.createElement(
@ -67,16 +61,13 @@ export default new (class PackageDownloader {
onClick: async () => { onClick: async () => {
setDisabled(true) setDisabled(true)
const failed = const failed =
await window.installPackage( await window.installPackage(gitURL)
gitURL
)
if (failed) { if (failed) {
Toasts.showToast( Toasts.showToast(
Toasts.createToast( Toasts.createToast(
"Failed to install package", "Failed to install package",
Toasts.ToastType Toasts.ToastType.ERROR
.ERROR
) )
) )
pluginLog( pluginLog(
@ -88,8 +79,7 @@ export default new (class PackageDownloader {
Toasts.showToast( Toasts.showToast(
Toasts.createToast( Toasts.createToast(
"Successfully installed package! Please reload discord with Ctrl+R.", "Successfully installed package! Please reload discord with Ctrl+R.",
Toasts.ToastType Toasts.ToastType.SUCCESS
.SUCCESS
) )
) )
pluginLog( pluginLog(
@ -116,8 +106,14 @@ export default new (class PackageDownloader {
), ),
React.createElement(MiniPopover.Separator), React.createElement(MiniPopover.Separator),
] ]
}) }
if (
props?.message &&
props.channel &&
props.channel.id == "899717501120806963"
) )
args[0].children.unshift(React.createElement(Button))
return funcCopy.apply(this, args) return funcCopy.apply(this, args)
} }