From 6381cfee4f989d7d827e807c7ac8353416dd73d7 Mon Sep 17 00:00:00 2001 From: Albert Portnoy Date: Mon, 10 Apr 2023 22:27:14 -0500 Subject: [PATCH] fix: badges injection --- src/renderer/coremods/badges/index.tsx | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/renderer/coremods/badges/index.tsx b/src/renderer/coremods/badges/index.tsx index c52fd43b5..bfabbf025 100644 --- a/src/renderer/coremods/badges/index.tsx +++ b/src/renderer/coremods/badges/index.tsx @@ -11,10 +11,15 @@ interface BadgeModArgs { user: User; } -type BadgeMod = (args: BadgeModArgs) => React.ReactElement<{ - children: React.ReactElement[]; - className: string; -}>; +type BadgeMod = (args: BadgeModArgs) => { + props: unknown; + type: (props: unknown) => { + props: { + className: string; + children: React.ReactElement[]; + }; + }; +}; interface BadgeCache { badges: APIBadges; @@ -51,7 +56,8 @@ export async function start(): Promise { res, ) => { if (!generalSettings.get("badges")) return res; - if (!res?.props?.children) return res; + const memoRes = res.type(res.props); + res.type = () => memoRes; const [badges, setBadges] = React.useState(); @@ -93,13 +99,13 @@ export async function start(): Promise { } if (badges.custom?.name && badges.custom.icon) { - res.props.children.push(); + memoRes.props.children.push(); } badgeElements.forEach(({ type, component }) => { const value = badges[type]; if (value) { - res.props.children.push( + memoRes.props.children.push( React.createElement(component, { color: badges.custom?.color, }), @@ -107,12 +113,12 @@ export async function start(): Promise { } }); - if (res.props.children.length > 0) { - if (!res.props.className.includes(containerWithContent)) { - res.props.className += ` ${containerWithContent}`; + if (memoRes.props.children.length > 0) { + if (!memoRes.props.className.includes(containerWithContent)) { + memoRes.props.className += ` ${containerWithContent}`; } - if (!res.props.className.includes("replugged-badges-container")) { - res.props.className += " replugged-badges-container"; + if (!memoRes.props.className.includes("replugged-badges-container")) { + memoRes.props.className += " replugged-badges-container"; } }