Skip to content

Commit

Permalink
fix(OrderRolesModal): don't sort roles
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Oct 23, 2024
1 parent 0ffe51a commit 82c5e9d
Showing 1 changed file with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Button from "components/common/Button"
import DiscardAlert from "components/common/DiscardAlert"
import { Modal } from "components/common/Modal"
import { Reorder } from "framer-motion"
import { useMemo } from "react"
import { useController, useForm } from "react-hook-form"
import useReorderRoles from "../hooks/useReorderRoles"
import DraggableRoleCard from "./DraggableRoleCard"
Expand All @@ -27,34 +26,16 @@ const OrderRolesModal = ({ isOpen, onClose, finalFocusRef }): JSX.Element => {
const { roles } = useGuild()
const group = useRoleGroup()
const relevantRoles = group
? roles.filter((role) => role.groupId === group.id)
: roles.filter((role) => !role.groupId)
? roles?.filter((role) => role.groupId === group.id)
: roles?.filter((role) => !role.groupId)

const {
isOpen: isAlertOpen,
onOpen: onAlertOpen,
onClose: onAlertClose,
} = useDisclosure()

// temporary, will order roles already in the SQL query in the future
const sortedRoles = useMemo(() => {
if (relevantRoles?.every((role) => role.position === null)) {
const byMembers = relevantRoles?.sort(
(role1, role2) => role2.memberCount - role1.memberCount
)
return byMembers
}

return (
relevantRoles?.sort((role1, role2) => {
if (role1.position === null) return 1
if (role2.position === null) return -1
return role1.position - role2.position
}) ?? []
)
}, [relevantRoles])

const publicAndSecretRoles = sortedRoles.filter(
const publicAndSecretRoles = relevantRoles?.filter(
(role) => role.visibility !== "HIDDEN"
)

Expand Down

0 comments on commit 82c5e9d

Please sign in to comment.