From c724ffae4363e038a37aab544f64142e1948162c Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 30 Jun 2021 21:28:56 +0100 Subject: [PATCH] View roles in server settings. --- src/pages/settings/ServerSettings.tsx | 9 ++++- src/pages/settings/server/Roles.tsx | 54 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/pages/settings/server/Roles.tsx diff --git a/src/pages/settings/ServerSettings.tsx b/src/pages/settings/ServerSettings.tsx index ca894005..5d34d01d 100644 --- a/src/pages/settings/ServerSettings.tsx +++ b/src/pages/settings/ServerSettings.tsx @@ -3,7 +3,7 @@ import Category from "../../components/ui/Category"; import { GenericSettings } from "./GenericSettings"; import { useServer } from "../../context/revoltjs/hooks"; import { Route, useHistory, useParams } from "react-router-dom"; -import { ListUl, Share, Group } from "@styled-icons/boxicons-regular"; +import { ListUl, Share, Group, ListCheck } from "@styled-icons/boxicons-regular"; import { XSquare } from "@styled-icons/boxicons-solid"; import RequiresOnline from "../../context/revoltjs/RequiresOnline"; @@ -11,6 +11,7 @@ import { Overview } from "./server/Overview"; import { Members } from "./server/Members"; import { Invites } from "./server/Invites"; import { Bans } from "./server/Bans"; +import { Roles } from "./server/Roles"; export default function ServerSettings() { const { server: sid } = useParams<{ server: string; }>(); @@ -49,12 +50,18 @@ export default function ServerSettings() { id: 'bans', icon: , title: "Bans" + }, + { + id: 'roles', + icon: , + title: "Roles" } ]} children={[ , , , + , ]} category="server_pages" diff --git a/src/pages/settings/server/Roles.tsx b/src/pages/settings/server/Roles.tsx new file mode 100644 index 00000000..308c6e66 --- /dev/null +++ b/src/pages/settings/server/Roles.tsx @@ -0,0 +1,54 @@ +import { useEffect, useState } from "preact/hooks"; +import Button from "../../../components/ui/Button"; +import { Servers } from "revolt.js/dist/api/objects"; +import Checkbox from "../../../components/ui/Checkbox"; +import { ServerPermission } from "revolt.js/dist/api/permissions"; + +interface Props { + server: Servers.Server; +} + +export function Roles({ server }: Props) { + const [ selected, setSelected ] = useState('default'); + + const roles = server.roles ?? {}; + const keys = [ 'default', ...Object.keys(roles) ]; + + const defaultRole = { name: 'Default', permissions: server.default_permissions }; + const selectedRole: Servers.Role = selected === 'default' ? defaultRole : roles[selected]; + + if (!selectedRole) { + useEffect(() => setSelected('default'), [ ]); + return null; + } + + return ( +
+

select role

+ { keys + .map(id => { + let role: Servers.Role = id === 'default' ? defaultRole : roles[id]; + + return ( + selected && setSelected(id)}> + { role.name } + + ) + }) + } + +

permmissions

+ { Object.keys(ServerPermission) + .map(perm => { + let value = ServerPermission[perm as keyof typeof ServerPermission]; + + return ( + 0} onChange={() => {}}> + { perm } + + ) + }) + } +
+ ); +}