Skip to content

Commit

Permalink
Removed window resize listener
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaPrahoveanu-SL committed Nov 22, 2024
1 parent 9495400 commit b582371
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
6 changes: 0 additions & 6 deletions frontend/src/components/message.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.container {
align-items: center;
display: flex;
flex-direction: row;
justify-content: left;
Expand Down Expand Up @@ -33,8 +32,3 @@
line-height: 22px;
font-size: 16px;
}

.messageStyle.single-line {
margin-top: 0;
margin-bottom: 0;
}
28 changes: 2 additions & 26 deletions frontend/src/components/message.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, { useMemo } from 'react';
import styles from './message.module.css';
import UserIcon from '../icons/account-circle.svg';
import BotIcon from '../icons/logomark.svg';
Expand Down Expand Up @@ -40,34 +40,10 @@ export const MessageComponent = ({ message }: MessageProps) => {

const { class: roleClass, icon } = useMemo(() => roleStyleMap[role], [role]);

const messageRef = useRef<HTMLParagraphElement>(null);
const [isSingleLine, setIsSingleLine] = useState(false);

const checkSingleLine = () => {
if (messageRef.current) {
const singleLineHeight = 22;
const actualHeight = messageRef.current.offsetHeight;
setIsSingleLine(actualHeight <= singleLineHeight);
}
};

useEffect(() => {
checkSingleLine();
window.addEventListener('resize', checkSingleLine);
return () => {
window.removeEventListener('resize', checkSingleLine);
};
}, [content]);

return (
<div className={classNames(styles.container, roleClass)}>
<img src={icon} className={styles.iconStyle} />
<p
ref={messageRef}
className={classNames(styles.messageStyle, {
[styles['single-line']]: isSingleLine,
})}
>
<p className={styles.messageStyle}>
{content}
</p>
</div>
Expand Down

0 comments on commit b582371

Please sign in to comment.