From c1e6ad876a4811dce496176437612e915b6c3977 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Tue, 19 Dec 2023 12:12:05 -0500 Subject: [PATCH] guild context menu --- src/components/GuildItem.tsx | 9 ++- .../contextMenus/GuildContextMenu.tsx | 59 +++++++++++++++++++ src/contexts/ContextMenuContext.tsx | 5 ++ src/hooks/useContextMenu.tsx | 2 + 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/components/contextMenus/GuildContextMenu.tsx diff --git a/src/components/GuildItem.tsx b/src/components/GuildItem.tsx index 2e46712..eb6e8e1 100644 --- a/src/components/GuildItem.tsx +++ b/src/components/GuildItem.tsx @@ -1,8 +1,9 @@ import { CDNRoutes, ChannelType, ImageFormat } from "@spacebarchat/spacebar-api-types/v9"; import { observer } from "mobx-react-lite"; -import React from "react"; +import React, { useContext } from "react"; import { useNavigate } from "react-router-dom"; import styled from "styled-components"; +import { ContextMenuContext } from "../contexts/ContextMenuContext"; import useLogger from "../hooks/useLogger"; import { useAppStore } from "../stores/AppStore"; import Guild from "../stores/objects/Guild"; @@ -49,6 +50,7 @@ function GuildItem({ guild, active }: Props) { const logger = useLogger("GuildItem"); const app = useAppStore(); const navigate = useNavigate(); + const contextMenu = useContext(ContextMenuContext); const [pillType, setPillType] = React.useState("none"); const [isHovered, setHovered] = React.useState(false); @@ -69,7 +71,10 @@ function GuildItem({ guild, active }: Props) { }; return ( - + contextMenu.onContextMenu(e, { type: "guild", guild })} + > + {isNotOwner && ( + <> + + Leave Guild + + + + )} + + Copy Guild ID + + + ); +} + +export default GuildContextMenu; diff --git a/src/contexts/ContextMenuContext.tsx b/src/contexts/ContextMenuContext.tsx index 8145a55..1892b6e 100644 --- a/src/contexts/ContextMenuContext.tsx +++ b/src/contexts/ContextMenuContext.tsx @@ -3,6 +3,7 @@ import { FloatingPortal, useFloating } from "@floating-ui/react"; import React from "react"; import useContextMenu, { ContextMenuComponents } from "../hooks/useContextMenu"; import Channel from "../stores/objects/Channel"; +import Guild from "../stores/objects/Guild"; import GuildMember from "../stores/objects/GuildMember"; import { MessageLike } from "../stores/objects/Message"; import User from "../stores/objects/User"; @@ -20,6 +21,10 @@ export type ContextMenuProps = | { type: "channel"; channel: Channel; + } + | { + type: "guild"; + guild: Guild; }; export type ContextMenuContextType = { diff --git a/src/hooks/useContextMenu.tsx b/src/hooks/useContextMenu.tsx index 07357a0..caefa58 100644 --- a/src/hooks/useContextMenu.tsx +++ b/src/hooks/useContextMenu.tsx @@ -1,6 +1,7 @@ import { autoUpdate, flip, offset, shift, useDismiss, useFloating, useInteractions, useRole } from "@floating-ui/react"; import { useMemo, useState } from "react"; import ChannelContextMenu from "../components/contextMenus/ChannelContextMenu"; +import GuildContextMenu from "../components/contextMenus/GuildContextMenu"; import MessageContextMenu from "../components/contextMenus/MessageContextMenu"; import UserContextMenu from "../components/contextMenus/UserContextMenu"; import { ContextMenuProps } from "../contexts/ContextMenuContext"; @@ -12,6 +13,7 @@ export const ContextMenuComponents: Components = { user: UserContextMenu, message: MessageContextMenu, channel: ChannelContextMenu, + guild: GuildContextMenu, }; export default function () {