2021-07-29 13:41:01 -04:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-07-30 15:24:53 -04:00
|
|
|
import { Channel } from "revolt.js/dist/maps/Channels";
|
2021-07-10 10:57:29 -04:00
|
|
|
import styled, { css } from "styled-components";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import { Text } from "preact-i18n";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
2021-07-10 10:57:29 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import InputBox from "../../../components/ui/InputBox";
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
interface Props {
|
2021-07-29 13:41:01 -04:00
|
|
|
channel: Channel;
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
|
|
|
|
2021-07-09 17:08:00 -04:00
|
|
|
const Row = styled.div`
|
|
|
|
gap: 20px;
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.name {
|
|
|
|
flex-grow: 1;
|
|
|
|
|
|
|
|
input {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
export default observer(({ channel }: Props) => {
|
2021-07-05 06:25:20 -04:00
|
|
|
const client = useContext(AppContext);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
const [name, setName] = useState(channel.name ?? undefined);
|
2021-07-05 06:25:20 -04:00
|
|
|
const [description, setDescription] = useState(channel.description ?? "");
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-29 13:41:01 -04:00
|
|
|
useEffect(() => setName(channel.name ?? undefined), [channel.name]);
|
2021-07-05 06:25:20 -04:00
|
|
|
useEffect(
|
|
|
|
() => setDescription(channel.description ?? ""),
|
|
|
|
[channel.description],
|
|
|
|
);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const [changed, setChanged] = useState(false);
|
|
|
|
function save() {
|
2021-07-10 10:57:29 -04:00
|
|
|
const changes: any = {};
|
2021-07-05 06:25:20 -04:00
|
|
|
if (name !== channel.name) changes.name = name;
|
|
|
|
if (description !== channel.description)
|
|
|
|
changes.description = description;
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-30 15:24:53 -04:00
|
|
|
channel.edit(changes);
|
2021-07-05 06:25:20 -04:00
|
|
|
setChanged(false);
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
2021-07-09 17:09:59 -04:00
|
|
|
<div className="overview">
|
2021-07-09 17:08:00 -04:00
|
|
|
<Row>
|
2021-07-05 06:25:20 -04:00
|
|
|
<FileUploader
|
|
|
|
width={80}
|
|
|
|
height={80}
|
|
|
|
style="icon"
|
|
|
|
fileType="icons"
|
|
|
|
behaviour="upload"
|
|
|
|
maxFileSize={2_500_000}
|
2021-07-30 15:24:53 -04:00
|
|
|
onUpload={(icon) => channel.edit({ icon })}
|
|
|
|
previewURL={channel.generateIconURL(
|
2021-07-05 06:25:20 -04:00
|
|
|
{ max_side: 256 },
|
|
|
|
true,
|
|
|
|
)}
|
2021-07-30 15:24:53 -04:00
|
|
|
remove={() => channel.edit({ remove: "Icon" })}
|
2021-07-05 06:25:20 -04:00
|
|
|
defaultPreview={
|
|
|
|
channel.channel_type === "Group"
|
|
|
|
? "/assets/group.png"
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
/>
|
2021-07-09 17:09:59 -04:00
|
|
|
<div className="name">
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
{channel.channel_type === "Group" ? (
|
|
|
|
<Text id="app.main.groups.name" />
|
|
|
|
) : (
|
|
|
|
<Text id="app.main.servers.channel_name" />
|
|
|
|
)}
|
|
|
|
</h3>
|
|
|
|
<InputBox
|
|
|
|
contrast
|
|
|
|
value={name}
|
|
|
|
maxLength={32}
|
|
|
|
onChange={(e) => {
|
|
|
|
setName(e.currentTarget.value);
|
|
|
|
if (!changed) setChanged(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-07-09 17:08:00 -04:00
|
|
|
</Row>
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
<h3>
|
|
|
|
{channel.channel_type === "Group" ? (
|
|
|
|
<Text id="app.main.groups.description" />
|
|
|
|
) : (
|
|
|
|
<Text id="app.main.servers.channel_description" />
|
|
|
|
)}
|
|
|
|
</h3>
|
|
|
|
<TextAreaAutoSize
|
|
|
|
maxRows={10}
|
|
|
|
minHeight={60}
|
|
|
|
maxLength={1024}
|
|
|
|
value={description}
|
|
|
|
placeholder={"Add a description..."}
|
|
|
|
onChange={(ev) => {
|
|
|
|
setDescription(ev.currentTarget.value);
|
|
|
|
if (!changed) setChanged(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<p>
|
|
|
|
<Button onClick={save} contrast disabled={!changed}>
|
|
|
|
<Text id="app.special.modals.actions.save" />
|
|
|
|
</Button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
2021-07-29 13:41:01 -04:00
|
|
|
});
|