mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
Fix role ordering (#789)
* fix role order in picker * one of these sorts will flip it omg * fix role list * revert forced role sort in api
This commit is contained in:
parent
33a8a0048f
commit
45a1f45055
4 changed files with 21 additions and 18 deletions
|
@ -47,18 +47,15 @@ export const getGuild = async (
|
|||
.filter((x) => x !== undefined) as APIRole[]
|
||||
)?.position || -1;
|
||||
|
||||
const roles = guildRaw.roles
|
||||
.map<Role>((role) => ({
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
color: role.color,
|
||||
managed: role.managed,
|
||||
position: role.position,
|
||||
permissions: role.permissions,
|
||||
safety: calculateRoleSafety(role, highestRolePosition),
|
||||
}))
|
||||
// sort so that highest is first
|
||||
.sort((a, b) => b.position - a.position);
|
||||
const roles = guildRaw.roles.map<Role>((role) => ({
|
||||
id: role.id,
|
||||
name: role.name,
|
||||
color: role.color,
|
||||
managed: role.managed,
|
||||
position: role.position,
|
||||
permissions: role.permissions,
|
||||
safety: calculateRoleSafety(role, highestRolePosition),
|
||||
}));
|
||||
|
||||
const guild: Guild & OwnRoleInfo = {
|
||||
id,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { Popover } from '@roleypoly/design-system/atoms/popover';
|
||||
import { Role } from '@roleypoly/design-system/atoms/role';
|
||||
import { RoleSearch } from '@roleypoly/design-system/molecules/role-search';
|
||||
import { sortBy } from '@roleypoly/misc-utils/sortBy';
|
||||
import { Role as RoleT } from '@roleypoly/types';
|
||||
import { sortBy, uniq } from 'lodash';
|
||||
import { uniq } from 'lodash';
|
||||
import React from 'react';
|
||||
import { GoPlus } from 'react-icons/go';
|
||||
import { AddRoleButton, EditableRoleListStyled } from './EditableRoleList.styled';
|
||||
|
@ -38,7 +39,9 @@ export const EditableRoleList = (props: Props) => {
|
|||
<>
|
||||
{sortBy(
|
||||
props.roles.filter((r) => props.selectedRoles.includes(r.id)),
|
||||
'position'
|
||||
'position',
|
||||
undefined,
|
||||
true
|
||||
).map((role) => (
|
||||
<Role
|
||||
key={role.id}
|
||||
|
|
|
@ -47,7 +47,7 @@ export const PickerCategory = (props: CategoryProps) => (
|
|||
)}
|
||||
</Head>
|
||||
<Category>
|
||||
{sortBy(props.roles, 'position').map((role, idx) => (
|
||||
{sortBy(props.roles, 'position', undefined, true).map((role, idx) => (
|
||||
<Container key={idx}>
|
||||
<Role
|
||||
role={role}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
export const sortBy = <T, Key extends keyof T>(
|
||||
array: T[],
|
||||
key: Key,
|
||||
predicate?: (a: T[typeof key], b: T[typeof key]) => number
|
||||
predicate?: (a: T[typeof key], b: T[typeof key]) => number,
|
||||
reverse?: boolean
|
||||
) => {
|
||||
let postmultiplier = reverse ? -1 : 1;
|
||||
|
||||
return array.sort((a, b) => {
|
||||
if (predicate) {
|
||||
return predicate(a[key], b[key]);
|
||||
|
@ -13,9 +16,9 @@ export const sortBy = <T, Key extends keyof T>(
|
|||
}
|
||||
|
||||
if (a[key] > b[key]) {
|
||||
return 1;
|
||||
return 1 * postmultiplier;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1 * postmultiplier;
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue