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: add today message divider #67

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

varshamenon4
Copy link
Member

@varshamenon4 varshamenon4 commented Nov 18, 2024

COSMO-544

This PR adds the Today message divider which divides old and new messages. See screenshot below:

Screenshot 2024-11-21 at 8 16 00 AM

Copy link
Member Author

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to add tests and make a little prettier but looking for initial feedback to make sure I'm on the right track! Ty!

src/components/ChatBox/index.jsx Outdated Show resolved Hide resolved
Copy link
Member Author

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes based on initial feedback and also added tests. Also realized that my timestamp / today check wasn't actually working so updated that as well.

src/components/ChatBox/index.test.jsx Outdated Show resolved Hide resolved

// container for all of the messages
const ChatBox = ({ chatboxContainerRef }) => {
const { messageList, apiIsLoading } = useSelector(state => state.learningAssistant);
const messagesBeforeToday = messageList.filter((m) => (!isToday(new Date(m.timestamp))));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the logic here to ensure that the divider only shows for the conditions below.

@alangsto
Copy link
Member

One question (and maybe this could be cleared up in a demo), but the image included in the PR shows that the last message is hidden behind the message text field. Is the auto scroll behavior not working as expected now? I would expect the message to not be hidden behind the field. Thanks!

@varshamenon4
Copy link
Member Author

One question (and maybe this could be cleared up in a demo), but the image included in the PR shows that the last message is hidden behind the message text field. Is the auto scroll behavior not working as expected now? I would expect the message to not be hidden behind the field. Thanks!

@alangsto ah yes! This is just because I had to scroll up to see the divider. It does still auto scroll as expected. Happy to demo to show how it works or even just add a screenshare.

Copy link
Member

@alangsto alangsto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit and a suggestion for debugging! Otherwise this approach looks good to me

@varshamenon4 varshamenon4 force-pushed the varshamenon4/feat-add-old-message-divider branch from 0db591c to baa26ef Compare November 22, 2024 02:05
Copy link
Member

@rijuma rijuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a comment as a question. LGTM if the question is irrelevant.

@@ -3,15 +3,34 @@ import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import Message from '../Message';
import './ChatBox.scss';
import MessageDivider from '../MessageDivider';

function isToday(date) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a blocking feedback. That said, why can't a open source library like moment.js help you here?

Copy link
Member

@rijuma rijuma Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, I'm not fully agree on adding a library to the bundle and dependencies just for something trivial, but I understand the point.

If we don't add the dependency, we might want to compare dates as strings to make it a bit simpler.

const now = new Date()
const isToday = (now.toDateString() === otherDate.toDateString());

Just leaving it as an alternative.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you both! So part of the issue with comparing the dates as strings is that these are timestamps. So I would need to extract the date only first and compare those strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simon, to your point, I did look in frontend-app-learning to see if something similar was implemented and I did see this: https://github.com/openedx/frontend-app-learning/blob/master/src/course-home/dates-tab/utils.jsx. I wonder if there was a reason that we didn't just use another library there; I wonder if for a similar reason as what Marcos suggested?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how custom code proliferate. Some engineer think the custom code at that time is a good idea, then it gets accepted. Others later would find it to be acceptable too. I get it. This is why my question here is not a blocking feedback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I'll do some quick research on moment.js and make the call soon to merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so I went to moment.js and see an article suggesting more modern alternatives: https://momentjs.com/. Maybe for times sake I'll move forward as is though this isn't the ideal. Thanks for the feedback in any case.

@varshamenon4 varshamenon4 force-pushed the varshamenon4/feat-add-old-message-divider branch from 1b16b12 to d5019ab Compare November 22, 2024 19:41
@varshamenon4 varshamenon4 merged commit 455345e into main Nov 22, 2024
4 checks passed
@varshamenon4 varshamenon4 deleted the varshamenon4/feat-add-old-message-divider branch November 22, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants