Skip to content

Commit b378067

Browse files
authored
Merge pull request #1081 from kimbu-chat/develop
Develop
2 parents fd6bdb3 + 0f81bda commit b378067

File tree

96 files changed

+618
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+618
-468
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"eslint-plugin-react-hooks": "4.2.0",
8888
"file-loader": "6.2.0",
8989
"husky": "7.0.1",
90-
"kimbu-models": "git://github.com/ravudi/frontend-types.git#fd7cc7c",
90+
"kimbu-models": "git://github.com/kimbu-chat/frontend-types.git#fd7cc7c",
9191
"lint-staged": "11.1.2",
9292
"prettier": "2.3.2",
9393
"run-script-os": "1.1.6",

src/utils/constants.ts src/common/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ export const FULL_DATE_TIME = 'l LT';
1515
export const SHORT_TIME_AM_PM = 'LT';
1616
export const MINUTES_SECONDS = 'mm:ss';
1717
export const REQUEST_TIMEOUT = 10000;
18+
19+
export const INTERSECTION_THROTTLE_FOR_MEDIA = 350;
20+
export const INTERSECTION_THRESHOLD_FOR_MEDIA = 0.0001;

src/common/constants/media.ts

-2
This file was deleted.

src/components/active-call/active-call.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
66
import { useSelector } from 'react-redux';
77
import { Rnd } from 'react-rnd';
88

9+
import { SECOND_DURATION } from '@common/constants';
910
import { Avatar } from '@components/avatar';
1011
import { Dropdown } from '@components/dropdown';
1112
import { useActionWithDispatch } from '@hooks/use-action-with-dispatch';
@@ -48,7 +49,6 @@ import {
4849
getInterlocutorVideoTrack,
4950
tracks,
5051
} from '@store/calls/utils/user-media';
51-
import { SECOND_DURATION } from '@utils/constants';
5252
import { playSoundSafely } from '@utils/current-music';
5353
import { getHourMinuteSecond } from '@utils/date-utils';
5454

src/components/chat-info-right-panel/chat-actions/chat-actions.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export const ChatActions: React.FC = () => {
5858

5959
const chat = useSelector(
6060
getInfoChatSelector,
61-
(prev, next) => prev === next || prev?.draftMessage !== next?.draftMessage,
61+
// todo: avoid unnecessary renders
62+
(prev, next) => prev === next,
6263
);
6364

6465
const isMe = useIsMe(chat.interlocutorId);

src/components/chat-info-right-panel/chat-info-right-panel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useSelector } from 'react-redux';
66
import {
77
INTERSECTION_THROTTLE_FOR_MEDIA,
88
INTERSECTION_THRESHOLD_FOR_MEDIA,
9-
} from '@common/constants/media';
9+
} from '@common/constants';
1010
import { Avatar } from '@components/avatar';
1111
import { MediaModal } from '@components/image-modal';
1212
import { useActionWithDispatch } from '@hooks/use-action-with-dispatch';

src/components/chat-info-right-panel/chat-media/audio-list/audio-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const AudioList: React.FC<IAudioListProps> = ({ rootRef }) => {
3535
}, [getAudios]);
3636

3737
const audiosWithSeparators = setSeparators<IAudioAttachment>(
38-
audiosForSelectedChat?.audios,
38+
audiosForSelectedChat?.data,
3939
{ separateByMonth: true, separateByYear: true },
4040
{ separateByMonth: true, separateByYear: true },
4141
);

src/components/chat-info-right-panel/chat-media/file-list/file-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const FileList: React.FC<IFileListProps> = ({ rootRef }) => {
2828
}, [getRawAttachments]);
2929

3030
const filesWithSeparators = setSeparators(
31-
filesForSelectedChat?.files,
31+
filesForSelectedChat?.data,
3232
{ separateByMonth: true, separateByYear: true },
3333
{ separateByMonth: true, separateByYear: true },
3434
);

src/components/chat-info-right-panel/chat-media/photo-list/photo-list.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const PhotoList: React.FC<PhotoListProps> = ({ observeIntersection, rootRef }) =
3333
}, [getPhotoAttachments]);
3434

3535
const photosWithSeparators = setSeparators<IPictureAttachment>(
36-
photoForSelectedChat?.photos,
36+
photoForSelectedChat?.data,
3737
{ separateByMonth: true, separateByYear: true },
3838
{ separateByMonth: true, separateByYear: true },
3939
);
4040

4141
const PhotoAttachmentComponent: React.FC<IPictureAttachment> = ({ ...photo }) =>
42-
photoForSelectedChat?.photos ? (
42+
photoForSelectedChat?.data ? (
4343
<Photo
4444
photo={photo}
45-
attachmentsArr={photoForSelectedChat.photos}
45+
attachmentsArr={photoForSelectedChat.data}
4646
observeIntersection={observeIntersection}
4747
/>
4848
) : null;

src/components/chat-info-right-panel/chat-media/recordings-list/recordings-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const RecordingsList: React.FC<IRecordingsListProps> = ({ rootRef }) => {
2929
}, [getRecordings]);
3030

3131
const recordingsWithSeparators = setSeparators<IVoiceAttachment>(
32-
recordingsForSelectedChat?.recordings,
32+
recordingsForSelectedChat?.data,
3333
{ separateByMonth: true, separateByYear: true },
3434
{ separateByMonth: true, separateByYear: true },
3535
);

src/components/chat-info-right-panel/chat-media/video-list/video-list.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export const VideoList: React.FC<IVideoListProps> = ({ rootRef }) => {
3131
}, [getVideoAttachmentss]);
3232

3333
const videosWithSeparators = setSeparators<IVideoAttachment>(
34-
videosForSelectedChat?.videos,
34+
videosForSelectedChat?.data,
3535
{ separateByMonth: true, separateByYear: true },
3636
{ separateByMonth: true, separateByYear: true },
3737
);
3838

3939
const VideoAttachmentComponent: React.FC<IVideoAttachment & IGroupable> = ({ ...video }) =>
40-
videosForSelectedChat?.videos ? (
41-
<VideoFromList video={video} attachmentsArr={videosForSelectedChat.videos} />
40+
videosForSelectedChat?.data ? (
41+
<VideoFromList video={video} attachmentsArr={videosForSelectedChat.data} />
4242
) : null;
4343

4444
return (

src/components/chat-list/chat-item/chat-item.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ const ChatItem: React.FC<IChatItemProps> = React.memo(({ chatId }) => {
121121
t,
122122
]);
123123

124+
// TODO: Make this logic common across chat item and message item
124125
const messageStatIconMap = {
125126
[MessageState.QUEUED]: <MessageQeuedSvg />,
126127
[MessageState.SENT]: <MessageSentSvg />,
127128
[MessageState.READ]: <MessageReadSvg />,
128129
[MessageState.ERROR]: <MessageErrorSvg />,
129130
[MessageState.DELETED]: undefined,
130131
[MessageState.LOCALMESSAGE]: undefined,
132+
[MessageState.DRAFT]: undefined,
131133
};
132134

133135
return (

src/components/chat-top-bar/messages-search/messages-search.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ const MessagesSearch = () => {
3030
if (isSearching) {
3131
setIsSearching(false);
3232
getMessages({
33-
isFromScroll: false,
33+
initializedByScroll: false,
3434
});
3535
}
3636
}, [isSearching, getMessages]);
3737

3838
const resetSearch = useCallback(() => {
3939
getMessages({
40-
isFromScroll: false,
40+
initializedByScroll: false,
4141
});
4242
}, [getMessages]);
4343

4444
const searchMessages = useCallback(
4545
(e: React.ChangeEvent<HTMLInputElement>) => {
4646
getMessages({
47-
isFromScroll: false,
47+
initializedByScroll: false,
4848
searchString: e.target.value,
4949
});
5050
},

src/components/friend-list/friend-list.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useSelector } from 'react-redux';
55
import { InfiniteScroll } from '@components/infinite-scroll';
66
import { CenteredLoader, LoaderSize } from '@components/loader';
77
import { SearchBox } from '@components/search-box';
8-
import { useActionWithDeferred } from '@hooks/use-action-with-deferred';
98
import { useActionWithDispatch } from '@hooks/use-action-with-dispatch';
109
import { getFriendsAction, resetSearchFriendsAction } from '@store/friends/actions';
1110
import { getMyFriendsListSelector, getMySearchFriendsListSelector } from '@store/friends/selectors';
@@ -27,7 +26,7 @@ export const FriendList = () => {
2726
loading: searchFriendsLoading,
2827
} = searchFriendsList;
2928

30-
const loadFriends = useActionWithDeferred(getFriendsAction);
29+
const loadFriends = useActionWithDispatch(getFriendsAction);
3130
const resetSearchFriends = useActionWithDispatch(resetSearchFriendsAction);
3231

3332
useEffect(

src/components/group-chat-add-friend-modal/group-chat-add-friend-modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const InitialGroupChatAddFriendModal: React.FC<
4343
const [name, setName] = useState('');
4444

4545
const chat = useSelector(
46+
// todo: avoid unnecessary renders
4647
getInfoChatSelector,
47-
(prev, next) => prev === next || prev?.draftMessage !== next?.draftMessage,
4848
);
4949

5050
const addUsersToGroupChat = useActionWithDeferred(addUsersToGroupChatAction);

src/components/message-input/message-input-attachment/message-input-attachment.tsx

+24-30
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import { ReactComponent as PlaySVG } from '@icons/play.svg';
1515
import { ReactComponent as VideoSVG } from '@icons/video.svg';
1616
import { ReactComponent as MicrophoneSvg } from '@icons/voice.svg';
1717
import { removeAttachmentAction } from '@store/chats/actions';
18-
import { IAttachmentToSend, IAttachmentCreation } from '@store/chats/models';
18+
import { IAttachmentCreation, IAttachmentToSend } from '@store/chats/models';
1919
import { INamedAttachment } from '@store/chats/models/named-attachment';
2020
import { getRawAttachmentSizeUnit } from '@utils/get-file-size-unit';
2121

2222
import './message-input-attachment.scss';
2323

2424
interface IMessageInputAttachmentProps {
25-
attachment: IAttachmentToSend<IAttachmentBase>;
25+
attachment: IAttachmentToSend | IAttachmentBase;
2626
isFromEdit?: boolean;
2727
removeSelectedAttachment?: (attachmentToRemove: IAttachmentCreation) => void;
2828
}
@@ -33,93 +33,87 @@ export const MessageInputAttachment: React.FC<IMessageInputAttachmentProps> = ({
3333
removeSelectedAttachment,
3434
}) => {
3535
const removeAttachment = useActionWithDispatch(removeAttachmentAction);
36-
36+
const newAttachment = attachment as IAttachmentToSend;
3737
const [previewUrl, setPreviewUr] = useState<string>('');
3838

3939
const removeThisAttachment = useCallback(() => {
4040
if (removeSelectedAttachment) {
4141
removeSelectedAttachment({
42-
type: attachment.attachment.type,
43-
id: attachment.attachment.id,
42+
type: attachment.type,
43+
id: attachment.id,
4444
});
4545
} else {
4646
removeAttachment({
47-
attachmentId: attachment.attachment.id,
47+
attachmentId: attachment.id,
4848
});
4949
}
50-
}, [
51-
attachment.attachment.id,
52-
attachment.attachment.type,
53-
removeAttachment,
54-
removeSelectedAttachment,
55-
]);
50+
}, [attachment.id, attachment.type, removeAttachment, removeSelectedAttachment]);
5651

5752
useEffect(() => {
58-
if (attachment.attachment.type === AttachmentType.Picture && !isFromEdit) {
53+
if (attachment.type === AttachmentType.Picture && !isFromEdit) {
5954
const reader = new FileReader();
6055

6156
reader.onload = (e) => {
6257
setPreviewUr(e.target?.result as string);
6358
};
6459

65-
reader.readAsDataURL(attachment.file);
60+
reader.readAsDataURL(newAttachment.file);
6661
}
67-
}, [setPreviewUr, isFromEdit, attachment.attachment.type, attachment.file]);
62+
}, [setPreviewUr, isFromEdit, attachment.type, newAttachment.file]);
6863

6964
return (
7065
<div className="message-input-attachment">
71-
{attachment.attachment.type === AttachmentType.Raw && (
66+
{attachment.type === AttachmentType.Raw && (
7267
<FileSVG className="message-input-attachment__type-icon" />
7368
)}
74-
{attachment.attachment.type === AttachmentType.Video && (
69+
{attachment.type === AttachmentType.Video && (
7570
<>
76-
{(attachment.attachment as IVideoAttachment).firstFrameUrl && (
71+
{(attachment as unknown as IVideoAttachment).firstFrameUrl && (
7772
<img
78-
src={(attachment.attachment as IVideoAttachment).firstFrameUrl}
73+
src={(attachment as unknown as IVideoAttachment).firstFrameUrl}
7974
alt=""
8075
className="message-input-attachment__bg"
8176
/>
8277
)}
8378
<VideoSVG className="message-input-attachment__type-icon" />
8479
</>
8580
)}
86-
{attachment.attachment.type === AttachmentType.Picture && (
81+
{attachment.type === AttachmentType.Picture && (
8782
<>
88-
{((attachment.attachment as IPictureAttachment).previewUrl || previewUrl) && (
83+
{((attachment as unknown as IPictureAttachment).previewUrl || previewUrl) && (
8984
<img
90-
src={(attachment.attachment as IPictureAttachment).previewUrl || previewUrl}
85+
src={(attachment as unknown as IPictureAttachment).previewUrl || previewUrl}
9186
alt=""
9287
className="message-input-attachment__bg"
9388
/>
9489
)}
9590
<PhotoSVG className="message-input-attachment__type-icon" />
9691
</>
9792
)}
98-
{attachment.attachment.type === AttachmentType.Audio && (
93+
{attachment.type === AttachmentType.Audio && (
9994
<PlaySVG className="message-input-attachment__type-icon" />
10095
)}
10196

102-
{attachment.attachment.type === AttachmentType.Voice && (
97+
{attachment.type === AttachmentType.Voice && (
10398
<MicrophoneSvg className="message-input-attachment__type-icon" />
10499
)}
105100

106101
<div
107-
style={{ width: `${attachment.progress}%` }}
102+
style={{ width: `${newAttachment.progress}%` }}
108103
className={`message-input-attachment__progress ${
109-
attachment.attachment.type === AttachmentType.Picture ||
110-
attachment.attachment.type === AttachmentType.Video
104+
attachment.type === AttachmentType.Picture || attachment.type === AttachmentType.Video
111105
? 'message-input-attachment__progress--photo'
112106
: ''
113107
}`}
114108
/>
115109

116110
<div className="message-input-attachment__data">
117111
<div className="message-input-attachment__title">
118-
{(attachment.attachment as INamedAttachment).fileName}
112+
{(attachment as unknown as INamedAttachment).fileName}
119113
</div>
120114
<div className="message-input-attachment__size">{`${getRawAttachmentSizeUnit(
121-
attachment.uploadedBytes || attachment.attachment.byteSize,
122-
)}/${getRawAttachmentSizeUnit(attachment.attachment.byteSize)}}`}</div>
115+
newAttachment.uploadedBytes || attachment.byteSize,
116+
)}/${getRawAttachmentSizeUnit(attachment.byteSize)}}`}</div>
123117
</div>
124118

125119
<button

0 commit comments

Comments
 (0)