1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-22 10:22:30 +01:00

add invite creation context menu item

This commit is contained in:
Puyodead1 2023-12-23 23:30:54 -05:00
parent 0dd31bfbd0
commit 732248dd04
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
2 changed files with 33 additions and 0 deletions

View File

@ -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 (
<ContextMenu>
<ContextMenuButton onClick={openInviteCreateModal}>Create Invite</ContextMenuButton>
<ContextMenuDivider />
{channel.hasPermission("MANAGE_CHANNELS") && (
<>
<ContextMenuButton disabled>Edit Channel</ContextMenuButton>

View File

@ -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 (
<ContextMenu>
<ContextMenuButton onClick={openInviteCreateModal}>Create Invite</ContextMenuButton>
<ContextMenuDivider />
{isNotOwner && (
<>
<ContextMenuButton destructive onClick={leaveGuild}>