1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-25 11:42: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 // 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 Channel from "../../stores/objects/Channel";
import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu"; import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu";
@ -15,8 +16,20 @@ function ChannelContextMenu({ channel }: MenuProps) {
navigator.clipboard.writeText(channel.id); navigator.clipboard.writeText(channel.id);
} }
/**
* Open invite creation modal
*/
function openInviteCreateModal() {
modalController.push({
type: "create_invite",
target: channel,
});
}
return ( return (
<ContextMenu> <ContextMenu>
<ContextMenuButton onClick={openInviteCreateModal}>Create Invite</ContextMenuButton>
<ContextMenuDivider />
{channel.hasPermission("MANAGE_CHANNELS") && ( {channel.hasPermission("MANAGE_CHANNELS") && (
<> <>
<ContextMenuButton disabled>Edit Channel</ContextMenuButton> <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 // 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 { modalController } from "../../controllers/modals";
import useLogger from "../../hooks/useLogger";
import { useAppStore } from "../../stores/AppStore"; import { useAppStore } from "../../stores/AppStore";
import Guild from "../../stores/objects/Guild"; import Guild from "../../stores/objects/Guild";
import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu"; import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "./ContextMenu";
@ -11,6 +13,7 @@ interface MenuProps {
function GuildContextMenu({ guild }: MenuProps) { function GuildContextMenu({ guild }: MenuProps) {
const app = useAppStore(); const app = useAppStore();
const logger = useLogger("GuildContextMenu");
const isNotOwner = guild.ownerId !== app.account!.id; const isNotOwner = guild.ownerId !== app.account!.id;
/** /**
* Copy id to clipboard * 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 ( return (
<ContextMenu> <ContextMenu>
<ContextMenuButton onClick={openInviteCreateModal}>Create Invite</ContextMenuButton>
<ContextMenuDivider />
{isNotOwner && ( {isNotOwner && (
<> <>
<ContextMenuButton destructive onClick={leaveGuild}> <ContextMenuButton destructive onClick={leaveGuild}>