-
+
- I32ToU32(
+ function getPermissions(id: string) {
+ return I32ToU32(
id === "default"
? server.default_permissions
: roles[id].permissions,
);
- const [perm, setPerm] = useState(v(role));
- useEffect(() => setPerm(v(role)), [role, roles[role]?.permissions]);
+ }
+
+ const { name: roleName, colour: roleColour } = roles[role] ?? {};
+
+ const [perm, setPerm] = useState(getPermissions(role));
+ const [name, setName] = useState(roleName);
+ const [colour, setColour] = useState(roleColour);
+
+ useEffect(
+ () => setPerm(getPermissions(role)),
+ [role, roles[role]?.permissions],
+ );
+
+ useEffect(() => setName(roleName), [role, roleName]);
+ useEffect(() => setColour(roleColour), [role, roleColour]);
+
+ const modified =
+ !isEqual(perm, getPermissions(role)) ||
+ !isEqual(name, roleName) ||
+ !isEqual(colour, roleColour);
+
+ const save = () => {
+ if (!isEqual(perm, getPermissions(role))) {
+ client.servers.setPermissions(server._id, role, {
+ server: perm[0],
+ channel: perm[1],
+ });
+ }
+
+ if (!isEqual(name, roleName) || !isEqual(colour, roleColour)) {
+ client.servers.editRole(server._id, role, { name, colour });
+ }
+ };
- const modified = !isEqual(perm, v(role));
- const save = () =>
- client.servers.setPermissions(server._id, role, {
- server: perm[0],
- channel: perm[1],
- });
const deleteRole = () => {
setRole("default");
client.servers.deleteRole(server._id, role);
@@ -92,7 +118,8 @@ export function Roles({ server }: Props) {
return (
setRole(id)}>
+ onClick={() => setRole(id)}
+ style={{ color: roles[id].colour }}>
{roles[id].name}
);
@@ -111,6 +138,31 @@ export function Roles({ server }: Props) {
Save
+ {role !== "default" && (
+ <>
+
+ Role Name
+
+
+ setName(e.currentTarget.value)
+ }
+ contrast
+ />
+
+
+
+ Role Colour
+
+ setColour(value)}
+ />
+
+
+ >
+ )}
diff --git a/yarn.lock b/yarn.lock
index 29260891..05ad5dbf 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3563,10 +3563,10 @@ reusify@^1.0.4:
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
-revolt.js@4.3.3-alpha.14:
- version "4.3.3-alpha.14"
- resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.14.tgz#f4912ee25725de6e43ba1d4fd8ab84c711678271"
- integrity sha512-4p3DhEu+GUKZxczCPXR2JM04fzGlFfZdwHYjgkgU48NgPXgzxQrSv4x0FjpyIIv3xNpuO59z35mYRMLxAnBXsQ==
+revolt.js@4.3.3-alpha.15:
+ version "4.3.3-alpha.15"
+ resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.15.tgz#e511ad500a20f658b15b7bad0fdb9e2a5465d1b1"
+ integrity sha512-24hIQEO+FIRIAQXITBH2qVvWH6LA1MeJW2/3lj6cqBgJz7lnb3ZNIXZBu5sHbUEJpIDtJiHcOEeaeh3sE2RwxA==
dependencies:
"@insertish/mutable" "1.1.0"
axios "^0.19.2"