Skip to content

Commit

Permalink
fix: Fix markdown lazy load preview message background color (#401)
Browse files Browse the repository at this point in the history
## Changes
- Fixed markdown lazy load preview message background color

ticket: [AC-4525]

## Additional Notes
- 

## Checklist
Before requesting a code review, please check the following:
- [ ] **[Required]** CI has passed all checks.
- [ ] **[Required]** A self-review has been conducted to ensure there
are no minor mistakes.
- [ ] **[Required]** Unnecessary comments/debugging code have been
removed.
- [ ] **[Required]** All requirements specified in the ticket have been
accurately implemented.
- [ ] Ensure the ticket has been updated with the sprint, status, and
story points.


[AC-4525]:
https://sendbird.atlassian.net/browse/AC-4525?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
liamcho authored Dec 12, 2024
1 parent 790ce35 commit bc82954
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 29 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 15 additions & 14 deletions src/components/ParsedBotMessageBody.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { css } from '@linaria/core';
import { lazy, Suspense } from 'react';
import styled from 'styled-components';

Expand All @@ -12,13 +13,17 @@ type Props = {
sources?: Source[];
};

const TextContainer = styled.div`
width: inherit;
text-align: start;
const textContainerStyle = css`
word-break: break-word;
padding: 8px 12px;
gap: 12px;
white-space: pre-wrap;
padding: 0 12px; // apply side padding of the bubble
`;

const Container = styled.div`
padding: 8px 0; // Bubble top and bottom padding. Side padding is applied for token containers.
border-radius: 16px;
overflow: auto;
background-color: ${({ theme }) => theme.bgColor.incomingMessage};
`;

/**
Expand All @@ -30,14 +35,10 @@ export default function ParsedBotMessageBody(props: Props) {
const { text, tokens, sources } = props;

return (
<Suspense
fallback={
<TextContainer className="sendbird-word" style={{ borderRadius: 16 }}>
{text}
</TextContainer>
}
>
<TokensBody tokens={tokens} sources={sources} />
</Suspense>
<Container>
<Suspense fallback={<div className={textContainerStyle}>{text}</div>}>
<TokensBody className={textContainerStyle} tokens={tokens} sources={sources} />
</Suspense>
</Container>
);
}
17 changes: 6 additions & 11 deletions src/components/TokensBody.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cx } from '@linaria/core';
import DOMPurify from 'dompurify';
import Markdown from 'markdown-to-jsx';
import styled from 'styled-components';
Expand All @@ -13,6 +14,7 @@ import './markdown.scss';
type TokensBodyProps = {
tokens: Token[];
sources?: Source[];
className?: string;
};

const BlockContainer = styled.div`
Expand All @@ -24,23 +26,16 @@ const BlockContainer = styled.div`
margin: 0.5em 0;
`;

const MultipleTokenTypeContainer = styled.div`
padding: 8px 0; // Bubble top and bottom padding. Side padding is applied for token containers.
border-radius: 16px;
overflow: auto;
background-color: ${({ theme }) => theme.bgColor.incomingMessage};
`;

export default function TokensBody({ tokens, sources }: TokensBodyProps) {
export default function TokensBody({ tokens, sources, className }: TokensBodyProps) {
const { enableSourceMessage } = useConstantState();

return (
<MultipleTokenTypeContainer className="sendbird-word">
<>
{tokens.map((token: Token, i) => {
// Normal text part of the message.
if (token.type === TokenType.string) {
return (
<div key={i} className="widget-markdown">
<div key={i} className={cx(className, 'widget-markdown')}>
<Markdown
options={{
sanitizer: (value: string) => {
Expand Down Expand Up @@ -95,6 +90,6 @@ export default function TokensBody({ tokens, sources }: TokensBodyProps) {
<BotMessageBottom />
</div>
) : null}
</MultipleTokenTypeContainer>
</>
);
}
4 changes: 0 additions & 4 deletions src/components/markdown.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.widget-markdown {
padding: 0 12px; /* apply side padding of the bubble */
}

.widget-markdown * {
color: var(--sb-on-content-inverse-1);
}
Expand Down

0 comments on commit bc82954

Please sign in to comment.