mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-24 06:32:08 -05:00
View roles in server settings.
This commit is contained in:
parent
f6daa54411
commit
c724ffae43
2 changed files with 62 additions and 1 deletions
|
@ -3,7 +3,7 @@ import Category from "../../components/ui/Category";
|
||||||
import { GenericSettings } from "./GenericSettings";
|
import { GenericSettings } from "./GenericSettings";
|
||||||
import { useServer } from "../../context/revoltjs/hooks";
|
import { useServer } from "../../context/revoltjs/hooks";
|
||||||
import { Route, useHistory, useParams } from "react-router-dom";
|
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 { XSquare } from "@styled-icons/boxicons-solid";
|
||||||
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
|
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import { Overview } from "./server/Overview";
|
||||||
import { Members } from "./server/Members";
|
import { Members } from "./server/Members";
|
||||||
import { Invites } from "./server/Invites";
|
import { Invites } from "./server/Invites";
|
||||||
import { Bans } from "./server/Bans";
|
import { Bans } from "./server/Bans";
|
||||||
|
import { Roles } from "./server/Roles";
|
||||||
|
|
||||||
export default function ServerSettings() {
|
export default function ServerSettings() {
|
||||||
const { server: sid } = useParams<{ server: string; }>();
|
const { server: sid } = useParams<{ server: string; }>();
|
||||||
|
@ -49,12 +50,18 @@ export default function ServerSettings() {
|
||||||
id: 'bans',
|
id: 'bans',
|
||||||
icon: <XSquare size={20} />,
|
icon: <XSquare size={20} />,
|
||||||
title: "Bans"
|
title: "Bans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'roles',
|
||||||
|
icon: <ListCheck size={20} />,
|
||||||
|
title: "Roles"
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
children={[
|
children={[
|
||||||
<Route path="/server/:server/settings/members"><RequiresOnline><Members server={server} /></RequiresOnline></Route>,
|
<Route path="/server/:server/settings/members"><RequiresOnline><Members server={server} /></RequiresOnline></Route>,
|
||||||
<Route path="/server/:server/settings/invites"><RequiresOnline><Invites server={server} /></RequiresOnline></Route>,
|
<Route path="/server/:server/settings/invites"><RequiresOnline><Invites server={server} /></RequiresOnline></Route>,
|
||||||
<Route path="/server/:server/settings/bans"><RequiresOnline><Bans server={server} /></RequiresOnline></Route>,
|
<Route path="/server/:server/settings/bans"><RequiresOnline><Bans server={server} /></RequiresOnline></Route>,
|
||||||
|
<Route path="/server/:server/settings/roles"><RequiresOnline><Roles server={server} /></RequiresOnline></Route>,
|
||||||
<Route path="/"><Overview server={server} /></Route>
|
<Route path="/"><Overview server={server} /></Route>
|
||||||
]}
|
]}
|
||||||
category="server_pages"
|
category="server_pages"
|
||||||
|
|
54
src/pages/settings/server/Roles.tsx
Normal file
54
src/pages/settings/server/Roles.tsx
Normal file
|
@ -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 (
|
||||||
|
<div>
|
||||||
|
<h2>select role</h2>
|
||||||
|
{ keys
|
||||||
|
.map(id => {
|
||||||
|
let role: Servers.Role = id === 'default' ? defaultRole : roles[id];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Checkbox checked={selected === id} onChange={selected => selected && setSelected(id)}>
|
||||||
|
{ role.name }
|
||||||
|
</Checkbox>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
<Button disabled={selected === 'default'} error onClick={() => {}}>delete role</Button>
|
||||||
|
<h2>permmissions</h2>
|
||||||
|
{ Object.keys(ServerPermission)
|
||||||
|
.map(perm => {
|
||||||
|
let value = ServerPermission[perm as keyof typeof ServerPermission];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Checkbox checked={(selectedRole.permissions[0] & value) > 0} onChange={() => {}}>
|
||||||
|
{ perm }
|
||||||
|
</Checkbox>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue