Skip to content

Commit

Permalink
feat: more role settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed Jul 15, 2024
1 parent 7ce07c1 commit f654950
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
11 changes: 11 additions & 0 deletions i18n/strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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</2>?",
"body_message": "Are you sure you want to delete <2>this message</2>?",
"body_server": "Are you sure you want to delete <2>{{name}}</2>?",
"warning": "This cannot be undone."
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -224,6 +232,9 @@
}
},
"misc": {
"generic_errors": {
"rateLimited_toast": "Slow down and try again in a minute."
},
"network_indicator": {
"body": "Connection lost",
"hide": "(hide)"
Expand Down
5 changes: 5 additions & 0 deletions src/Generic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
({
Expand All @@ -43,6 +45,10 @@ export const RoleSettingsSection = observer(
setColour(hex);
};

setFunction('closeRoleSubsection', () => {
setSection({section: 'roles', subsection: undefined});
});

return (
<>
<BackButton
Expand Down Expand Up @@ -71,8 +77,8 @@ export const RoleSettingsSection = observer(
<InputWithButton
placeholder={t('app.servers.settings.roles.name_placeholder')}
defaultValue={server.roles![section!.subsection].name}
onPress={(v: string) => {
server.editRole(section!.subsection!, {
onPress={async (v: string) => {
await server.editRole(section!.subsection!, {
name: v,
});
}}
Expand Down Expand Up @@ -109,6 +115,40 @@ export const RoleSettingsSection = observer(
/> */}
<Text>{server.roles![section!.subsection].rank}</Text>
<GapView size={2} />
<Text type={'h2'}>
{t('app.servers.settings.roles.options_header')}
</Text>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<View style={{flex: 1, flexDirection: 'column'}}>
<Text style={{fontWeight: 'bold'}}>
{t('app.servers.settings.roles.options.hoist')}
</Text>
<Text colour={currentTheme.foregroundSecondary}>
{t('app.servers.settings.roles.options.hoist_body')}
</Text>
</View>
<Checkbox
value={server.roles![section!.subsection].hoist ?? false}
callback={async () => {
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;
}
}}
/>
</View>
<GapView size={2} />
<Text type={'h2'}>
{t('app.servers.settings.roles.permissions')}
</Text>
Expand Down Expand Up @@ -182,6 +222,18 @@ export const RoleSettingsSection = observer(
</Pressable>
</View>
</View>
<GapView size={8} />
<Button
style={{marginHorizontal: 0}}
backgroundColor={currentTheme.error}
onPress={() => {
app.openDeletionConfirmationModal({
type: 'Role',
object: {role: section!.subsection!, server},
});
}}>
<Text>{t('app.servers.settings.roles.delete')}</Text>
</Button>
<Modal visible={showColourPicker} animationType="slide">
<View
style={{
Expand Down
5 changes: 5 additions & 0 deletions src/components/modals/ConfirmDeletionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const ConfirmDeletionModal = observer(
<Button
onPress={async () => {
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);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f654950

Please sign in to comment.