Skip to content

Commit

Permalink
fix(useReorderRoles): sort roles when mutating the SWR cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Oct 23, 2024
1 parent 82c5e9d commit 7e24370
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/[guild]/AddAndOrderRoles/hooks/useReorderRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ const useReorderRoles = (onClose) => {
...oldData,
// requirements, and rolePlatforms are not returned, so we need to spread older data too
// Plus, we don't update all the roles, only the ones that changed, so this also retains those that weren't updated
roles: (oldData?.roles ?? []).map((prevRole) => ({
...prevRole,
...(newRoles ?? []).find((newRole) => newRole.id === prevRole.id),
})),
roles: (oldData?.roles ?? [])
.map((prevRole) => ({
...prevRole,
...(newRoles ?? []).find((newRole) => newRole.id === prevRole.id),
}))
.sort(
(role1, role2) =>
(role1.position ?? Infinity) - (role2.position ?? Infinity)
),
}),
{
revalidate: false,
Expand Down

0 comments on commit 7e24370

Please sign in to comment.