From 8ac7403522ca588520f8a06fb5f291a7e2ac05fd Mon Sep 17 00:00:00 2001 From: RigidStudios Date: Thu, 23 Sep 2021 23:08:28 +0400 Subject: [PATCH] Prettier, Fix no role refresh --- src/pages/settings/server/Roles.tsx | 44 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/pages/settings/server/Roles.tsx b/src/pages/settings/server/Roles.tsx index a66c4041..4a8523d9 100644 --- a/src/pages/settings/server/Roles.tsx +++ b/src/pages/settings/server/Roles.tsx @@ -6,9 +6,16 @@ import { Server } from "revolt.js/dist/maps/Servers"; import styles from "./Panes.module.scss"; import { Text } from "preact-i18n"; -import {useCallback, useContext, useEffect, useMemo, useState} from "preact/hooks"; +import { + useCallback, + useContext, + useEffect, + useMemo, + useState, +} from "preact/hooks"; import { useIntermediate } from "../../../context/intermediate/Intermediate"; +import { AppContext } from "../../../context/revoltjs/RevoltClient"; import Button from "../../../components/ui/Button"; import Checkbox from "../../../components/ui/Checkbox"; @@ -17,7 +24,6 @@ import InputBox from "../../../components/ui/InputBox"; import Overline from "../../../components/ui/Overline"; import ButtonItem from "../../../components/navigation/items/ButtonItem"; -import {AppContext} from "../../../context/revoltjs/RevoltClient"; interface Props { server: Server; @@ -30,7 +36,7 @@ export const Roles = observer(({ server }: Props) => { const client = useContext(AppContext); const [role, setRole] = useState("default"); const { openScreen } = useIntermediate(); - const roles = useMemo(() => server.roles ?? {}, [server]); + const roles = server.roles || {}; if (role !== "default" && typeof roles[role] === "undefined") { useEffect(() => setRole("default"), [role]); @@ -123,26 +129,25 @@ export const Roles = observer(({ server }: Props) => { } /> - {["default", ...Object.keys(roles)].map((id) => { - if (id === "default") { - return ( - setRole("default")}> - - - ); - } - return ( + {["default", ...Object.keys(roles)].map((id) => + id === "default" ? ( + setRole("default")}> + + + ) : ( setRole(id)} - style={{ color: roles[id].colour }}> + style={{ + color: roles[id].colour, + }}> {roles[id].name} - ); - })} + ), + )}
@@ -238,7 +243,10 @@ export const Roles = observer(({ server }: Props) => { onChange={() => setPerm([perm[0], perm[1] ^ value]) } - disabled={key === "View" || (!(clientPermissions & value))} + disabled={ + key === "View" || + !(clientPermissions & value) + } description={ }>