From 3191d15cd004fc9b9a1addc41e5280b5ad3449f7 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 4 Jul 2021 19:49:58 +0100 Subject: [PATCH] Add a way to edit system message channels. --- external/lang | 2 +- src/pages/settings/server/Members.tsx | 3 +- src/pages/settings/server/Overview.tsx | 50 +++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/external/lang b/external/lang index 66e45632..7ed91d39 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit 66e4563231bcfab8f8b7cf3fa0f5b86797719b7b +Subproject commit 7ed91d39ac72edc9d70c8e531caf50172bd79ff6 diff --git a/src/pages/settings/server/Members.tsx b/src/pages/settings/server/Members.tsx index e7d30a6f..8f0c1710 100644 --- a/src/pages/settings/server/Members.tsx +++ b/src/pages/settings/server/Members.tsx @@ -1,7 +1,6 @@ import styles from './Panes.module.scss'; import { useEffect, useState } from "preact/hooks"; import { Servers } from "revolt.js/dist/api/objects"; -import UserIcon from "../../../components/common/user/UserIcon"; import { useForceUpdate, useUsers } from "../../../context/revoltjs/hooks"; interface Props { @@ -23,7 +22,7 @@ export function Members({ server }: Props) { return (
- X Members + { members?.length ?? 0 } Members
{ members && members.length > 0 && users?.map(x => x &&
diff --git a/src/pages/settings/server/Overview.tsx b/src/pages/settings/server/Overview.tsx index fe530276..19c8fed3 100644 --- a/src/pages/settings/server/Overview.tsx +++ b/src/pages/settings/server/Overview.tsx @@ -1,10 +1,13 @@ import { Text } from "preact-i18n"; +import isEqual from "lodash.isequal"; import styles from './Panes.module.scss'; import Button from "../../../components/ui/Button"; -import { Servers } from "revolt.js/dist/api/objects"; import InputBox from "../../../components/ui/InputBox"; +import ComboBox from "../../../components/ui/ComboBox"; +import { Servers, Server } from "revolt.js/dist/api/objects"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { useContext, useEffect, useState } from "preact/hooks"; +import { getChannelName } from "../../../context/revoltjs/util"; import { AppContext } from "../../../context/revoltjs/RevoltClient"; import { FileUploader } from "../../../context/revoltjs/FileUploads"; @@ -17,16 +20,18 @@ export function Overview({ server }: Props) { const [name, setName] = useState(server.name); const [description, setDescription] = useState(server.description ?? ''); + const [systemMessages, setSystemMessages] = useState(server.system_messages); useEffect(() => setName(server.name), [ server.name ]); useEffect(() => setDescription(server.description ?? ''), [ server.description ]); + useEffect(() => setSystemMessages(server.system_messages), [ server.system_messages ]); const [ changed, setChanged ] = useState(false); function save() { - let changes: any = {}; + let changes: Partial> = {}; if (name !== server.name) changes.name = name; - if (description !== server.description) - changes.description = description; + if (description !== server.description) changes.description = description; + if (!isEqual(systemMessages, server.system_messages)) changes.system_messages = systemMessages; client.servers.edit(server._id, changes); setChanged(false); @@ -76,6 +81,43 @@ export function Overview({ server }: Props) { if (!changed) setChanged(true) }} /> + +

+ +

+ {[ + [ 'User Joined', 'user_joined' ], + [ 'User Left', 'user_left' ], + [ 'User Kicked', 'user_kicked' ], + [ 'User Banned', 'user_banned' ] + ].map(([ i18n, key ]) => + // ! FIXME: temporary code just so we can expose the options +

+ {i18n} + { + if (!changed) setChanged(true) + const v = e.currentTarget.value; + if (v === 'disabled') { + const { [key as keyof typeof systemMessages]: _, ...other } = systemMessages; + setSystemMessages(other); + } else { + setSystemMessages({ + ...systemMessages, + [key]: v + }); + } + }}> + + { server.channels.map(id => { + const channel = client.channels.get(id); + if (!channel) return null; + return ; + }) } + +

+ )} +