Fix unnecessarily re-renders
This commit is contained in:
parent
d75d00fb39
commit
7636cafd91
1 changed files with 83 additions and 87 deletions
34
renderer.js
34
renderer.js
|
@ -26,13 +26,7 @@ export default new (class PackageDownloader {
|
|||
? args[0].children.at(-1).props
|
||||
: null
|
||||
|
||||
if (
|
||||
props?.message &&
|
||||
props.channel &&
|
||||
props.channel.id == "899717501120806963"
|
||||
)
|
||||
args[0].children.unshift(
|
||||
React.createElement(() => {
|
||||
const Button = () => {
|
||||
const [disabled, setDisabled] = React.useState(false)
|
||||
|
||||
const gitURL = props.message.content
|
||||
|
@ -42,12 +36,12 @@ export default new (class PackageDownloader {
|
|||
)
|
||||
|
||||
if (!disabled)
|
||||
Object.values(
|
||||
kernel.packages.getPackages()
|
||||
).forEach((pkg) => {
|
||||
Object.values(kernel.packages.getPackages()).forEach(
|
||||
(pkg) => {
|
||||
if (pkg.path.split("/").at(-1) == gitURL[7])
|
||||
setDisabled(true)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return [
|
||||
React.createElement(
|
||||
|
@ -67,16 +61,13 @@ export default new (class PackageDownloader {
|
|||
onClick: async () => {
|
||||
setDisabled(true)
|
||||
const failed =
|
||||
await window.installPackage(
|
||||
gitURL
|
||||
)
|
||||
await window.installPackage(gitURL)
|
||||
|
||||
if (failed) {
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Failed to install package",
|
||||
Toasts.ToastType
|
||||
.ERROR
|
||||
Toasts.ToastType.ERROR
|
||||
)
|
||||
)
|
||||
pluginLog(
|
||||
|
@ -88,8 +79,7 @@ export default new (class PackageDownloader {
|
|||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Successfully installed package! Please reload discord with Ctrl+R.",
|
||||
Toasts.ToastType
|
||||
.SUCCESS
|
||||
Toasts.ToastType.SUCCESS
|
||||
)
|
||||
)
|
||||
pluginLog(
|
||||
|
@ -116,8 +106,14 @@ export default new (class PackageDownloader {
|
|||
),
|
||||
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)
|
||||
}
|
||||
|
|
Reference in a new issue