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

check channel creation permissions

This commit is contained in:
Puyodead1 2024-03-05 09:50:20 -05:00
parent e4081b8c16
commit 95411d5158
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
2 changed files with 38 additions and 9 deletions

View File

@ -1,9 +1,11 @@
import React, { useContext } from "react"; import React, { useContext, useEffect } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import styled from "styled-components"; import styled from "styled-components";
import { ContextMenuContext } from "../../contexts/ContextMenuContext"; import { ContextMenuContext } from "../../contexts/ContextMenuContext";
import { modalController } from "../../controllers/modals"; import { modalController } from "../../controllers/modals";
import { useAppStore } from "../../stores/AppStore";
import Channel from "../../stores/objects/Channel"; import Channel from "../../stores/objects/Channel";
import { Permissions } from "../../utils/Permissions";
import Icon from "../Icon"; import Icon from "../Icon";
import Floating from "../floating/Floating"; import Floating from "../floating/Floating";
import FloatingTrigger from "../floating/FloatingTrigger"; import FloatingTrigger from "../floating/FloatingTrigger";
@ -43,12 +45,22 @@ interface Props {
} }
function ChannelListItem({ channel, isCategory, active }: Props) { function ChannelListItem({ channel, isCategory, active }: Props) {
const app = useAppStore();
const navigate = useNavigate(); const navigate = useNavigate();
const contextMenu = useContext(ContextMenuContext); const contextMenu = useContext(ContextMenuContext);
const [wrapperHovered, setWrapperHovered] = React.useState(false); const [wrapperHovered, setWrapperHovered] = React.useState(false);
const [createChannelHovered, setCreateChannelHovered] = React.useState(false); const [createChannelHovered, setCreateChannelHovered] = React.useState(false);
const [createChannelDown, setChannelCreateDown] = React.useState(false); const [createChannelDown, setChannelCreateDown] = React.useState(false);
const [hasCreateChannelPermission, setHasCreateChannelPermission] = React.useState(false);
useEffect(() => {
if (!isCategory) return;
const permission = Permissions.getPermission(app.account!.id, channel.guild, channel);
const hasPermission = permission.has("MANAGE_CHANNELS");
setHasCreateChannelPermission(hasPermission);
}, [channel]);
return ( return (
<ListItem <ListItem
@ -100,7 +112,7 @@ function ChannelListItem({ channel, isCategory, active }: Props) {
{channel.name} {channel.name}
</Text> </Text>
</div> </div>
{isCategory && ( {isCategory && hasCreateChannelPermission && (
<Floating <Floating
placement="top" placement="top"
type="tooltip" type="tooltip"

View File

@ -1,8 +1,10 @@
import styled from "styled-components"; import styled from "styled-components";
import useLogger from "../../hooks/useLogger"; import useLogger from "../../hooks/useLogger";
import React, { useEffect } from "react";
import { modalController } from "../../controllers/modals"; import { modalController } from "../../controllers/modals";
import { useAppStore } from "../../stores/AppStore"; import { useAppStore } from "../../stores/AppStore";
import { Permissions } from "../../utils/Permissions";
import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "../contextMenus/ContextMenu"; import { ContextMenu, ContextMenuButton, ContextMenuDivider } from "../contextMenus/ContextMenu";
const CustomContextMenu = styled(ContextMenu)` const CustomContextMenu = styled(ContextMenu)`
@ -10,8 +12,19 @@ const CustomContextMenu = styled(ContextMenu)`
`; `;
function GuildMenuPopout() { function GuildMenuPopout() {
const { activeGuild } = useAppStore(); const { activeGuild, account } = useAppStore();
const logger = useLogger("GuildMenuPopout"); const logger = useLogger("GuildMenuPopout");
const [hasCreateChannelPermission, setHasCreateChannelPermission] = React.useState(false);
useEffect(() => {
if (!activeGuild) return;
const permission = Permissions.getPermission(account!.id, activeGuild, undefined);
const hasPermission = permission.has("MANAGE_CHANNELS");
setHasCreateChannelPermission(hasPermission);
}, [activeGuild]);
if (!activeGuild) { if (!activeGuild) {
logger.error("activeGuild is undefined"); logger.error("activeGuild is undefined");
return null; return null;
@ -36,12 +49,16 @@ function GuildMenuPopout() {
<ContextMenuButton icon="mdiCog" disabled> <ContextMenuButton icon="mdiCog" disabled>
Server Settings Server Settings
</ContextMenuButton> </ContextMenuButton>
{hasCreateChannelPermission && (
<>
<ContextMenuButton icon="mdiPlusCircle" onClick={onChannelCreateClick}> <ContextMenuButton icon="mdiPlusCircle" onClick={onChannelCreateClick}>
Create Channel Create Channel
</ContextMenuButton> </ContextMenuButton>
<ContextMenuButton icon="mdiFolderPlus" disabled> <ContextMenuButton icon="mdiFolderPlus" disabled>
Create Category Create Category
</ContextMenuButton> </ContextMenuButton>
</>
)}
<ContextMenuDivider /> <ContextMenuDivider />
<ContextMenuButton icon="mdiBell" disabled> <ContextMenuButton icon="mdiBell" disabled>
Notification Settings Notification Settings