diff --git a/i18n/strings/en.json b/i18n/strings/en.json index 94c8dcad..09d791e7 100644 --- a/i18n/strings/en.json +++ b/i18n/strings/en.json @@ -56,8 +56,10 @@ }, "modals": { "confirm_deletion": { + "header_role": "Delete role?", "header_message": "Delete message?", "header_server": "Delete server?", + "body_role": "Are you sure you want to delete <2>this role?", "body_message": "Are you sure you want to delete <2>this message?", "body_server": "Are you sure you want to delete <2>{{name}}?", "warning": "This cannot be undone." @@ -118,9 +120,15 @@ "title": "Roles", "name": "Name", "name_placeholder": "Set a role nameā€¦", + "options_header": "Options", + "options": { + "hoist": "Hoist role", + "hoist_body": "Display this role above others in the member list." + }, "rank": "Rank", "permissions": "Permissions", "colour": "Colour", + "delete": "Delete Role", "set_colour": "Set role colour", "open_colour_modal": "Enter colour manually", "errors": { @@ -224,6 +232,9 @@ } }, "misc": { + "generic_errors": { + "rateLimited_toast": "Slow down and try again in a minute." + }, "network_indicator": { "body": "Connection lost", "hide": "(hide)" diff --git a/src/Generic.tsx b/src/Generic.tsx index 3f389787..fe71bb8d 100644 --- a/src/Generic.tsx +++ b/src/Generic.tsx @@ -339,6 +339,11 @@ export const app = { `[FUNCTIONS] Tried to run uninitialised function handleServerSettingsVisibility (args: ${stateFunction})`, ); }, + closeRoleSubsection: () => { + console.log( + '[FUNCTIONS] Tried to run uninitialised function handleServerSettingsVisibility', + ); + }, }; export function setFunction(name: string, func: any) { diff --git a/src/components/common/settings/sections/server/RoleSettingsSection.tsx b/src/components/common/settings/sections/server/RoleSettingsSection.tsx index f5f74be9..4eafed2f 100644 --- a/src/components/common/settings/sections/server/RoleSettingsSection.tsx +++ b/src/components/common/settings/sections/server/RoleSettingsSection.tsx @@ -13,16 +13,18 @@ import ColourPicker, { import {Server} from 'revolt.js'; -import {app} from '@rvmob/Generic'; +import {app, setFunction} from '@rvmob/Generic'; import {SettingsSection} from '@rvmob/lib/types'; import {currentTheme, styles} from '@rvmob/Theme'; import {GapView} from '@rvmob/components/layout'; import { BackButton, Button, + Checkbox, InputWithButton, Text, } from '@rvmob/components/common/atoms'; +import {showToast} from '@rvmob/lib/utils'; export const RoleSettingsSection = observer( ({ @@ -43,6 +45,10 @@ export const RoleSettingsSection = observer( setColour(hex); }; + setFunction('closeRoleSubsection', () => { + setSection({section: 'roles', subsection: undefined}); + }); + return ( <> { - server.editRole(section!.subsection!, { + onPress={async (v: string) => { + await server.editRole(section!.subsection!, { name: v, }); }} @@ -109,6 +115,40 @@ export const RoleSettingsSection = observer( /> */} {server.roles![section!.subsection].rank} + + {t('app.servers.settings.roles.options_header')} + + + + + {t('app.servers.settings.roles.options.hoist')} + + + {t('app.servers.settings.roles.options.hoist_body')} + + + { + try { + await server.editRole(section!.subsection!, { + hoist: !server.roles![section!.subsection!].hoist, + }); + } catch (error) { + `${error}`.match('429') + ? showToast( + t('app.misc.generic_errors.rateLimited_toast'), + ) + : null; + } + }} + /> + + {t('app.servers.settings.roles.permissions')} @@ -182,6 +222,18 @@ export const RoleSettingsSection = observer( + + { switch (target.type) { + case 'Role': + app.closeRoleSubsection(); + target.object.server.deleteRole(target.object.role); + app.openDeletionConfirmationModal(null); + break; case 'Server': app.openServerContextMenu(null); app.openServer(undefined); diff --git a/src/lib/types.ts b/src/lib/types.ts index ce8af4b2..718580cf 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -33,6 +33,14 @@ export type ReplyingMessage = { message: Message; }; +interface TypedRole { + type: 'Role'; + object: { + role: string; // role ID + server: Server; + }; +} + interface TypedMessage { type: 'Message'; object: Message; @@ -50,7 +58,7 @@ interface TypedUser { export type ReportedObject = TypedMessage | TypedServer | TypedUser; -export type DeletableObject = TypedMessage | TypedServer; +export type DeletableObject = TypedRole | TypedMessage | TypedServer; export type TextEditingModalProps = { initialString: string;