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 my message component #8

Merged
merged 13 commits into from
Nov 8, 2021
Merged

Feat: add my message component #8

merged 13 commits into from
Nov 8, 2021

Conversation

alamorre
Copy link
Contributor

@alamorre alamorre commented Nov 7, 2021

No description provided.

Copy link
Contributor

@dhavelock dhavelock left a comment

Choose a reason for hiding this comment

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

looks goodddd just one comment

Comment on lines 24 to 31
const topRightRadius =
!lastMessage || lastMessage.sender_username !== message.sender_username
? '1.3em'
: '0.3em';
const bottomRightRadius =
!nextMessage || nextMessage.sender_username !== message.sender_username
? '1.3em'
: '0.3em';
Copy link
Contributor

Choose a reason for hiding this comment

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

some repeated logic- maybe create a helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is a bit different, I typically enforce a refactor 3 or more times.

~1.5 times is typically fine with me

Copy link
Contributor

Choose a reason for hiding this comment

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

ya I also find giving something a name makes the code easier to read but will leave up to you


setConfiguration({ maxScreenClass: 'xl' });

export const MyMessage: React.FC<Props> = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

thinking ahead to TheirMessage - I'm thinking that there will be some logic that can be shared between the two e.g. renderFiles, renderImages, renderReads

idk how it's done in typescript but in Java we would use an Abstract Class for a base Message class then have MyMessage and TheirMessage extend it

at the very least they can be helper functions that both classes have access to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah and good catch, the new ImageThumb and FileThumb are refactored in now.

I'm going to pick this apart a bit more tomorrow, I think it can be a bit better.

@alamorre
Copy link
Contributor Author

alamorre commented Nov 7, 2021

Oh FYI I'm not done. There is quite a bit I'm gonna clean before doing the review.

I just have a habit of pushing and making the PR early lol

@github-actions
Copy link

github-actions bot commented Nov 8, 2021

size-limit report 📦

Path Size
dist/react-chat-engine-components.cjs.production.min.js 162 B (0%)
dist/react-chat-engine-components.esm.js 25 B (0%)

@dhavelock
Copy link
Contributor

Oh FYI I'm not done. There is quite a bit I'm gonna clean before doing the review.

I just have a habit of pushing and making the PR early lol

ahhh all good- just lmk when it's ready for review

@alamorre
Copy link
Contributor Author

alamorre commented Nov 8, 2021

I think it's ready for v1 review now

first_name: string | null;
last_name: string | null;
avatar: string | null;
custom_json: string | object | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

what is custom_json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom JSON is a Chat Engine feature https://www.youtube.com/watch?v=EcC6fA2Umn8&t=2s

created: string;
}
export interface MessageProps {
id?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

id is optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I got some time after work to do this 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah so when the last_message attribute in a chat objects may not have an ID if the message is blank.

This is something we can patch with the API later but now it's optional

Comment on lines +47 to +85
const renderImages = () => {
const attachments =
message && message.attachments ? message.attachments : [];

return attachments.map((attachment, index) => {
const fileName = getFileName(attachment.file);

if (isImage(fileName)) {
return (
<ImageThumb
attachment={attachment}
isLoading={isSending || attachment.file === null}
/>
);
}

return <div key={`attachment${index}`} />;
});
};

const renderFiles = () => {
const attachments =
message && message.attachments ? message.attachments : [];

return attachments.map((attachment, index) => {
const fileName = getFileName(attachment.file);

if (!isImage(fileName)) {
return (
<FileThumb
attachment={attachment}
isLoading={isSending || attachment.file === null}
/>
);
}

return <div key={`attachment${index}`} />;
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this could be combined to a renderAttachments function instead of looping over the list of attachments twice you could just do if/else on the isImage and do it all in one go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I got some time after work to do this 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually wait there's a good reason for this too: Basically we want all the images rendered, then all the Files rendered. If we do it all in one loop then the files/images render in a mixed order which we don't want UI wise

@alamorre alamorre merged commit c5ee8f7 into main Nov 8, 2021
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.

2 participants