1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 09:56:24 +00:00

no longer using ContextMenuAPI and refactoring

This commit is contained in:
programminglaboratorys 2024-09-27 19:15:50 +03:00
parent 0d289a3ddc
commit 5be2fb5b9b

View file

@ -16,14 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { getUserSettingLazy } from "@api/UserSettings"; import { getUserSettingLazy } from "@api/UserSettings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType, StartAt } from "@utils/types";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; 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}", { // 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}") // 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 Components = findByPropsLazy("Status");
const StatusStyles = findByPropsLazy("statusItem"); const StatusStyles = findByPropsLazy("statusItem");
const Icons = findByPropsLazy("CircleXIcon");
const statusSettings = getUserSettingLazy("status", "status"); const statusSettings = getUserSettingLazy("status", "status");
const customStatusSettings = 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 RenderStatusMenuItem = ({ status }) => {
const [isHovering, setIsHovering] = useState(false); const [isHovering, setIsHovering] = useState(false);
@ -103,23 +107,17 @@ const RenderStatusMenuItem = ({ status }) => {
</div>; </div>;
}; };
function MakeContextCallback(): NavContextMenuPatchCallback { const StatusSubMenuComponent = () => {
return (children, _) => { return <Menu.Menu navId="sp-custom-status-submenu" onClose={() => { }}>
children[0]?.props.children.splice(1, 0, {Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => <Menu.MenuItem
<Menu.MenuItem id={"status-presets-" + status.text}
id="status-presets" label={status.status}
label="Presets" // add an icon to fit in action={() => SetStatus(status, { "location": { "section": "Account Panel", "object": "Avatar" } })}
> render={() => <RenderStatusMenuItem status={status} />}
{Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => <Menu.MenuItem />)}
id={"status-presets-" + status.text} </Menu.Menu>;
label={status.status} };
action={() => console.log("pog")}
render={() => <RenderStatusMenuItem status={status} />}
/>)}
</Menu.MenuItem>
);
};
}
export default definePlugin({ export default definePlugin({
name: "StatusPresets_", name: "StatusPresets_",
@ -143,42 +141,22 @@ export default definePlugin({
} }
} }
], ],
contextMenus: { render(status, openStatusModal_: () => void, OnClose: () => void) {
"set-status-submenu": MakeContextCallback() const openStatusModal = () => { OnClose(), openStatusModal_(); };
},
render(status, openStatusModal, OnClose) {
return <ErrorBoundary> return <ErrorBoundary>
<div className={StatusStyles.menuDivider} /> <div className={StatusStyles.menuDivider} />
{status == null ? <PMenu {status == null ? <PMenu
id="sp-custom/presets-status" id="sp-custom/presets-status"
action="PRESS_SET_STATUS" action="PRESS_SET_STATUS"
onClick={() => { OnClose(), openStatusModal(); }} onClick={openStatusModal}
icon={() => <div className={StatusStyles.customEmojiPlaceholder} />} icon={() => <div className={StatusStyles.customEmojiPlaceholder} />}
label="Set Custom Status" renderSubmenu={() => { label="Set Custom Status" renderSubmenu={StatusSubMenuComponent} /> : <PMenu
return <Menu.Menu navId="sp-custom-status-submenu" onClose={() => { }}>
{Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => <Menu.MenuItem
id={"status-presets-" + status.text}
label={status.status}
action={() => console.log("pog")}
render={() => <RenderStatusMenuItem status={status} />}
/>)}
</Menu.Menu>;
}} /> : <PMenu
id="sp-edit/presets-status" id="sp-edit/presets-status"
action="PRESS_EDIT_CUSTOM_STATUS" action="PRESS_EDIT_CUSTOM_STATUS"
onClick={() => { OnClose(), openStatusModal(); }} onClick={openStatusModal}
hint={<Clickable className={StatusStyles.clearCustomStatusHint} onClick={() => customStatusSettings.updateSetting(null)}><Menu.CircleXIcon size="sm" /></Clickable>} hint={<Clickable className={StatusStyles.clearCustomStatusHint} onClick={() => customStatusSettings.updateSetting(null)}><Icons.CircleXIcon size="sm" /></Clickable>}
icon={() => status.emoji != null ? <EmojiComponent emoji={status.emoji} animate={false} hideTooltip={false} /> : null} icon={() => status.emoji != null ? <EmojiComponent emoji={status.emoji} animate={false} hideTooltip={false} /> : null}
label="Edit Custom Status" renderSubmenu={() => { label="Edit Custom Status" renderSubmenu={StatusSubMenuComponent} />}
return <Menu.Menu navId="sp-custom-status-submenu" onClose={() => { }}>
{Object.values((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(status => <Menu.MenuItem
id={"status-presets-" + status.text}
label={status.status}
action={() => console.log("pog")}
render={() => <RenderStatusMenuItem status={status} />}
/>)}
</Menu.Menu>;
}} />}
</ErrorBoundary>; </ErrorBoundary>;
}, },
renderRememberButton(statue: DiscordStatus) { renderRememberButton(statue: DiscordStatus) {
@ -190,5 +168,6 @@ export default definePlugin({
id: Toasts.genId() id: Toasts.genId()
}); });
}} style={{ marginRight: "20px" }}>Remember</Button>; }} style={{ marginRight: "20px" }}>Remember</Button>;
} },
startAt: StartAt.WebpackReady
}); });