import isEqual from "lodash.isequal"; import { Servers, Server } from "revolt.js/dist/api/objects"; import styles from "./Panes.module.scss"; import { Text } from "preact-i18n"; import { useContext, useEffect, useState } from "preact/hooks"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { FileUploader } from "../../../context/revoltjs/FileUploads"; import { AppContext } from "../../../context/revoltjs/RevoltClient"; import { getChannelName } from "../../../context/revoltjs/util"; import Button from "../../../components/ui/Button"; import ComboBox from "../../../components/ui/ComboBox"; import InputBox from "../../../components/ui/InputBox"; interface Props { server: Servers.Server; } export function Overview({ server }: Props) { const client = useContext(AppContext); 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() { const changes: Partial< Pick > = {}; if (name !== server.name) changes.name = name; 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); } return (
client.servers.edit(server._id, { icon }) } previewURL={client.servers.getIconURL( server._id, { max_side: 256 }, true, )} remove={() => client.servers.edit(server._id, { remove: "Icon" }) } />

{ setName(e.currentTarget.value); if (!changed) setChanged(true); }} />

{ setDescription(ev.currentTarget.value); if (!changed) setChanged(true); }} />

client.servers.edit(server._id, { banner }) } previewURL={client.servers.getBannerURL( server._id, { width: 1000 }, true, )} remove={() => client.servers.edit(server._id, { remove: "Banner" }) } />

{[ ["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 ( ); })}

))}

); }