-
Notifications
You must be signed in to change notification settings - Fork 143
feat: Improve message template view #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
02f95af
feat: Improve message template view
chohongm 3cfb580
remove max 10 items in carousel limitation logic
chohongm df530ab
Remove MessageContentMiddleContainerType
chohongm 0fb7498
update container type logic
chohongm e9719a3
Update template logic to render multiple items even when items contai…
chohongm a52d9f1
Add MessageContentForTemplateMessage
chohongm 24dfd42
minor bug fix
chohongm f3219fd
apply feeds
chohongm 4d57770
remove unused
chohongm cb4f1bc
fix
chohongm f55fb65
Merge branch 'main' into feat/CLNP-4852-improve-message-template-view
chohongm e6d3359
fix
chohongm bf75f44
fix
chohongm 471c7dd
Merge branch 'main' into feat/CLNP-4852-improve-message-template-view
chohongm a4072e2
Update src/ui/MessageContent/index.scss
chohongm 380a591
Update src/ui/MessageContent/index.scss
chohongm 00fafab
Merge branch 'main' into feat/CLNP-4852-improve-message-template-view
chohongm dd4d29d
Merge branch 'main' into feat/CLNP-4852-improve-message-template-view
chohongm 87d2e2b
remove unused
chohongm 07d3cd2
fix bugs
chohongm d011233
fix bugs
chohongm 8260f45
apply feeds
chohongm b388132
update snapshots
chohongm 9e42fba
lock file update
chohongm 7ec3d10
Update src/ui/TemplateMessageItemBody/index.tsx
chohongm 28185c5
apply feeds
chohongm 4be3798
apply feeds
chohongm 3dab003
Update src/ui/MessageContent/index.tsx
chohongm 9252030
Update src/ui/MessageContent/index.tsx
chohongm 412bdf3
rename file
chohongm 7d34767
apply feeds
chohongm 8b20f7b
apply feeds
chohongm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 19 additions & 9 deletions
28
src/modules/Channel/components/Message/hooks/useIsElementInViewport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import React, { useLayoutEffect, useState } from 'react'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
|
||
export const useIsElementInViewport = (elementRef: React.MutableRefObject<any>) => { | ||
export const useIsElementInViewport = (): [React.RefCallback<HTMLDivElement>, boolean] => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
const [element, setElement] = useState(null); | ||
|
||
useLayoutEffect(() => { | ||
const observer = new IntersectionObserver((entries: IntersectionObserverEntry[]) => { | ||
const ref = useCallback((node) => { | ||
if (node !== null) setElement(node); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!element) return; | ||
|
||
const observer = new IntersectionObserver((entries) => { | ||
const [entry] = entries; | ||
if (entry) setIsVisible(entry.isIntersecting); | ||
setIsVisible(entry.isIntersecting); | ||
}); | ||
|
||
if (elementRef.current) observer.observe(elementRef.current); | ||
return () => observer.disconnect(); | ||
}, [elementRef.current]); | ||
observer.observe(element); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}, [element]); | ||
|
||
return isVisible; | ||
return [ref, isVisible]; | ||
}; |
8 changes: 4 additions & 4 deletions
8
src/modules/Channel/components/Message/hooks/useLazyImageLoader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React, { useRef } from 'react'; | ||
import { RefCallback, useRef } from 'react'; | ||
import { useIsElementInViewport } from './useIsElementInViewport'; | ||
|
||
export const useLazyImageLoader = (elementRef: React.MutableRefObject<any>) => { | ||
export const useLazyImageLoader = (): [RefCallback<HTMLDivElement>, boolean] => { | ||
const isLoaded = useRef(false); | ||
const isVisible = useIsElementInViewport(elementRef); | ||
const [ref, isVisible] = useIsElementInViewport(); | ||
|
||
if (isVisible) isLoaded.current = true; | ||
return isLoaded.current; | ||
return [ref, isLoaded.current]; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/ui/MessageContent/MessageContentForTemplateMessage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React, { ReactElement } from 'react'; | ||
import Label, { LabelColors, LabelTypography } from '../Label'; | ||
import { classnames } from '../../utils/utils'; | ||
import format from 'date-fns/format'; | ||
import { MessageTemplateData, TemplateType } from '../TemplateMessageItemBody/types'; | ||
import { MessageComponentRenderers, MessageContentProps } from './index'; | ||
import useSendbirdStateContext from '../../hooks/useSendbirdStateContext'; | ||
import { uiContainerType } from '../../utils'; | ||
import { useLocalization } from '../../lib/LocalizationContext'; | ||
import { MESSAGE_TEMPLATE_KEY } from '../../utils/consts'; | ||
|
||
type MessageContentForTemplateMessageProps = MessageContentProps & MessageComponentRenderers & { | ||
isByMe: boolean; | ||
displayThreadReplies: boolean; | ||
mouseHover: boolean; | ||
isMobile: boolean; | ||
isReactionEnabledInChannel: boolean; | ||
hoveredMenuClassName: string; | ||
templateType: TemplateType | null; | ||
useReplying: boolean; | ||
}; | ||
|
||
export function MessageContentForTemplateMessage(props: MessageContentForTemplateMessageProps): ReactElement { | ||
const { | ||
channel, | ||
message, | ||
showFileViewer, | ||
onMessageHeightChange, | ||
onBeforeDownloadFileMessage, | ||
|
||
renderSenderProfile, | ||
renderMessageHeader, | ||
renderMessageBody, | ||
|
||
isByMe, | ||
displayThreadReplies, | ||
mouseHover, | ||
isMobile, | ||
isReactionEnabledInChannel, | ||
hoveredMenuClassName, | ||
templateType, | ||
useReplying, | ||
} = props; | ||
|
||
const { config } = useSendbirdStateContext(); | ||
const { dateLocale } = useLocalization(); | ||
|
||
const uiContainerTypeClassName = uiContainerType[templateType] ?? ''; | ||
|
||
const senderProfile = renderSenderProfile({ | ||
...props, | ||
chainBottom: false, | ||
className: '', | ||
isByMe, | ||
displayThreadReplies, | ||
}); | ||
const messageHeader = renderMessageHeader(props); | ||
const messageBody = renderMessageBody({ | ||
message, | ||
channel, | ||
showFileViewer, | ||
onMessageHeightChange, | ||
mouseHover, | ||
isMobile, | ||
config, | ||
isReactionEnabledInChannel, | ||
isByMe, | ||
onBeforeDownloadFileMessage, | ||
}); | ||
|
||
const timeStamp = <Label | ||
className={classnames( | ||
'sendbird-message-content__middle__body-container__created-at', | ||
'right', | ||
hoveredMenuClassName, | ||
uiContainerTypeClassName, | ||
)} | ||
type={LabelTypography.CAPTION_3} | ||
color={LabelColors.ONBACKGROUND_2} | ||
> | ||
{format(message?.createdAt || 0, 'p', { | ||
locale: dateLocale, | ||
})} | ||
</Label>; | ||
|
||
const templateData: MessageTemplateData = message.extendedMessagePayload?.[MESSAGE_TEMPLATE_KEY] as MessageTemplateData; | ||
const { profile = true, time = true, nickname = true } = templateData?.container_options ?? {}; | ||
const hasContainerHeader = profile || nickname; | ||
|
||
return ( | ||
<div className="sendbird-message-content__sendbird-ui-container-type__default__root"> | ||
{ | ||
!isByMe | ||
&& hasContainerHeader | ||
&& !useReplying | ||
&& ( | ||
<div className="sendbird-message-content__sendbird-ui-container-type__default__header-container"> | ||
<div | ||
className="sendbird-message-content__sendbird-ui-container-type__default__header-container__left__profile"> | ||
{profile && senderProfile} | ||
</div> | ||
{nickname && messageHeader} | ||
</div> | ||
) | ||
} | ||
{messageBody} | ||
{ | ||
(!isByMe && time) | ||
&& <div className="sendbird-message-content__sendbird-ui-container-type__default__bottom"> | ||
{timeStamp} | ||
</div> | ||
} | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.