2021-08-04 12:52:59 +03:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-08-31 16:13:31 +03:00
|
|
|
import './RoomViewFloating.scss';
|
2021-08-04 12:52:59 +03:00
|
|
|
|
|
|
|
import initMatrix from '../../../client/initMatrix';
|
|
|
|
import cons from '../../../client/state/cons';
|
|
|
|
|
|
|
|
import Text from '../../atoms/text/Text';
|
|
|
|
import IconButton from '../../atoms/button/IconButton';
|
|
|
|
|
|
|
|
import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg';
|
|
|
|
|
|
|
|
import { getUsersActionJsx } from './common';
|
|
|
|
|
2021-08-31 16:13:31 +03:00
|
|
|
function RoomViewFloating({
|
2021-08-04 12:52:59 +03:00
|
|
|
roomId, roomTimeline, timelineScroll, viewEvent,
|
|
|
|
}) {
|
|
|
|
const [reachedBottom, setReachedBottom] = useState(true);
|
|
|
|
const [typingMembers, setTypingMembers] = useState(new Set());
|
|
|
|
const mx = initMatrix.matrixClient;
|
|
|
|
|
|
|
|
function isSomeoneTyping(members) {
|
|
|
|
const m = members;
|
|
|
|
m.delete(mx.getUserId());
|
|
|
|
if (m.size === 0) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTypingMessage(members) {
|
|
|
|
const userIds = members;
|
|
|
|
userIds.delete(mx.getUserId());
|
2021-08-26 15:58:33 +03:00
|
|
|
return getUsersActionJsx(roomId, [...userIds], 'typing...');
|
2021-08-04 12:52:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTyping(members) {
|
|
|
|
setTypingMembers(members);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setReachedBottom(true);
|
|
|
|
setTypingMembers(new Set());
|
|
|
|
viewEvent.on('toggle-reached-bottom', setReachedBottom);
|
|
|
|
return () => viewEvent.removeListener('toggle-reached-bottom', setReachedBottom);
|
|
|
|
}, [roomId]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
roomTimeline.on(cons.events.roomTimeline.TYPING_MEMBERS_UPDATED, updateTyping);
|
|
|
|
return () => {
|
|
|
|
roomTimeline?.removeListener(cons.events.roomTimeline.TYPING_MEMBERS_UPDATED, updateTyping);
|
|
|
|
};
|
|
|
|
}, [roomTimeline]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-08-31 16:13:31 +03:00
|
|
|
<div className={`room-view__typing${isSomeoneTyping(typingMembers) ? ' room-view__typing--open' : ''}`}>
|
2021-09-26 16:17:37 +03:00
|
|
|
<div className="bouncing-loader"><div /></div>
|
2021-08-04 12:52:59 +03:00
|
|
|
<Text variant="b2">{getTypingMessage(typingMembers)}</Text>
|
|
|
|
</div>
|
2021-08-31 16:13:31 +03:00
|
|
|
<div className={`room-view__STB${reachedBottom ? '' : ' room-view__STB--open'}`}>
|
2021-08-04 12:52:59 +03:00
|
|
|
<IconButton
|
|
|
|
onClick={() => {
|
|
|
|
timelineScroll.enableSmoothScroll();
|
|
|
|
timelineScroll.reachBottom();
|
|
|
|
timelineScroll.disableSmoothScroll();
|
|
|
|
}}
|
|
|
|
src={ChevronBottomIC}
|
|
|
|
tooltip="Scroll to Bottom"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-08-31 16:13:31 +03:00
|
|
|
RoomViewFloating.propTypes = {
|
2021-08-04 12:52:59 +03:00
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
roomTimeline: PropTypes.shape({}).isRequired,
|
|
|
|
timelineScroll: PropTypes.shape({
|
|
|
|
reachBottom: PropTypes.func,
|
|
|
|
}).isRequired,
|
|
|
|
viewEvent: PropTypes.shape({}).isRequired,
|
|
|
|
};
|
|
|
|
|
2021-08-31 16:13:31 +03:00
|
|
|
export default RoomViewFloating;
|