From 49d54ee05a90a4136f787958c0a45896c5d5aeac Mon Sep 17 00:00:00 2001 From: Ryan Alexander Date: Tue, 17 Aug 2021 06:31:25 +1000 Subject: [PATCH 1/2] Added create category context menu when right clicking in channel list --- src/context/intermediate/Intermediate.tsx | 1 + src/context/intermediate/modals/Prompt.tsx | 60 ++++++++++++++++++++++ src/lib/ContextMenus.tsx | 18 ++++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/context/intermediate/Intermediate.tsx b/src/context/intermediate/Intermediate.tsx index ac3f8f47..a3d30489 100644 --- a/src/context/intermediate/Intermediate.tsx +++ b/src/context/intermediate/Intermediate.tsx @@ -46,6 +46,7 @@ export type Screen = | { type: "unfriend_user"; target: User } | { type: "block_user"; target: User } | { type: "create_channel"; target: Server } + | { type: "create_category"; target: Server } )) | ({ id: "special_input" } & ( | { diff --git a/src/context/intermediate/modals/Prompt.tsx b/src/context/intermediate/modals/Prompt.tsx index 9b1e4462..d58fa53c 100644 --- a/src/context/intermediate/modals/Prompt.tsx +++ b/src/context/intermediate/modals/Prompt.tsx @@ -1,5 +1,6 @@ import { observer } from "mobx-react-lite"; import { useHistory } from "react-router-dom"; +import { Category } from "revolt-api/types/Servers"; import { Channel } from "revolt.js/dist/maps/Channels"; import { Message as MessageI } from "revolt.js/dist/maps/Messages"; import { Server } from "revolt.js/dist/maps/Servers"; @@ -70,6 +71,7 @@ type SpecialProps = { onClose: () => void } & ( | { type: "unfriend_user"; target: User } | { type: "block_user"; target: User } | { type: "create_channel"; target: Server } + | { type: "create_category"; target: Server } ); export const SpecialPromptModal = observer((props: SpecialProps) => { @@ -459,6 +461,64 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { /> ); } + case "create_category": { + const [name, setName] = useState(""); + const [cats, setCats] = useState( + props.target.categories ?? [], + ); + const history = useHistory(); + + return ( + } + actions={[ + { + confirmation: true, + contrast: true, + children: ( + + ), + onClick: async () => { + setProcessing(true); + try { + cats.push({ + id: ulid(), + title: name, + channels: [], + }); + props.target.edit({ categories: cats }); + onClose(); + setProcessing(false); + } catch (err) { + setError(takeError(err)); + setProcessing(false); + } + }, + }, + { + children: ( + + ), + onClick: onClose, + }, + ]} + content={ + <> + + + + setName(e.currentTarget.value)} + /> + + } + disabled={processing} + error={error} + /> + ); + } default: return null; } diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx index 7448be6e..70e0a6a7 100644 --- a/src/lib/ContextMenus.tsx +++ b/src/lib/ContextMenus.tsx @@ -102,6 +102,7 @@ type Action = | { action: "set_status" } | { action: "clear_status" } | { action: "create_channel"; target: Server } + | { action: "create_category"; target: Server } | { action: "create_invite"; target: Channel; @@ -400,6 +401,7 @@ function ContextMenus(props: Props) { case "delete_server": case "delete_message": case "create_channel": + case "create_category": case "create_invite": // Typescript flattens the case types into a single type and type structure and specifity is lost openScreen({ @@ -508,11 +510,16 @@ function ContextMenus(props: Props) { const server = client.servers.get(server_list)!; const permissions = server.permission; if (server) { - if (permissions & ServerPermission.ManageChannels) + if (permissions & ServerPermission.ManageChannels) { + generateAction({ + action: "create_category", + target: server, + }); generateAction({ action: "create_channel", target: server, }); + } if (permissions & ServerPermission.ManageServer) generateAction({ action: "open_server_settings", @@ -860,6 +867,15 @@ function ContextMenus(props: Props) { } if (sid && server) { + if (server.channels[0] !== undefined) + generateAction( + { + action: "create_invite", + target: server.channels[0], + }, + "create_invite", + ); + if ( serverPermissions & ServerPermission.ChangeNickname || From dccc0f4eb7d91883bd188a5e2caf5bb592bf145e Mon Sep 17 00:00:00 2001 From: Ryan Alexander <38785445+ryanalexander@users.noreply.github.com> Date: Wed, 18 Aug 2021 06:28:18 +1000 Subject: [PATCH 2/2] Update Prompt.tsx --- src/context/intermediate/modals/Prompt.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/context/intermediate/modals/Prompt.tsx b/src/context/intermediate/modals/Prompt.tsx index d58fa53c..f041f010 100644 --- a/src/context/intermediate/modals/Prompt.tsx +++ b/src/context/intermediate/modals/Prompt.tsx @@ -463,9 +463,6 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { } case "create_category": { const [name, setName] = useState(""); - const [cats, setCats] = useState( - props.target.categories ?? [], - ); const history = useHistory(); return ( @@ -482,12 +479,12 @@ export const SpecialPromptModal = observer((props: SpecialProps) => { onClick: async () => { setProcessing(true); try { - cats.push({ - id: ulid(), - title: name, - channels: [], + props.target.edit({ + categories: [ + ...props.target.categories ?? [], + { id: ulid(), title: name, channels: [] } + ] }); - props.target.edit({ categories: cats }); onClose(); setProcessing(false); } catch (err) {