From 5be2fb5b9b14c3dc495d6d3232a376fb74abeae2 Mon Sep 17 00:00:00 2001 From: programminglaboratorys Date: Fri, 27 Sep 2024 19:15:50 +0300 Subject: [PATCH] no longer using ContextMenuAPI and refactoring --- src/plugins/statusPresets/index.tsx | 77 +++++++++++------------------ 1 file changed, 28 insertions(+), 49 deletions(-) diff --git a/src/plugins/statusPresets/index.tsx b/src/plugins/statusPresets/index.tsx index 8cae9064c..b8e16d2c4 100644 --- a/src/plugins/statusPresets/index.tsx +++ b/src/plugins/statusPresets/index.tsx @@ -16,14 +16,13 @@ * along with this program. If not, see . */ -import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { definePluginSettings } from "@api/Settings"; import { getUserSettingLazy } from "@api/UserSettings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; -import definePlugin, { OptionType } from "@utils/types"; +import definePlugin, { OptionType, StartAt } from "@utils/types"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { Button, Clickable, Menu, Text, Toasts, useState } from "@webpack/common"; +import { Button, Clickable, Icons, Menu, Text, Toasts, useState } from "@webpack/common"; // const { PMenu } = mapMangledModuleLazy("{id:t,label:n,icon:c,hint:_,renderSubmenu:E,...h}", { // PMenu: filters.byCode("{id:t,label:n,icon:c,hint:_,renderSubmenu:E,...h}") @@ -37,7 +36,6 @@ const PSubMenu = findComponentByCodeLazy("submenuPaddingContainer,children:(0,i. const Components = findByPropsLazy("Status"); const StatusStyles = findByPropsLazy("statusItem"); -const Icons = findByPropsLazy("CircleXIcon"); const statusSettings = getUserSettingLazy("status", "status"); const customStatusSettings = getUserSettingLazy("status", "status"); @@ -66,6 +64,12 @@ const settings = definePluginSettings({ } }); + +function SetStatus(status: DiscordStatus, sourceAnalyticsContext: any) { + return Vencord.Webpack.wreq(720449).Z(status.text, status.emojiInfo, status.clearAfter, sourceAnalyticsContext); +} + + const RenderStatusMenuItem = ({ status }) => { const [isHovering, setIsHovering] = useState(false); @@ -103,23 +107,17 @@ const RenderStatusMenuItem = ({ status }) => { ; }; -function MakeContextCallback(): NavContextMenuPatchCallback { - return (children, _) => { - children[0]?.props.children.splice(1, 0, - - {Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => console.log("pog")} - render={() => } - />)} - - ); - }; -} +const StatusSubMenuComponent = () => { + return { }}> + {Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => SetStatus(status, { "location": { "section": "Account Panel", "object": "Avatar" } })} + render={() => } + />)} + ; +}; + export default definePlugin({ name: "StatusPresets_", @@ -143,42 +141,22 @@ export default definePlugin({ } } ], - contextMenus: { - "set-status-submenu": MakeContextCallback() - }, - render(status, openStatusModal, OnClose) { + render(status, openStatusModal_: () => void, OnClose: () => void) { + const openStatusModal = () => { OnClose(), openStatusModal_(); }; return
{status == null ? { OnClose(), openStatusModal(); }} + onClick={openStatusModal} icon={() =>
} - label="Set Custom Status" renderSubmenu={() => { - return { }}> - {Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => console.log("pog")} - render={() => } - />)} - ; - }} /> : : { OnClose(), openStatusModal(); }} - hint={ customStatusSettings.updateSetting(null)}>} + onClick={openStatusModal} + hint={ customStatusSettings.updateSetting(null)}>} icon={() => status.emoji != null ? : null} - label="Edit Custom Status" renderSubmenu={() => { - return { }}> - {Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => console.log("pog")} - render={() => } - />)} - ; - }} />} + label="Edit Custom Status" renderSubmenu={StatusSubMenuComponent} />} ; }, renderRememberButton(statue: DiscordStatus) { @@ -190,5 +168,6 @@ export default definePlugin({ id: Toasts.genId() }); }} style={{ marginRight: "20px" }}>Remember; - } + }, + startAt: StartAt.WebpackReady });