From 732248dd042b47f108a4f30fce458a0c2980eab7 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sat, 23 Dec 2023 23:30:54 -0500 Subject: [PATCH] add invite creation context menu item --- .../contextMenus/ChannelContextMenu.tsx | 13 ++++++++++++ .../contextMenus/GuildContextMenu.tsx | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/components/contextMenus/ChannelContextMenu.tsx b/src/components/contextMenus/ChannelContextMenu.tsx index da3ea1f..9597cc6 100644 --- a/src/components/contextMenus/ChannelContextMenu.tsx +++ b/src/components/contextMenus/ChannelContextMenu.tsx @@ -1,5 +1,6 @@ // loosely based on https://github.com/revoltchat/frontend/blob/master/components/app/menus/UserContextMenu.tsx +import { modalController } from "../../controllers/modals"; import Channel from "../../stores/objects/Channel"; import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu"; @@ -15,8 +16,20 @@ function ChannelContextMenu({ channel }: MenuProps) { navigator.clipboard.writeText(channel.id); } + /** + * Open invite creation modal + */ + function openInviteCreateModal() { + modalController.push({ + type: "create_invite", + target: channel, + }); + } + return ( + Create Invite + {channel.hasPermission("MANAGE_CHANNELS") && ( <> Edit Channel diff --git a/src/components/contextMenus/GuildContextMenu.tsx b/src/components/contextMenus/GuildContextMenu.tsx index ed3f98a..b7aedf3 100644 --- a/src/components/contextMenus/GuildContextMenu.tsx +++ b/src/components/contextMenus/GuildContextMenu.tsx @@ -1,6 +1,8 @@ // loosely based on https://github.com/revoltchat/frontend/blob/master/components/app/menus/UserContextMenu.tsx +import { ChannelType } from "@spacebarchat/spacebar-api-types/v9"; import { modalController } from "../../controllers/modals"; +import useLogger from "../../hooks/useLogger"; import { useAppStore } from "../../stores/AppStore"; import Guild from "../../stores/objects/Guild"; import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu"; @@ -11,6 +13,7 @@ interface MenuProps { function GuildContextMenu({ guild }: MenuProps) { const app = useAppStore(); + const logger = useLogger("GuildContextMenu"); const isNotOwner = guild.ownerId !== app.account!.id; /** * Copy id to clipboard @@ -29,8 +32,25 @@ function GuildContextMenu({ guild }: MenuProps) { }); } + /** + * Open invite creation modal + */ + function openInviteCreateModal() { + const channel = guild.channels.find((x) => x.type === ChannelType.GuildText && x.hasPermission("VIEW_CHANNEL")); + if (!channel) { + logger.error("Failed to find suitable channel for invite creation"); + return; + } + modalController.push({ + type: "create_invite", + target: channel, + }); + } + return ( + Create Invite + {isNotOwner && ( <>