diff --git a/src/equicordplugins/hideChatButtons/index.tsx b/src/equicordplugins/hideChatButtons/index.tsx new file mode 100644 index 00000000..8f16b510 --- /dev/null +++ b/src/equicordplugins/hideChatButtons/index.tsx @@ -0,0 +1,104 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { ChatBarButton } from "@api/ChatButtons"; +import { definePluginSettings } from "@api/Settings"; +import { EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType, StartAt } from "@utils/types"; +import { useMemo, useState } from "@webpack/common"; +import { MouseEventHandler } from "react"; + +let hidechatbuttonsopen: boolean | undefined; + +const settings = definePluginSettings({ + Color: { + type: OptionType.BOOLEAN, + description: "Color it red on open", // something extra + default: false, + }, + Open: { + type: OptionType.BOOLEAN, + description: "opened by default", + default: false, + onChange: (store: { open: boolean; }) => { + console.log("changing open", store.open); + hidechatbuttonsopen = store.open; + } + }, +}); + +// id={"menu-button-" + (props.open ? "close" : "open")} +function HideToggleButton(props: { open: boolean | undefined, onClick: MouseEventHandler; }) { + console.log(props.open); + return ( + + {props.open ? + <> : + + } + + ); +} +interface ButtonReactNode { + props?: { + disabled?: boolean; + }; +} + +function buttonsInner(buttons: ButtonReactNode[]) { + if (buttons.every(x => x.props?.disabled === true)) { + return null; + } + const [open, setOpen] = useState(hidechatbuttonsopen); + + useMemo(() => { + console.log("useMemo: changing open", open); + hidechatbuttonsopen = open; + }, [open]); + + const buttonList = ( +
+ {open ? buttons.map(b => <>{b}) : null} + setOpen(!open)} open={open}> +
+ ); + buttons = [buttonList]; + return buttons; +} + + +export default definePlugin({ + name: "hideChatButtons", + description: "able to hide the chat buttons", + settings: settings, + authors: [EquicordDevs.iamme], + patches: [ + { + find: '"sticker")', + replacement: { + match: /(.buttons,children:)(\i)\}/, + replace: "$1$self.buttonsInner($2)}" + } + } + ], + startAt: StartAt.Init, + buttonsInner: buttonsInner, + start: async () => { hidechatbuttonsopen = settings.store.Open; } +});