refactor: replying image display

This commit is contained in:
zerosoul
2022-06-07 21:43:37 +08:00
parent 06da664e05
commit b0b6c5f8e3
2 changed files with 15 additions and 9 deletions
+1
View File
@@ -98,6 +98,7 @@ const renderContent = (data) => {
<span className="txt"> <span className="txt">
{reactStringReplace( {reactStringReplace(
content, content,
// eslint-disable-next-line no-useless-escape
/(\s{1}\@[0-9]+\s{1})/g, /(\s{1}\@[0-9]+\s{1})/g,
(match, idx) => { (match, idx) => {
console.log("match", match); console.log("match", match);
+14 -9
View File
@@ -35,15 +35,17 @@ const Styled = styled.div`
} }
.content { .content {
white-space: normal; white-space: normal;
height: 20px;
/* overflow-y: hidden; */
color: #616161; color: #616161;
overflow: hidden; overflow: hidden;
/* text-overflow: ellipsis; */
padding-right: 30px; padding-right: 30px;
font-weight: 500; font-weight: 500;
font-size: 14px; font-size: 14px;
line-height: 20px; line-height: 20px;
> .pic {
width: 50px;
height: 50px;
object-fit: cover;
}
.md { .md {
position: relative; position: relative;
max-height: 100px; max-height: 100px;
@@ -81,7 +83,7 @@ const Styled = styled.div`
} }
`; `;
const renderContent = (data) => { const renderContent = (data) => {
const { content_type, content, properties } = data; const { content_type, content, thumbnail = "", properties } = data;
let res = null; let res = null;
switch (content_type) { switch (content_type) {
case ContentTypes.text: case ContentTypes.text:
@@ -105,8 +107,10 @@ const renderContent = (data) => {
case ContentTypes.file: case ContentTypes.file:
{ {
const { content_type, name, size } = properties; const { content_type, name, size } = properties;
if (isImage(content_type, size)) { const image = isImage(content_type, size);
res = <img className="pic" src={pictureIcon} />; // console.log("replying data", content_type, size, image);
if (image) {
res = <img className="pic" src={thumbnail || pictureIcon} />;
} else { } else {
const icon = getFileIcon(content_type, name); const icon = getFileIcon(content_type, name);
res = ( res = (
@@ -121,6 +125,7 @@ const renderContent = (data) => {
default: default:
break; break;
} }
// console.log("replying data", data);
return res; return res;
}; };
export default function Replying({ context, id, mid }) { export default function Replying({ context, id, mid }) {
@@ -136,10 +141,10 @@ export default function Replying({ context, id, mid }) {
const user = contactsData[from_uid]; const user = contactsData[from_uid];
return ( return (
<Styled className="reply"> <Styled className="reply">
<span className="prefix"> <div className="prefix">
Replying to <em>{user?.name}</em> Replying to <em>{user?.name}</em>
</span> </div>
<span className="content">{renderContent(msg)}</span> <div className="content">{renderContent(msg)}</div>
<button className="close" onClick={removeReply}> <button className="close" onClick={removeReply}>
<img src={closeIcon} alt="close icon" /> <img src={closeIcon} alt="close icon" />
</button> </button>