mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
one of these sorts will flip it omg
This commit is contained in:
parent
84685a14d5
commit
ceca93e54d
3 changed files with 9 additions and 6 deletions
|
@ -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}
|
||||
|
|
|
@ -90,11 +90,11 @@ export const RolePicker = (props: RolePickerProps) => {
|
|||
selectedRoles={selectedRoles.filter((roleId) =>
|
||||
category.roles.includes(roleId)
|
||||
)}
|
||||
roles={(
|
||||
roles={
|
||||
category.roles
|
||||
.map((role) => props.roles.find((r) => r.id === role))
|
||||
.filter((r) => r !== undefined) as Role[]
|
||||
).sort((a, b) => b.position - a.position)}
|
||||
}
|
||||
onChange={handleChange(category)}
|
||||
wikiMode={false}
|
||||
type={category.type === CategoryType.Single ? 'single' : 'multi'}
|
||||
|
|
|
@ -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