Skip to content

Commit

Permalink
[#2009] Fixed unnecessary recalls and rerenders (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten authored Jun 28, 2021
1 parent 2e3763f commit 5164662
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
border-radius: 8px;
background-color: var(--color-background-blue);
.contactDetails {
border-bottom: none;
padding-bottom: 0;
}
}
Expand Down
10 changes: 7 additions & 3 deletions frontend/ui/src/pages/Inbox/ConversationListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ const ConversationListItem = (props: ConversationListItemProps) => {
);
};

useEffect(() => {
const markAsRead = () => {
if (active && unread) {
return readConversations(conversation.id);
readConversations(conversation.id);
}
};

useEffect(() => {
markAsRead();
}, [active, conversation, currentConversationState]);

return (
<div className={styles.clickableListItem} onClick={() => readConversations(conversation.id)}>
<div className={styles.clickableListItem} onClick={markAsRead}>
<Link to={`${INBOX_CONVERSATIONS_ROUTE}/${conversation.id}`}>
<div
className={`${active ? styles.containerListItemActive : styles.containerListItem} ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ const ConversationMetadata = (props: ConnectedProps<typeof connector>) => {
const [displayName, setDisplayName] = useState(conversation.metadata.contact.displayName);

useEffect(() => {
listTags();
setShowEditDisplayName(false);
setDisplayName(conversation.metadata.contact.displayName);
}, [conversation]);

useEffect(() => {
listTags();
}, []);

const showAddTags = () => {
setTagName('');
setShowTagsDialog(true);
Expand Down
3 changes: 2 additions & 1 deletion frontend/ui/src/pages/Inbox/QuickFilter/Popup.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
cursor: pointer;
outline: none;
max-height: 29px;
white-space: nowrap;

svg {
display: inline-block;
Expand All @@ -93,7 +94,7 @@
background: none;
border: 2px solid #bf1a2f;
border-radius: 50%;
margin-right: 2px;
margin-right: 4px;
}

.filterButtonSelected {
Expand Down
4 changes: 2 additions & 2 deletions frontend/ui/src/pages/Inbox/QuickFilter/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ const PopUpFilter = (props: PopUpFilterProps) => {
return (
<DialogCustomizable
close={closeCallback}
style={{marginTop: '10px'}}
style={{marginTop: '20px', left: '0px', marginLeft: '215px'}}
coverStyle={{backgroundColor: 'rgba(247,247,247,0.7)'}}>
<div className={styles.content}>
<div id="dialogContent" className={styles.content}>
<div className={styles.filterColumn}>
<div className={styles.filterStateContainer}>
<div className={styles.filterItem}>
Expand Down
27 changes: 19 additions & 8 deletions lib/typescript/render/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ const fallbackAvatarImage = (event: SyntheticEvent<HTMLImageElement, Event>) =>
event.currentTarget.alt = 'fallback avatar';
};

export const Avatar = ({contact}: AvatarProps) => (
<img
alt={contact?.displayName || 'Unknown contact'}
className={styles.avatarImage}
src={contact?.avatarUrl || fallbackAvatar}
onError={(event: React.SyntheticEvent<HTMLImageElement, Event>) => fallbackAvatarImage(event)}
/>
);
const AvatarComponent = ({contact}: AvatarProps) => {
return (
<img
alt={contact?.displayName || 'Unknown contact'}
className={styles.avatarImage}
src={contact?.avatarUrl || fallbackAvatar}
onError={(event: React.SyntheticEvent<HTMLImageElement, Event>) => fallbackAvatarImage(event)}
/>
);
};

const areEqual = (prevProps, nextProps) => {
if (prevProps.contact.avatarUrl === nextProps.contact.avatarUrl) {
return true;
}
return false;
};

export const Avatar = React.memo(AvatarComponent, areEqual);

0 comments on commit 5164662

Please sign in to comment.