Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Display 'Unread Message' Divider Functionality Similar to RC #766

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/react/src/views/ChatBody/ChatBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ChatBody = ({
const [, setIsUserScrolledUp] = useState(false);
const [otherUserMessage, setOtherUserMessage] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const firstUnreadMessageIdRef = useRef('');
const { RCInstance, ECOptions } = useContext(RCContext);
const showAnnouncement = ECOptions?.showAnnouncement;
const messages = useMessageStore((state) => state.messages);
Expand Down Expand Up @@ -117,7 +118,13 @@ const ChatBody = ({
const isScrolledUp = messageListRef?.current?.scrollTop !== 0;
if (isScrolledUp && !('pinned' in message) && !('starred' in message)) {
setOtherUserMessage(true);

if (firstUnreadMessageIdRef.current === '') {
firstUnreadMessageIdRef.current = message._id;
}
}
} else {
firstUnreadMessageIdRef.current = '';
}
upsertMessage(message, ECOptions?.enableThreads);
},
Expand Down Expand Up @@ -180,6 +187,7 @@ const ChatBody = ({
setPopupVisible(false);
setIsUserScrolledUp(false);
setOtherUserMessage(false);
firstUnreadMessageIdRef.current = '';
}
}, [
messageListRef,
Expand Down Expand Up @@ -292,7 +300,10 @@ const ChatBody = ({
threadMessages={threadMessages}
/>
) : (
<MessageList messages={messages} />
<MessageList
messages={messages}
firstUnreadMessageId={firstUnreadMessageIdRef.current}
/>
)}

<TotpModal handleLogin={handleLogin} />
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/views/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import useFetchChatData from '../../hooks/useFetchChatData';

const Message = ({
message,
firstUnreadMessageId,
type = 'default',
sequential = false,
lastSequential = false,
Expand Down Expand Up @@ -338,6 +339,9 @@ const Message = ({
{format(new Date(message.ts), 'MMMM d, yyyy')}
</MessageDivider>
)}
{message._id === firstUnreadMessageId ? (
<MessageDivider unreadLabel="unread messages" />
) : null}
</>
);
};
Expand Down
38 changes: 37 additions & 1 deletion packages/react/src/views/Message/Message.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const MessageBodyStyles = {
`,
};

export const getMessageDividerStyles = (theme) => {
export const getMessageDividerStyles = (theme, mode) => {
const styles = {
divider: css`
letter-spacing: 0rem;
Expand Down Expand Up @@ -107,6 +107,42 @@ export const getMessageDividerStyles = (theme) => {
height: 1px;
background-color: ${theme.colors.secondary};
`,

unreadDivider: css`
letter-spacing: 0rem;
font-size: 0.75rem;
font-weight: 700;
line-height: 1rem;
position: relative;
display: flex;
z-index: 1000;
align-items: center;
padding-left: 1.25rem;
padding-right: 1.25rem;
@media (max-width: 780px) {
z-index: 1;
}
`,

unreadDividerContent: css`
color: ${mode === 'light'
? theme.colors.destructive
: theme.colors.warningForeground};
font-size: 0.875rem;
font-weight: 750;
margin-left: 10px;
`,

unreadBar: css`
display: flex;
justify-content: flex-end;
align-items: center;
flex-grow: 1;
height: 0.7px;
background-color: ${mode === 'light'
? theme.colors.destructive
: theme.colors.warningForeground};
`,
};

return styles;
Expand Down
56 changes: 40 additions & 16 deletions packages/react/src/views/Message/MessageDivider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,50 @@ export const MessageDivider = ({
style
);
const { theme } = useTheme();
const styles = getMessageDividerStyles(theme);
const { mode } = useTheme();
const styles = getMessageDividerStyles(theme, mode);

const isUnread = unreadLabel !== undefined;

return (
<Box
role="separator"
css={styles.divider}
className={appendClassNames('ec-message-divider', classNames)}
style={styleOverrides}
{...props}
>
{children && (
<>
<Box css={styles.bar} className="ec-message-divider-bar" />
<>
{isUnread ? (
<Box
role="separator"
css={styles.unreadDivider}
className={appendClassNames('ec-message-divider', classNames)}
style={styleOverrides}
{...props}
>
<Box css={styles.unreadBar} className="ec-message-divider-bar" />
<Box
css={styles.dividerContent}
css={styles.unreadDividerContent}
className="ec-message-divider-content"
>
{children}
</Box>{' '}
</>
{unreadLabel}
</Box>
</Box>
) : (
<Box
role="separator"
css={styles.divider}
className={appendClassNames('ec-message-divider', classNames)}
style={styleOverrides}
{...props}
>
{children && (
<>
<Box css={styles.bar} className="ec-message-divider-bar" />
<Box
css={styles.dividerContent}
className="ec-message-divider-content"
>
{children}
</Box>
</>
)}
</Box>
)}
</Box>
</>
);
};
3 changes: 2 additions & 1 deletion packages/react/src/views/MessageList/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import isMessageSequential from '../../lib/isMessageSequential';
import { Message } from '../Message';
import isMessageLastSequential from '../../lib/isMessageLastSequential';

const MessageList = ({ messages }) => {
const MessageList = ({ messages, firstUnreadMessageId }) => {
const showReportMessage = useMessageStore((state) => state.showReportMessage);
const messageToReport = useMessageStore((state) => state.messageToReport);
const isMessageLoaded = useMessageStore((state) => state.isMessageLoaded);
Expand Down Expand Up @@ -48,6 +48,7 @@ const MessageList = ({ messages }) => {
return (
<Message
key={msg._id}
firstUnreadMessageId={firstUnreadMessageId}
message={msg}
newDay={newDay}
sequential={sequential}
Expand Down
Loading