Skip to content

Commit 4824c92

Browse files
committed
configured new and old msg layout
1 parent 511dade commit 4824c92

File tree

3 files changed

+59
-17
lines changed

3 files changed

+59
-17
lines changed

packages/messenger-widget/src/components/Message/Message.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { ProfilePreview } from './ProfilePreview';
1717
import { AuthContext } from '../../context/AuthContext';
1818
import { ConversationContext } from '../../context/ConversationContext';
1919
import { DM3UserProfileContext } from '../../context/DM3UserProfileContext';
20+
import { SettingsContext } from '../../context/SettingsContext';
21+
import { MsgViewType } from '../../hooks/settings/useSettings';
2022

2123
export function Message(props: MessageProps) {
2224
const { messageView } = useContext(UiViewContext);
@@ -27,6 +29,8 @@ export function Message(props: MessageProps) {
2729

2830
const { accountProfilePicture } = useContext(DM3UserProfileContext);
2931

32+
const { msgViewSelected } = useContext(SettingsContext);
33+
3034
return (
3135
<span
3236
id={props.envelop.metadata?.messageHash}
@@ -38,20 +42,22 @@ export function Message(props: MessageProps) {
3842
)}
3943
>
4044
{/* Profile preview before every message content to show the actual sender of it */}
41-
{props.showProfile && (
42-
<ProfilePreview
43-
name={
44-
props.ownMessage
45-
? (displayName as string)
46-
: (selectedContact?.name as string)
47-
}
48-
picture={
49-
props.ownMessage
50-
? accountProfilePicture
51-
: (selectedContact?.image as string)
52-
}
53-
/>
54-
)}
45+
{msgViewSelected.viewType === MsgViewType.NEW &&
46+
props.showProfile && (
47+
<ProfilePreview
48+
name={
49+
props.ownMessage
50+
? (displayName as string)
51+
: (selectedContact?.name as string)
52+
}
53+
picture={
54+
props.ownMessage
55+
? accountProfilePicture
56+
: (selectedContact?.image as string)
57+
}
58+
ownMessage={props.ownMessage}
59+
/>
60+
)}
5561

5662
<div className="d-flex">
5763
<div className={getMessageStyleClasses(props, messageView)}>

packages/messenger-widget/src/components/Message/ProfilePreview.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
1+
import { useContext } from 'react';
12
import './Message.css';
3+
import { UiViewContext } from '../../context/UiViewContext';
4+
import { RightViewSelected } from '../../utils/enum-type-utils';
5+
import { closeContactMenu } from '../../utils/common-utils';
6+
import { ConversationContext } from '../../context/ConversationContext';
27

38
export interface ProfilePreviewProps {
49
picture: string;
510
name: string;
11+
ownMessage: boolean;
612
}
713

814
export function ProfilePreview(props: ProfilePreviewProps) {
15+
const { setSelectedRightView } = useContext(UiViewContext);
16+
const { setSelectedContactName } = useContext(ConversationContext);
17+
18+
// method to open the profile of selected account
19+
const openProfile = () => {
20+
// if our own profile icon is clicked
21+
if (props.ownMessage) {
22+
// select and open profile component
23+
setSelectedRightView(RightViewSelected.Profile);
24+
// unselect the contact
25+
setSelectedContactName(undefined);
26+
return;
27+
}
28+
// open contact info of the selected contact
29+
setSelectedRightView(RightViewSelected.ContactInfo);
30+
// close the contact menu
31+
closeContactMenu();
32+
};
33+
934
return (
1035
<div className="d-flex align-items-center">
36+
{/* profile picture of the account or contact selected */}
1137
<img
1238
className="chat-profile-pic mb-1 pointer-cursor"
1339
src={props.picture}
40+
onClick={() => openProfile()}
1441
/>
15-
<div className="ms-2 font-size-12 font-weight-800 pointer-cursor">
42+
{/* Name of the account or contact selected */}
43+
<div
44+
className="ms-2 font-size-12 font-weight-800 pointer-cursor"
45+
onClick={() => openProfile()}
46+
>
1647
{props.name.length > 16 ? props.name.slice(0, 16) : props.name}
1748
</div>
1849
</div>

packages/messenger-widget/src/hooks/settings/useSettings.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ export type SettingsDataType = {
1212
messageView: string;
1313
};
1414

15+
export enum MsgViewType {
16+
OLD = 'OLD',
17+
NEW = 'NEW',
18+
}
19+
1520
// available message view options
1621
export const MSG_VIEW_OPTIONS = [
1722
{
1823
name: 'Old message view',
19-
viewType: 'OLD',
24+
viewType: MsgViewType.OLD,
2025
isEnabled: true,
2126
},
2227
{
2328
name: 'New message view',
24-
viewType: 'NEW',
29+
viewType: MsgViewType.NEW,
2530
isEnabled: true,
2631
},
2732
];

0 commit comments

Comments
 (0)