Refactor chat messages (#151)

This commit is contained in:
Szymon Szlachtowicz 2021-12-09 14:38:29 +01:00 committed by GitHub
parent c06ea9cca0
commit 032d9ae471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 21 deletions

View File

@ -29,6 +29,37 @@ import { ChatMessageContent } from "./ChatMessageContent";
const today = new Date(); const today = new Date();
function calcHeight(quote: ChatMessage) {
if (quote.image && quote.content) {
return 88;
} else if (quote.image && !quote.content) {
return 68;
} else {
return 25;
}
}
type MessageQuoteProps = {
quote: ChatMessage | undefined;
};
function MessageQuote({ quote }: MessageQuoteProps) {
if (quote) {
return (
<QuoteWrapper>
<QuoteSvg width={22} height={calcHeight(quote)} />
<QuoteSender>
{" "}
<UserIcon memberView={true} /> {quote.sender}
</QuoteSender>
<Quote>{quote.content}</Quote>
{quote.image && <QuoteImage src={quote.image} />}
</QuoteWrapper>
);
}
return null;
}
type ChatUiMessageProps = { type ChatUiMessageProps = {
idx: number; idx: number;
message: ChatMessage; message: ChatMessage;
@ -98,28 +129,8 @@ function ChatUiMessage({
: message.date.toLocaleDateString()} : message.date.toLocaleDateString()}
</DateSeparator> </DateSeparator>
)} )}
<MessageWrapper className={`${mentioned && "mention"}`}> <MessageWrapper className={`${mentioned && "mention"}`}>
{quote && ( <MessageQuote quote={quote} />
<QuoteWrapper>
<QuoteSvg
width={22}
height={
quote.image && quote.content
? 88
: quote.image && !quote.content
? 68
: 25
}
/>
<QuoteSender>
{" "}
<UserIcon memberView={true} /> {quote.sender}
</QuoteSender>
<Quote>{quote.content}</Quote>
{quote.image && <QuoteImage src={quote.image} />}
</QuoteWrapper>
)}
<UserMessageWrapper> <UserMessageWrapper>
<Icon <Icon
onClick={() => { onClick={() => {