import { observer } from "mobx-react-lite"; import { Channel } from "revolt.js"; import styled from "styled-components/macro"; import { Text } from "preact-i18n"; import { useEffect, useState } from "preact/hooks"; import { Button, Checkbox, InputBox } from "@revoltchat/ui"; import TextAreaAutoSize from "../../../lib/TextAreaAutoSize"; import { FileUploader } from "../../../context/revoltjs/FileUploads"; interface Props { channel: Channel; } const Row = styled.div` gap: 20px; display: flex; .name { flex-grow: 1; input { width: 100%; } } `; export default observer(({ channel }: Props) => { const [name, setName] = useState(channel.name ?? undefined); const [description, setDescription] = useState(channel.description ?? ""); const [nsfw, setNSFW] = useState(channel.nsfw ?? false); useEffect(() => setName(channel.name ?? undefined), [channel.name]); useEffect( () => setDescription(channel.description ?? ""), [channel.description], ); useEffect(() => setNSFW(channel.nsfw ?? false), [channel.nsfw]); const [changed, setChanged] = useState(false); function save() { const changes: Record = {}; if (name !== channel.name) changes.name = name; if (description !== channel.description) changes.description = description; if (nsfw !== channel.nsfw) changes.nsfw = nsfw; channel.edit(changes); setChanged(false); } return (
channel.edit({ icon })} previewURL={channel.generateIconURL( { max_side: 256 }, true, )} remove={() => channel.edit({ remove: ["Icon"] })} defaultPreview={ channel.channel_type === "Group" ? "/assets/group.png" : undefined } />

{channel.channel_type === "Group" ? ( ) : ( )}

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

{channel.channel_type === "Group" ? ( ) : ( )}

{ setDescription(ev.currentTarget.value); if (!changed) setChanged(true); }} />
{channel.channel_type === "VoiceChannel" ? ( "" ) : ( { setNSFW(nsfwchange); if (!changed) setChanged(true); }} title="NSFW" description="Set this channel to NSFW." /> )}

); });