Skip to content

Commit

Permalink
fix: Resolve hand raise reactivity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisamir98 committed Dec 6, 2024
1 parent fd52dbe commit 5390a68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import React from 'react';

import {TabIndex} from '@wireapp/react-ui-kit/lib/types/enums';
import {observable, Observable} from 'knockout';

import {Avatar, AVATAR_SIZE} from 'Components/Avatar';
import {UserStatusBadges} from 'Components/Badge';
Expand All @@ -46,7 +45,7 @@ export interface CallParticipantsListItemProps {
onContextMenu: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
isSelfVerified?: boolean;
isLast?: boolean;
handRaisedAt?: Observable<number | null>;
handRaisedAt?: number | null;
}

export const CallParticipantsListItem = ({
Expand All @@ -55,11 +54,10 @@ export const CallParticipantsListItem = ({
showContextMenu,
onContextMenu,
isLast = false,
handRaisedAt = observable(null),
handRaisedAt = null,
}: CallParticipantsListItemProps) => {
const {user} = callParticipant;
const {isMe: isSelf, isFederated} = user;

const {isAudioEstablished} = useKoSubscribableChildren(callParticipant, ['isAudioEstablished']);

const {
Expand Down Expand Up @@ -110,7 +108,7 @@ export const CallParticipantsListItem = ({
onDropdownClick={event => onContextMenu?.(event as unknown as React.MouseEvent<HTMLDivElement>)}
/>

<CallParticipantsListItemHandRaiseIcon handRaisedAt={{value: handRaisedAt}} />
{handRaisedAt && <CallParticipantsListItemHandRaiseIcon handRaisedAt={handRaisedAt} />}

{isAudioEstablished ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,35 @@
*
*/

import {Observable} from 'knockout';
import {useEffect, useState} from 'react';

import {TimeInMillis} from '@wireapp/commons/lib/util/TimeUtil';

import {InviteIcon, Tooltip} from '@wireapp/react-ui-kit';

import {useKoSubscribableChildren} from 'Util/ComponentUtil';
import {t} from 'Util/LocalizerUtil';
import {formatDuration} from 'Util/TimeUtil';

import {toolTipStyles} from './CallParticipantsListItemHandRaiseIcon.styles';

export interface CallParticipantsListItemHandRaiseIconProps {
handRaisedAt: {value: Observable<number | null>};
handRaisedAt: number;
}

export function CallParticipantsListItemHandRaiseIcon({handRaisedAt}: CallParticipantsListItemHandRaiseIconProps) {
const {value: handRaisedAtValue} = useKoSubscribableChildren(handRaisedAt, ['value']);
const [duration, setDuration] = useState<string>();

useEffect(() => {
const timerId = setTimeout(() => {
setDuration(formatDuration(Date.now() - handRaisedAt + TimeInMillis.SECOND).text);
}, TimeInMillis.SECOND);

return () => {
clearTimeout(timerId);
};
});

if (!handRaisedAtValue) {
if (!duration) {
return null;
}

Expand All @@ -46,7 +57,7 @@ export function CallParticipantsListItemHandRaiseIcon({handRaisedAt}: CallPartic
<InviteIcon />
<span>
{t('videoCallParticipantRaisedHandRaiseDuration', {
duration: formatDuration(Date.now() - handRaisedAtValue).text,
duration,
})}
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const CallingParticipantList = ({
{handRaisedParticipants.map((participant, index, participantsArray) => (
<li key={participant.clientId} className="call-ui__participant-list__participant">
<CallParticipantsListItem
handRaisedAt={participant.handRaisedAt}
handRaisedAt={participant.handRaisedAt()}
key={participant.clientId}
callParticipant={participant}
isSelfVerified={isSelfVerified}
Expand Down
26 changes: 13 additions & 13 deletions src/script/components/calling/FullscreenVideoCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ const FullscreenVideoCall: React.FC<FullscreenVideoCallProps> = ({
const [showEmojisBar, setShowEmojisBar] = useState<boolean>(false);
const [disabledEmojis, setDisabledEmojis] = useState<string[]>([]);
const selfParticipant = call.getSelfParticipant();
const {sharesScreen: selfSharesScreen, sharesCamera: selfSharesCamera} = useKoSubscribableChildren(selfParticipant, [
'sharesScreen',
'sharesCamera',
]);

const {
sharesScreen: selfSharesScreen,
sharesCamera: selfSharesCamera,
handRaisedAt: selfHandRaisedAt,
} = useKoSubscribableChildren(selfParticipant, ['sharesScreen', 'sharesCamera', 'handRaisedAt']);
const isSelfHandRaised = Boolean(selfHandRaisedAt);
const emojiBarRef = useRef(null);
const emojiBarToggleButtonRef = useRef(null);

Expand Down Expand Up @@ -225,11 +226,10 @@ const FullscreenVideoCall: React.FC<FullscreenVideoCallProps> = ({
const openPopup = () => callingRepository.setViewModeDetached();

const [isCallViewOpen, toggleCallView] = useToggleState(false);
const [isHandRaised, setIsHandRaised] = useState(false);
const [isParticipantsListOpen, toggleParticipantsList] = useToggleState(false);

function toggleIsHandRaised(currentIsHandRaised: boolean) {
setIsHandRaised(!currentIsHandRaised);
selfParticipant.handRaisedAt(new Date().getTime());
sendHandRaised(!currentIsHandRaised, call);
}

Expand Down Expand Up @@ -818,16 +818,16 @@ const FullscreenVideoCall: React.FC<FullscreenVideoCallProps> = ({
{Config.getConfig().FEATURE.ENABLE_IN_CALL_HAND_RAISE && !is1to1Conversation && (
<li className="video-controls__item">
<button
data-uie-value={isHandRaised ? 'active' : 'inactive'}
onClick={() => toggleIsHandRaised(isHandRaised)}
onKeyDown={event => handleKeyDown(event, () => toggleIsHandRaised(isHandRaised))}
className={cx('video-controls__button_primary', {active: isHandRaised})}
data-uie-value={isSelfHandRaised ? 'active' : 'inactive'}
onClick={() => toggleIsHandRaised(isSelfHandRaised)}
onKeyDown={event => handleKeyDown(event, () => toggleIsHandRaised(isSelfHandRaised))}
className={cx('video-controls__button_primary', {active: isSelfHandRaised})}
type="button"
data-uie-name="do-toggle-hand-raise"
role="switch"
aria-checked={isHandRaised}
aria-checked={isSelfHandRaised}
title={
isHandRaised
isSelfHandRaised
? t('videoCallOverlayHideParticipantsList')
: t('videoCallOverlayShowParticipantsList')
}
Expand Down

0 comments on commit 5390a68

Please sign in to comment.