Changed button into anonymous arrow function

This commit is contained in:
Henry Hiles 2022-04-26 12:25:30 -04:00
parent 2db736aa59
commit 31d29253ab

View file

@ -16,18 +16,35 @@ export default new (class PackageDownloader {
const Tooltip = Webpack.findByDisplayName("Tooltip") const Tooltip = Webpack.findByDisplayName("Tooltip")
const funcCopy = MiniPopover.default const funcCopy = MiniPopover.default
const Button = (componentProps) => { MiniPopover.default = (...args) => {
const [disabled, setDisabled] = React.useState(false) const props = args[0].children.at
? args[0].children.at(-1).props
: null
if (
props?.message &&
props.channel &&
props.channel.id == "899717501120806963"
)
args[0].children.unshift(
React.createElement(
(componentProps) => {
const [disabled, setDisabled] =
React.useState(false)
const props = componentProps.props const props = componentProps.props
const gitURL = props.message.content const gitURL = props.message.content
.slice(props.message.content.indexOf("Repository")) .slice(
props.message.content.indexOf("Repository")
)
.match( .match(
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/ /((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
) )
if (!disabled) if (!disabled)
Object.values(kernel.packages.getPackages()).forEach((pkg) => { Object.values(
kernel.packages.getPackages()
).forEach((pkg) => {
if (pkg.path.split("/").at(-1) == gitURL[7]) if (pkg.path.split("/").at(-1) == gitURL[7])
setDisabled(true) setDisabled(true)
}) })
@ -49,7 +66,8 @@ export default new (class PackageDownloader {
disabled: disabled, disabled: disabled,
onClick: async () => { onClick: async () => {
setDisabled(true) setDisabled(true)
const failed = await window.package.install( const failed =
await window.package.install(
gitURL gitURL
) )
@ -57,7 +75,8 @@ export default new (class PackageDownloader {
Toasts.showToast( Toasts.showToast(
Toasts.createToast( Toasts.createToast(
"Failed to install package", "Failed to install package",
Toasts.ToastType.ERROR Toasts.ToastType
.ERROR
) )
) )
console.error( console.error(
@ -69,7 +88,8 @@ 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.SUCCESS Toasts.ToastType
.SUCCESS
) )
) )
console.log( console.log(
@ -96,21 +116,15 @@ export default new (class PackageDownloader {
) )
) )
), ),
React.createElement(MiniPopover.Separator, null), React.createElement(
MiniPopover.Separator,
null
),
] ]
} },
{ props }
MiniPopover.default = (...args) => { )
const props = args[0].children.at
? args[0].children.at(-1).props
: null
if (
props?.message &&
props.channel &&
props.channel.id == "899717501120806963"
) )
args[0].children.unshift(React.createElement(Button, { props }))
return funcCopy.apply(this, args) return funcCopy.apply(this, args)
} }