Merge pull request #179 from Snazzah/server-identity-revamp

This commit is contained in:
Paul Makles 2021-09-09 21:03:43 +01:00 committed by GitHub
commit da7a27f325
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 41 deletions

View file

@ -0,0 +1,17 @@
.identityMain {
display: flex;
flex-direction: row;
gap: 10px;
> div {
display: flex;
flex-direction: column;
gap: 10px;
}
.buttons {
display: flex;
flex-direction: row;
gap: 10px;
}
}

View file

@ -1,13 +1,14 @@
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { Server } from "revolt.js/dist/maps/Servers"; import { Server } from "revolt.js/dist/maps/Servers";
import styles from "./ServerIdentityModal.module.scss";
import { Text } from "preact-i18n";
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import Button from "../../../components/ui/Button"; import Button from "../../../components/ui/Button";
import InputBox from "../../../components/ui/InputBox"; import InputBox from "../../../components/ui/InputBox";
import Modal from "../../../components/ui/Modal"; import Modal from "../../../components/ui/Modal";
import Overline from "../../../components/ui/Overline"; import Overline from "../../../components/ui/Overline";
import Tip from "../../../components/ui/Tip";
import { FileUploader } from "../../revoltjs/FileUploads"; import { FileUploader } from "../../revoltjs/FileUploads";
import { useClient } from "../../revoltjs/RevoltClient"; import { useClient } from "../../revoltjs/RevoltClient";
@ -27,49 +28,75 @@ export const ServerIdentityModal = observer(({ server, onClose }: Props) => {
if (!member) return null; if (!member) return null;
const [nickname, setNickname] = useState(""); const [nickname, setNickname] = useState("");
useEffect(() => setNickname(member.nickname ?? ""), [member.nickname]); const [currentNickname, setCurrentNickname] = useState("");
useEffect(() => {
setNickname(member.nickname ?? "");
setCurrentNickname(member.nickname ?? "");
}, [member.nickname]);
return ( return (
<Modal visible={true} onClose={onClose}> <Modal
<Tip warning hideSeparator> visible={true}
This section is under construction. title={
</Tip> <Text
<Overline type="subtle">Nickname</Overline> id={"app.special.popovers.server_identity.title"}
<p> fields={{ server: server.name }}
<InputBox
value={nickname}
onChange={(e) => setNickname(e.currentTarget.value)}
/> />
</p> }
<p> onClose={onClose}>
<Button onClick={() => member.edit({ nickname })}>Save</Button> <div className={styles.identityMain}>
</p> <div>
<p> <Overline type="subtle">
<Button onClick={() => member.edit({ remove: "Nickname" })}> <Text id="app.special.popovers.server_identity.avatar" />
Remove </Overline>
</Button> <FileUploader
</p> width={80}
<Overline type="subtle">Avatar</Overline> height={80}
<FileUploader style="icon"
width={80} fileType="avatars"
height={80} behaviour="upload"
style="icon" maxFileSize={4_000_000}
fileType="avatars" onUpload={(avatar) => member.edit({ avatar })}
behaviour="upload" remove={() => member.edit({ remove: "Avatar" })}
maxFileSize={4_000_000} defaultPreview={client.generateFileURL(
onUpload={(avatar) => member.edit({ avatar })} member.avatar ?? undefined,
remove={() => member.edit({ remove: "Avatar" })} { max_side: 256 },
defaultPreview={client.generateFileURL( true,
member.avatar ?? undefined, )}
{ max_side: 256 }, previewURL={client.generateFileURL(
true, member.avatar ?? undefined,
)} { max_side: 256 },
previewURL={client.generateFileURL( true,
member.avatar ?? undefined, )}
{ max_side: 256 }, />
true, </div>
)} <div>
/> <Overline type="subtle">
<Text id="app.special.popovers.server_identity.nickname" />
</Overline>
<InputBox
value={nickname}
placeholder={client.user!.username}
onChange={(e) => setNickname(e.currentTarget.value)}
/>
<div className={styles.buttons}>
<Button
disabled={nickname === currentNickname}
onClick={() => member.edit({ nickname })}>
<Text id="app.special.modals.actions.save" />
</Button>
{currentNickname !== "" && (
<Button
plain
onClick={() =>
member.edit({ remove: "Nickname" })
}>
<Text id="app.special.modals.actions.remove" />
</Button>
)}
</div>
</div>
</div>
</Modal> </Modal>
); );
}); });