2021-06-19 17:37:12 -04:00
|
|
|
import { Text } from "preact-i18n";
|
2021-07-04 14:49:58 -04:00
|
|
|
import isEqual from "lodash.isequal";
|
2021-06-19 17:37:12 -04:00
|
|
|
import styles from './Panes.module.scss';
|
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import InputBox from "../../../components/ui/InputBox";
|
2021-07-04 14:49:58 -04:00
|
|
|
import ComboBox from "../../../components/ui/ComboBox";
|
|
|
|
import { Servers, Server } from "revolt.js/dist/api/objects";
|
2021-06-21 16:11:53 -04:00
|
|
|
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2021-07-04 14:49:58 -04:00
|
|
|
import { getChannelName } from "../../../context/revoltjs/util";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
|
|
|
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
|
|
|
|
|
|
|
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 ?? '');
|
2021-07-04 14:49:58 -04:00
|
|
|
const [systemMessages, setSystemMessages] = useState(server.system_messages);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
useEffect(() => setName(server.name), [ server.name ]);
|
|
|
|
useEffect(() => setDescription(server.description ?? ''), [ server.description ]);
|
2021-07-04 14:49:58 -04:00
|
|
|
useEffect(() => setSystemMessages(server.system_messages), [ server.system_messages ]);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
const [ changed, setChanged ] = useState(false);
|
|
|
|
function save() {
|
2021-07-04 14:49:58 -04:00
|
|
|
let changes: Partial<Pick<Servers.Server, 'name' | 'description' | 'system_messages'>> = {};
|
2021-06-19 17:37:12 -04:00
|
|
|
if (name !== server.name) changes.name = name;
|
2021-07-04 14:49:58 -04:00
|
|
|
if (description !== server.description) changes.description = description;
|
|
|
|
if (!isEqual(systemMessages, server.system_messages)) changes.system_messages = systemMessages;
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
client.servers.edit(server._id, changes);
|
|
|
|
setChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.overview}>
|
|
|
|
<div className={styles.row}>
|
|
|
|
<FileUploader
|
|
|
|
width={80}
|
|
|
|
height={80}
|
|
|
|
style="icon"
|
|
|
|
fileType="icons"
|
|
|
|
behaviour="upload"
|
|
|
|
maxFileSize={2_500_000}
|
|
|
|
onUpload={icon => client.servers.edit(server._id, { icon })}
|
|
|
|
previewURL={client.servers.getIconURL(server._id, { max_side: 256 }, true)}
|
|
|
|
remove={() => client.servers.edit(server._id, { remove: 'Icon' })}
|
|
|
|
/>
|
|
|
|
<div className={styles.name}>
|
|
|
|
<h3>
|
|
|
|
<Text id="app.main.servers.name" />
|
|
|
|
</h3>
|
|
|
|
<InputBox
|
|
|
|
contrast
|
|
|
|
value={name}
|
|
|
|
maxLength={32}
|
|
|
|
onChange={e => {
|
|
|
|
setName(e.currentTarget.value)
|
|
|
|
if (!changed) setChanged(true)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<h3>
|
|
|
|
<Text id="app.main.servers.description" />
|
|
|
|
</h3>
|
2021-06-21 16:11:53 -04:00
|
|
|
<TextAreaAutoSize
|
|
|
|
maxRows={10}
|
|
|
|
minHeight={60}
|
2021-06-19 17:37:12 -04:00
|
|
|
maxLength={1024}
|
|
|
|
value={description}
|
|
|
|
placeholder={"Add a topic..."}
|
2021-06-20 15:30:42 -04:00
|
|
|
onChange={ev => {
|
|
|
|
setDescription(ev.currentTarget.value);
|
2021-06-19 17:37:12 -04:00
|
|
|
if (!changed) setChanged(true)
|
|
|
|
}}
|
|
|
|
/>
|
2021-07-04 14:49:58 -04:00
|
|
|
|
2021-07-04 15:33:05 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.main.servers.custom_banner" />
|
|
|
|
</h3>
|
|
|
|
<FileUploader
|
|
|
|
height={160}
|
|
|
|
style="banner"
|
|
|
|
fileType="banners"
|
|
|
|
behaviour="upload"
|
|
|
|
maxFileSize={6_000_000}
|
|
|
|
onUpload={banner => client.servers.edit(server._id, { banner })}
|
|
|
|
previewURL={client.servers.getBannerURL(server._id, { width: 1000 }, true)}
|
|
|
|
remove={() => client.servers.edit(server._id, { remove: 'Banner' })}
|
|
|
|
/>
|
|
|
|
|
2021-07-04 14:49:58 -04:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.server_pages.overview.system_messages" />
|
|
|
|
</h3>
|
|
|
|
{[
|
|
|
|
[ '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
|
|
|
|
<p style={{ display: 'flex', gap: '8px', alignItems: 'center' }}>
|
2021-07-04 15:33:05 -04:00
|
|
|
<span style={{ flexShrink: '0', flex: `25%` }}>{i18n}</span>
|
2021-07-04 14:49:58 -04:00
|
|
|
<ComboBox value={systemMessages?.[key as keyof typeof systemMessages] ?? 'disabled'}
|
|
|
|
onChange={e => {
|
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<option value='disabled'><Text id="general.disabled" /></option>
|
|
|
|
{ server.channels.map(id => {
|
|
|
|
const channel = client.channels.get(id);
|
|
|
|
if (!channel) return null;
|
|
|
|
return <option value={id}>{ getChannelName(client, channel, true) }</option>;
|
|
|
|
}) }
|
|
|
|
</ComboBox>
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
|
2021-07-01 12:36:34 -04:00
|
|
|
<p>
|
|
|
|
<Button onClick={save} contrast disabled={!changed}>
|
|
|
|
<Text id="app.special.modals.actions.save" />
|
|
|
|
</Button>
|
|
|
|
</p>
|
2021-06-19 17:37:12 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|