Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] RoomLeader status not working #27576

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions apps/meteor/app/theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -2650,78 +2650,3 @@
height: 100px;
}
}

.room-leader .chat-now {
position: absolute;
right: 25px;

height: 30px;
padding: 4px;

cursor: pointer;
text-align: center;
text-decoration: none;

color: #555555;
border: 1px solid var(--color-gray-light);
border-radius: var(--border-radius);

font-family: arial;
font-size: 14px;
}

.room-leader a.chat-now:hover {
color: #555555;
}

.room-leader {
position: absolute;
z-index: 9;
right: 0;
left: 0;

display: flex;

visibility: visible;
flex-direction: column;

height: 57px;
padding-bottom: 8px;

transition: transform 0.15s cubic-bezier(0.5, 0, 0.1, 1), visibility 0.15s cubic-bezier(0.5, 0, 0.1, 1);

border-bottom: 1px solid var(--color-gray-lightest);
justify-content: center;

&.message:hover {
background-color: #ffffff;
}

&.animated-hidden {
visibility: hidden;

transform: translateY(-100%);
}

& .leader-name {
font-size: 18px;
}

& .leader-status {
& .status-text {
padding-left: 15px;

font-size: 14px;
}

& .color-ball {
position: absolute;

width: 10px;
height: 10px;
margin-top: 5px;

border-radius: 5px;
}
}
}
76 changes: 50 additions & 26 deletions apps/meteor/client/views/room/components/body/LeaderBar.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import type { IUser } from '@rocket.chat/core-typings';
import { css } from '@rocket.chat/css-in-js';
import { Box, Button } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement, ReactNode, UIEvent } from 'react';
import type { ReactElement, UIEvent } from 'react';
import React, { memo, useCallback, useMemo } from 'react';

import { isTruthy } from '../../../../../lib/isTruthy';
import { UserStatus } from '../../../../components/UserStatus';
import UserAvatar from '../../../../components/avatar/UserAvatar';
import { usePresence } from '../../../../hooks/usePresence';
import { roomCoordinator } from '../../../../lib/rooms/roomCoordinator';

type LeaderBarProps = {
_id: IUser['_id'];
name: IUser['name'];
username: IUser['username'];
status?: 'online' | 'offline' | 'busy' | 'away';
statusText?: ReactNode;
visible: boolean;
onAvatarClick?: (event: UIEvent, username: IUser['username']) => void;
};

const LeaderBar = ({ name, username, status = 'offline', statusText, visible, onAvatarClick }: LeaderBarProps): ReactElement => {
const LeaderBar = ({ _id, name, username, visible, onAvatarClick }: LeaderBarProps): ReactElement => {
const t = useTranslation();

const chatNowLink = useMemo(() => roomCoordinator.getRouteLink('d', { name: username }) || undefined, [username]);
const roomLeaderData = usePresence(_id);

const handleAvatarClick = useCallback(
(event: UIEvent) => {
Expand All @@ -32,31 +36,51 @@ const LeaderBar = ({ name, username, status = 'offline', statusText, visible, on
throw new Error('username is required');
}

const roomLeaderStyle = css`
position: absolute;
z-index: 9;
right: 0;
left: 0;

visibility: visible;

transition: transform 0.15s cubic-bezier(0.5, 0, 0.1, 1), visibility 0.15s cubic-bezier(0.5, 0, 0.1, 1);

&.animated-hidden {
visibility: hidden;

transform: translateY(-100%);
}
`;

return (
<div
className={[
`room-leader`,
`message`,
`color-primary-font-color`,
`content-background-color`,
`border-component-color`,
!visible && 'animated-hidden',
]
.filter(isTruthy)
.join(' ')}
<Box
display='flex'
backgroundColor='light'
color='default'
pi='x24'
pb='x8'
justifyContent='space-between'
borderBlockEndWidth={2}
borderBlockEndColor='extra-light'
className={[roomLeaderStyle, 'room-leader', !visible && 'animated-hidden'].filter(isTruthy)}
>
<button type='button' className='thumb user-card-message' onClick={handleAvatarClick}>
<UserAvatar size='x40' username={username} />
</button>
<div className='leader-name'>{name}</div>
<div className='leader-status userStatus'>
<span className={`color-ball status-bg-${status}`} />
<span className='status-text leader-status-text'>{statusText ?? t(status)}</span>
</div>
<a className='chat-now' href={chatNowLink}>
<Box display='flex' alignItems='center'>
<Box is='button' mie='x4' onClick={handleAvatarClick}>
<UserAvatar username={username} />
</Box>
<Box fontScale='p2' mi='x4'>
<Box fontWeight={700}>{name}</Box>
<Box display='flex' alignItems='center'>
<UserStatus status={roomLeaderData?.status} />
<Box mis='x4'>{roomLeaderData?.statusText ?? t(roomLeaderData?.status || 'offline')}</Box>
</Box>
</Box>
</Box>
<Button is='a' href={chatNowLink}>
{t('Chat_Now')}
</a>
</div>
</Button>
</Box>
);
};

Expand Down
11 changes: 3 additions & 8 deletions apps/meteor/client/views/room/components/body/RoomBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const RoomBody = (): ReactElement => {

const useRealName = useSetting('UI_Use_Real_Name') as boolean;

const { data: roomLeader } = useReactiveQuery(['rooms', room._id, 'leader', { not: user?._id }], ({ roomRoles, users }) => {
const { data: roomLeader } = useReactiveQuery(['rooms', room._id, 'leader', { not: user?._id }], ({ roomRoles }) => {
const leaderRoomRole = roomRoles.findOne({
'rid': room._id,
'roles': 'leader',
Expand All @@ -171,13 +171,9 @@ const RoomBody = (): ReactElement => {
return null;
}

const leaderUser = users.findOne({ _id: leaderRoomRole.u._id }, { fields: { status: 1, statusText: 1 } });

return {
...leaderRoomRole.u,
name: useRealName ? leaderRoomRole.u.name || leaderRoomRole.u.username : leaderRoomRole.u.username,
status: leaderUser?.status,
statusText: leaderUser?.statusText,
};
});

Expand Down Expand Up @@ -614,10 +610,9 @@ const RoomBody = (): ReactElement => {
) : null}
{roomLeader ? (
<LeaderBar
name={roomLeader.name}
_id={roomLeader._id}
username={roomLeader.username}
status={roomLeader.status}
statusText={roomLeader.statusText}
name={roomLeader.name}
visible={!hideLeaderHeader}
onAvatarClick={handleOpenUserCardButtonClick}
/>
Expand Down