Skip to content

Commit

Permalink
fix(#644): fix scrolling issue in message list
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim-v committed Aug 1, 2021
1 parent 3c28749 commit 6c48445
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Deploy
on:
push:
branches:
- development
- bugfix/fix-scrolling

concurrency:
group: ${{ github.ref }}
Expand Down
1 change: 1 addition & 0 deletions src/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ input {
--dt-dark-wt-kingBlue: #262c38;
--dt-dark-wt-whiter: #262c38;
--dt-dark-wt-kingBlueLight-transparenter: #262c38;
--dt-dark-wt-kingBlueLight-hover: #222732;
--dt-dark-wt-kingBlue-lighter: #262c38;
--dt-dark-transparent-wt-kingBlueLight: rgba(38, 44, 56, 0.5);
--dt-dark-transparent-wt-kingBlueLight-transparent: rgba(38, 44, 56, 0.5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState, useRef } from 'react';

import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
Expand All @@ -24,6 +24,7 @@ interface IAddCallModalProps {

export const AddCallModal: React.FC<IAddCallModalProps> = ({ onClose }) => {
const { t } = useTranslation();
const containerRef = useRef<HTMLDivElement>(null);

const friendsList = useSelector(getMyFriendsListSelector);
const searchFriendsList = useSelector(getMySearchFriendsListSelector);
Expand Down Expand Up @@ -107,7 +108,7 @@ export const AddCallModal: React.FC<IAddCallModalProps> = ({ onClose }) => {

return (
<Modal closeModal={onClose}>
<>
<div ref={containerRef}>
<Modal.Header>
<AddCallSvg viewBox="0 0 65 64" className="add-call-modal__icon" />
<span> {t('addCallModal.title')} </span>
Expand All @@ -120,14 +121,15 @@ export const AddCallModal: React.FC<IAddCallModalProps> = ({ onClose }) => {
onChange={handleSearchInputChange}
/>
<InfiniteScroll
containerRef={containerRef}
className="add-call-modal__friends-block 1"
onReachBottom={loadMore}
hasMore={name.length ? hasMoreSearchFriends : hasMoreFriends}
isLoading={name.length ? searchFriendsLoading : friendsLoading}>
{selectEntities}
</InfiniteScroll>
</div>
</>
</div>
</Modal>
);
};
8 changes: 5 additions & 3 deletions src/components/call-list/call-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState, useMemo, useEffect } from 'react';
import React, { useCallback, useState, useMemo, useEffect, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -18,10 +18,11 @@ const BLOCK_NAME = 'call-list';
export const CallList = () => {
const callsList = useSelector(getCallsListSelector);
const searchCallsList = useSelector(getSearchCallsListSelector);

const getCalls = useActionWithDispatch(getCallsAction);
const resetSearchCalls = useActionWithDispatch(resetSearchCallsAction);

const containerRef = useRef<HTMLDivElement>(null);

const [searchString, setSearchString] = useState('');
const changeSearchString = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -75,8 +76,9 @@ export const CallList = () => {
onChange={changeSearchString}
/>
</div>
<div className={BLOCK_NAME}>
<div className={BLOCK_NAME} ref={containerRef}>
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={searchString.length ? searchCallsList.hasMore : callsList.hasMore}
isLoading={searchString.length ? searchCallsList.loading : callsList.loading}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -23,7 +23,7 @@ const AudioAttachmentComponent: React.FC<IAudioAttachment> = ({ ...audio }) => (

export const AudioList = () => {
const audiosForSelectedChat = useSelector(getSelectedChatAudiosSelector);

const containerRef = useRef<HTMLDivElement>(null);
const getAudios = useActionWithDispatch(getAudioAttachmentsAction);

const loadMore = useCallback(() => {
Expand All @@ -39,9 +39,10 @@ export const AudioList = () => {
);

return (
<div className="chat-audios">
<div className="chat-audios" ref={containerRef}>
<div className="chat-audios__audios">
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={audiosForSelectedChat?.hasMore}
isLoading={audiosForSelectedChat?.loading}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -24,7 +24,7 @@ const FileAttachmentComponent: React.FC<IBaseAttachment> = ({ ...file }) => (

export const FileList = () => {
const getRawAttachments = useActionWithDispatch(getRawAttachmentsAction);

const containerRef = useRef<HTMLDivElement>(null);
const filesForSelectedChat = useSelector(getSelectedChatFilesSelector);

const loadMore = useCallback(() => {
Expand All @@ -45,8 +45,9 @@ export const FileList = () => {
);

return (
<div className="chat-files">
<div className="chat-files" ref={containerRef}>
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={filesForSelectedChat?.hasMore}
isLoading={filesForSelectedChat?.loading}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand Down Expand Up @@ -26,6 +26,7 @@ type PhotoListProps = {
const PhotoList: React.FC<PhotoListProps> = ({ observeIntersection }) => {
const getPhotoAttachments = useActionWithDispatch(getPhotoAttachmentsAction);
const photoForSelectedChat = useSelector(getSelectedChatPhotosSelector);
const containerRef = useRef<HTMLDivElement>(null);

const loadMore = useCallback(() => {
const page: IPage = {
Expand Down Expand Up @@ -54,8 +55,9 @@ const PhotoList: React.FC<PhotoListProps> = ({ observeIntersection }) => {
) : null;

return (
<div className="chat-photo">
<div className="chat-photo" ref={containerRef}>
<InfiniteScroll
containerRef={containerRef}
className="chat-photo__photo-container"
onReachBottom={loadMore}
hasMore={photoForSelectedChat?.hasMore}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -16,7 +16,7 @@ import './recordings-list.scss';

export const RecordingsList = () => {
const recordingsForSelectedChat = useSelector(getSelectedChatRecordingsSelector);

const containerRef = useRef<HTMLDivElement>(null);
const getRecordings = useActionWithDispatch(getVoiceAttachmentsAction);

const loadMore = useCallback(() => {
Expand All @@ -36,9 +36,10 @@ export const RecordingsList = () => {
);

return (
<div className="chat-recordings">
<div className="chat-recordings" ref={containerRef}>
<div className="chat-recordings__recordings">
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={recordingsForSelectedChat?.hasMore}
isLoading={recordingsForSelectedChat?.loading}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -19,7 +19,7 @@ import './video-list.scss';

export const VideoList = () => {
const getVideoAttachmentss = useActionWithDispatch(getVideoAttachmentsAction);

const containerRef = useRef<HTMLDivElement>(null);
const videosForSelectedChat = useSelector(getSelectedChatVideosSelector);

const loadMore = useCallback(() => {
Expand All @@ -45,8 +45,9 @@ export const VideoList = () => {
) : null;

return (
<div className="chat-video">
<div className="chat-video" ref={containerRef}>
<InfiniteScroll
containerRef={containerRef}
className="chat-video__scroll"
onReachBottom={loadMore}
hasMore={videosForSelectedChat?.hasMore}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useRef } from 'react';

import classnames from 'classnames';
import { useTranslation } from 'react-i18next';
Expand All @@ -25,6 +25,7 @@ const BLOCK_NAME = 'chat-members';
export const ChatMembers: React.FC = () => {
const [searchStr, setSearchStr] = useState<string>('');
const [membersDisplayed, setMembersDisplayed] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);

const { t } = useTranslation();

Expand Down Expand Up @@ -64,7 +65,7 @@ export const ChatMembers: React.FC = () => {
);

return (
<div className={BLOCK_NAME}>
<div className={BLOCK_NAME} ref={containerRef}>
<div className={`${BLOCK_NAME}__heading-block`}>
<h3 className={`${BLOCK_NAME}__heading`}>{t('chatMembers.title')}</h3>
<button
Expand All @@ -84,6 +85,7 @@ export const ChatMembers: React.FC = () => {
</div>

<InfiniteScroll
containerRef={containerRef}
className={`${BLOCK_NAME}__members-list`}
onReachBottom={loadMore}
hasMore={membersListForGroupChat?.hasMore}
Expand Down
7 changes: 5 additions & 2 deletions src/components/chat-list/chat-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useCallback, useState, useMemo } from 'react';
import React, { useEffect, useCallback, useState, useMemo, useRef } from 'react';

import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
Expand Down Expand Up @@ -27,6 +27,8 @@ const ChatList = React.memo(() => {
const chatsList = useSelector(getChatsListSelector);
const searchChatsList = useSelector(getSearchChatsListSelector);

const containerRef = useRef<HTMLDivElement>(null);

const getChatsRequest = useActionWithDispatch(getChatsAction);
const changeSelectedChat = useActionWithDispatch(changeSelectedChatAction);
const resetSearchChats = useActionWithDispatch(resetSearchChatsAction);
Expand Down Expand Up @@ -96,7 +98,7 @@ const ChatList = React.memo(() => {

return (
<>
<div>
<div ref={containerRef}>
<div className={`${BLOCK_NAME}__search-top`}>
<SearchBox
containerClassName={`${BLOCK_NAME}__search-top__search-container`}
Expand All @@ -113,6 +115,7 @@ const ChatList = React.memo(() => {
</div>
<div className={BLOCK_NAME}>
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={searchString.length ? searchChatsList.hasMore : chatsList.hasMore}
isLoading={searchString.length ? searchChatsList.loading : chatsList.loading}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -21,6 +21,8 @@ const UserSelect: React.FC<IUserSelectProps> = ({ changeSelectedState, isSelecte

const [name, setName] = useState('');

const containerRef = useRef<HTMLDivElement>(null);

const friendsList = useSelector(getMyFriendsListSelector);
const searchFriendsList = useSelector(getMySearchFriendsListSelector);

Expand Down Expand Up @@ -76,12 +78,13 @@ const UserSelect: React.FC<IUserSelectProps> = ({ changeSelectedState, isSelecte
}, [name.length, searchFriendIds, friendIds, renderSelectEntity]);

return (
<div className="create-group-chat__select-friends">
<div className="create-group-chat__select-friends" ref={containerRef}>
<SearchBox
containerClassName="create-group-chat__select-friends__search"
onChange={handleSearchInputChange}
/>
<InfiniteScroll
containerRef={containerRef}
className="create-group-chat__friends-block"
onReachBottom={loadMore}
hasMore={name.length ? hasMoreSearchFriends : hasMoreFriends}
Expand Down
9 changes: 6 additions & 3 deletions src/components/forward-modal/forward-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState, useMemo, useEffect } from 'react';
import React, { useCallback, useState, useMemo, useEffect, useRef } from 'react';

import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -30,6 +30,8 @@ interface IForwardModalProps {
export const ForwardModal: React.FC<IForwardModalProps> = ({ onClose, messageIdsToForward }) => {
const { t } = useTranslation();

const containerRef = useRef<HTMLDivElement>(null);

const chatsList = useSelector(getChatsListSelector);
const searchChatsList = useSelector(getSearchChatsListSelector);

Expand Down Expand Up @@ -115,7 +117,7 @@ export const ForwardModal: React.FC<IForwardModalProps> = ({ onClose, messageIds

return (
<Modal closeModal={onClose}>
<>
<div ref={containerRef}>
<Modal.Header>
<>
<ForwardSvg viewBox="0 0 16 16" className={`${BLOCK_NAME}__icon`} />
Expand All @@ -130,6 +132,7 @@ export const ForwardModal: React.FC<IForwardModalProps> = ({ onClose, messageIds
onChange={handleChatSearchChange}
/>
<InfiniteScroll
containerRef={containerRef}
className={`${BLOCK_NAME}__chats-block`}
onReachBottom={loadMore}
hasMore={searchString.length ? searchChatsList.hasMore : chatsList.hasMore}
Expand All @@ -150,7 +153,7 @@ export const ForwardModal: React.FC<IForwardModalProps> = ({ onClose, messageIds
</Button>
</div>
</div>
</>
</div>
</Modal>
);
};
Expand Down
7 changes: 5 additions & 2 deletions src/components/friend-list/friend-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState, useMemo, useEffect } from 'react';
import React, { useCallback, useState, useMemo, useEffect, useRef } from 'react';

import { useSelector } from 'react-redux';

Expand All @@ -19,6 +19,8 @@ export const FriendList = () => {
const friendsList = useSelector(getMyFriendsListSelector);
const searchFriendsList = useSelector(getMySearchFriendsListSelector);

const containerRef = useRef<HTMLDivElement>(null);

const { hasMore: hasMoreFriends, friendIds, loading: friendsLoading } = friendsList;
const {
hasMore: hasMoreSearchFriends,
Expand Down Expand Up @@ -70,7 +72,7 @@ export const FriendList = () => {
}, [searchString.length, searchFriendIds, friendIds, renderFriend]);

return (
<div>
<div ref={containerRef}>
<div className="friend-list__search-top">
<SearchBox
containerClassName="friend-list__search-top__search-container"
Expand All @@ -81,6 +83,7 @@ export const FriendList = () => {
</div>
<div className="friend-list">
<InfiniteScroll
containerRef={containerRef}
onReachBottom={loadMore}
hasMore={searchString.length ? hasMoreSearchFriends : hasMoreFriends}
isLoading={searchString.length ? searchFriendsLoading : friendsLoading}>
Expand Down
Loading

0 comments on commit 6c48445

Please sign in to comment.