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:
parent
0dd31bfbd0
commit
732248dd04
@ -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>
|
||||
|
@ -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}>
|
||||
|
Loading…
Reference in New Issue
Block a user