fix adding View Raw to undesired channel context menus

This commit is contained in:
Vendicated 2024-01-09 17:39:38 +01:00
parent ba2695b499
commit ba6d23a31f
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
2 changed files with 11 additions and 5 deletions

View file

@ -126,7 +126,9 @@ function MenuItem(guildId: string, id?: string, type?: MenuItemParentType) {
function makeContextMenuPatch(childId: string | string[], type?: MenuItemParentType): NavContextMenuPatchCallback { function makeContextMenuPatch(childId: string | string[], type?: MenuItemParentType): NavContextMenuPatchCallback {
return (children, props) => () => { return (children, props) => () => {
if (!props || (type === MenuItemParentType.User && !props.user) || (type === MenuItemParentType.Guild && !props.guild)) return children; if (!props) return;
if ((type === MenuItemParentType.User && !props.user) || (type === MenuItemParentType.Guild && !props.guild) || (type === MenuItemParentType.Channel && (!props.channel || !props.guild)))
return children;
const group = findGroupChildrenByChildId(childId, children); const group = findGroupChildrenByChildId(childId, children);

View file

@ -117,22 +117,26 @@ const settings = definePluginSettings({
} }
}); });
function MakeContextCallback(name: string) { function MakeContextCallback(name: "Guild" | "User" | "Channel") {
const callback: NavContextMenuPatchCallback = (children, props) => () => { const callback: NavContextMenuPatchCallback = (children, props) => () => {
if ((name === "Guild" && !props.guild) || (name === "User" && !props.user)) return; const value = props[name.toLowerCase()];
if (!value) return;
if (props.label === "Channel Actions") return; // random shit like notification settings
const lastChild = children.at(-1); const lastChild = children.at(-1);
if (lastChild?.key === "developer-actions") { if (lastChild?.key === "developer-actions") {
const p = lastChild.props; const p = lastChild.props;
if (!Array.isArray(p.children)) if (!Array.isArray(p.children))
p.children = [p.children]; p.children = [p.children];
({ children } = p);
children = p.children;
} }
children.splice(-1, 0, children.splice(-1, 0,
<Menu.MenuItem <Menu.MenuItem
id={`vc-view-${name.toLowerCase()}-raw`} id={`vc-view-${name.toLowerCase()}-raw`}
label="View Raw" label="View Raw"
action={() => openViewRawModal(JSON.stringify(props[name.toLowerCase()], null, 4), name)} action={() => openViewRawModal(JSON.stringify(value, null, 4), name)}
icon={CopyIcon} icon={CopyIcon}
/> />
); );