sorting participants list and fixed context menu
This commit is contained in:
@@ -24,12 +24,20 @@ type ParticipantsBarProps = {
|
|||||||
currentContact: ContactsProps | null;
|
currentContact: ContactsProps | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type MeProps = {
|
||||||
|
isGroupAdmin: boolean;
|
||||||
|
iGroupOwner: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
function ParticipantsBar({
|
function ParticipantsBar({
|
||||||
initializeContact,
|
initializeContact,
|
||||||
currentContact,
|
currentContact,
|
||||||
}: ParticipantsBarProps) {
|
}: ParticipantsBarProps) {
|
||||||
const [participants, setParticipants] = useState<ParticipantsProps[]>([]);
|
const [participants, setParticipants] = useState<ParticipantsProps[]>([]);
|
||||||
const [isGroupAdmin, setIsGroupAdmin] = useState<boolean>(false);
|
const [me, setMe] = useState<MeProps>({
|
||||||
|
isGroupAdmin: false,
|
||||||
|
iGroupOwner: false,
|
||||||
|
});
|
||||||
const user: UsernameType = useOutletContext();
|
const user: UsernameType = useOutletContext();
|
||||||
|
|
||||||
const getParticipants = async () => {
|
const getParticipants = async () => {
|
||||||
@@ -109,7 +117,12 @@ function ParticipantsBar({
|
|||||||
(participant) =>
|
(participant) =>
|
||||||
participant.user_id === user.user_id && participant.isadmin,
|
participant.user_id === user.user_id && participant.isadmin,
|
||||||
);
|
);
|
||||||
setIsGroupAdmin(userIsAdmin);
|
const userIsOwner = participants.some(
|
||||||
|
(participant) =>
|
||||||
|
participant.user_id === user.user_id && participant.isowner,
|
||||||
|
);
|
||||||
|
|
||||||
|
setMe({ isGroupAdmin: userIsAdmin, iGroupOwner: userIsOwner });
|
||||||
}
|
}
|
||||||
}, [participants, user?.user_id]);
|
}, [participants, user?.user_id]);
|
||||||
|
|
||||||
@@ -119,6 +132,22 @@ function ParticipantsBar({
|
|||||||
}
|
}
|
||||||
}, [currentContact]);
|
}, [currentContact]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setParticipants((prevParticipants) => {
|
||||||
|
return [...prevParticipants].sort((a, b) => {
|
||||||
|
if (a.isowner !== b.isowner) {
|
||||||
|
return b.isowner ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.isadmin !== b.isadmin) {
|
||||||
|
return b.isadmin ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.username.localeCompare(b.username);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [participants]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socket || !currentContact) return;
|
if (!socket || !currentContact) return;
|
||||||
|
|
||||||
@@ -233,7 +262,9 @@ function ParticipantsBar({
|
|||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ContextMenuTrigger>
|
</ContextMenuTrigger>
|
||||||
{user.user_id !== participant.user_id && isGroupAdmin ? (
|
{user.user_id !== participant.user_id &&
|
||||||
|
me.isGroupAdmin &&
|
||||||
|
(!participant.isadmin || me.iGroupOwner) ? (
|
||||||
<ContextMenuContent className="p-0">
|
<ContextMenuContent className="p-0">
|
||||||
<ContextMenuItem
|
<ContextMenuItem
|
||||||
className="bg-zinc-900 text-white outline-1 hover:bg-zinc-800 hover:cursor-pointer"
|
className="bg-zinc-900 text-white outline-1 hover:bg-zinc-800 hover:cursor-pointer"
|
||||||
|
|||||||
Reference in New Issue
Block a user