-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ceb6a9
commit 7f18a70
Showing
1 changed file
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ import { Logger } from "@replugged"; | |
import type { User } from "discord-types/general"; | ||
import { Injector } from "../../modules/injector"; | ||
import { getByProps, waitForProps } from "../../modules/webpack"; | ||
import {util} from "@replugged"; | ||
Check warning on line 6 in src/renderer/coremods/badges/index.tsx GitHub Actions / Run ESLint
|
||
import { generalSettings } from "../settings/pages/General"; | ||
import { APIBadges, BadgeSizes, Custom, badgeElements, getBadgeSizeClass } from "./badge"; | ||
import {Tree} from "../../util"; | ||
|
||
const injector = new Injector(); | ||
|
||
|
@@ -22,19 +24,25 @@ interface BadgeModArgs { | |
|
||
type BadgeMod = (args: BadgeModArgs) => | ||
| React.ReactElement<{ | ||
children?: React.ReactElement[]; | ||
className: string; | ||
}> | ||
children?: React.ReactElement[]; | ||
className: string; | ||
}> | ||
| undefined; | ||
|
||
interface BadgeCache { | ||
badges: APIBadges; | ||
lastFetch: number; | ||
} | ||
|
||
interface BadgeHighs | ||
{ | ||
props:{children:{props:{children:{}}}} | ||
} | ||
|
||
// todo: guilds | ||
const cache = new Map<string, BadgeCache>(); | ||
const REFRESH_INTERVAL = 1000 * 60 * 30; | ||
type TreeWithCombine = Tree & { className: string }; | ||
|
||
export async function start(): Promise<void> { | ||
const mod = await waitForProps<{ BadgeSizes: BadgeSizes; default: BadgeMod }>("BadgeSizes"); | ||
|
@@ -43,7 +51,7 @@ export async function start(): Promise<void> { | |
"containerWithContent", | ||
)!; | ||
|
||
injector.after(mod, "default", ([props], res) => { | ||
injector.after(mod, "default", ([props], res: BadgeHighs) => { | ||
let { | ||
user: { id }, | ||
shrinkAtCount, | ||
|
@@ -93,7 +101,7 @@ export async function start(): Promise<void> { | |
if (!badges) { | ||
return res; | ||
} | ||
const children = res?.props.children; | ||
const children = res?.props.children.props.children; | ||
if (!children || !Array.isArray(children)) { | ||
logger.error("Error injecting badges: res.props.children is not an array", { children }); | ||
return res; | ||
|
@@ -134,15 +142,19 @@ export async function start(): Promise<void> { | |
} | ||
}); | ||
|
||
const badgesClassName: TreeWithCombine | any = util.findInTree(res as unknown as Tree, x => Boolean(x?.className)); | ||
if (!badgesClassName) return; | ||
|
||
if (children.length > 0) { | ||
if (!res.props.className.includes(containerWithContent)) { | ||
res.props.className += ` ${containerWithContent}`; | ||
if (!badgesClassName.className.includes(containerWithContent)) { | ||
badgesClassName.className += ` ${containerWithContent}`; | ||
} | ||
if (!res.props.className.includes("replugged-badges-container")) { | ||
res.props.className += " replugged-badges-container"; | ||
if (!badgesClassName.className.includes("replugged-badges-container")) { | ||
badgesClassName.className += " replugged-badges-container"; | ||
} | ||
} | ||
|
||
|
||
return res; | ||
} catch (err) { | ||
logger.error(err); | ||
|