2
0

feat(engine): 💄 Hide avatar if not last block

This commit is contained in:
Baptiste Arnaud
2022-05-17 13:28:33 -07:00
parent d9e273b008
commit 0de0d128b3
3 changed files with 10 additions and 3 deletions

View File

@ -10,10 +10,10 @@ import { Avatar } from '../avatars/Avatar'
import { useFrame } from 'react-frame-component'
import { CSSTransition } from 'react-transition-group'
type Props = { hostAvatarSrc?: string }
type Props = { hostAvatarSrc?: string; keepShowing: boolean }
export const AvatarSideContainer = forwardRef(
({ hostAvatarSrc }: Props, ref: ForwardedRef<unknown>) => {
({ hostAvatarSrc, keepShowing }: Props, ref: ForwardedRef<unknown>) => {
const { document } = useFrame()
const [show, setShow] = useState(false)
const [avatarTopOffset, setAvatarTopOffset] = useState(0)
@ -49,7 +49,7 @@ export const AvatarSideContainer = forwardRef(
<CSSTransition
classNames="bubble"
timeout={500}
in={show}
in={show && keepShowing}
unmountOnExit
>
<div

View File

@ -25,6 +25,7 @@ type ChatBlockProps = {
steps: Step[]
startStepIndex: number
blockTitle: string
keepShowingHostAvatar: boolean
onScroll: () => void
onBlockEnd: (
edgeId?: string,
@ -40,6 +41,7 @@ export const ChatBlock = ({
blockTitle,
onScroll,
onBlockEnd,
keepShowingHostAvatar,
}: ChatBlockProps) => {
const {
currentTypebotId,
@ -188,6 +190,7 @@ export const ChatBlock = ({
}}
hasGuestAvatar={typebot.theme.chat.guestAvatar?.isEnabled ?? false}
onDisplayNextStep={displayNextStep}
keepShowingHostAvatar={keepShowingHostAvatar}
/>
))}
</div>
@ -199,12 +202,14 @@ type Props = {
displayChunk: ChatDisplayChunk
hostAvatar: { isEnabled: boolean; src?: string }
hasGuestAvatar: boolean
keepShowingHostAvatar: boolean
onDisplayNextStep: (answerContent?: string, isRetry?: boolean) => void
}
const ChatChunks = ({
displayChunk: { bubbles, input },
hostAvatar,
hasGuestAvatar,
keepShowingHostAvatar,
onDisplayNextStep,
}: Props) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -224,6 +229,7 @@ const ChatChunks = ({
<AvatarSideContainer
ref={avatarSideContainerRef}
hostAvatarSrc={hostAvatar.src}
keepShowing={keepShowingHostAvatar || isDefined(input)}
/>
)}
<div

View File

@ -112,6 +112,7 @@ export const ConversationContainer = ({
onScroll={autoScrollToBottom}
onBlockEnd={displayNextBlock}
blockTitle={displayedBlock.block.title}
keepShowingHostAvatar={idx === displayedBlocks.length - 1}
/>
))}
{/* We use a block to simulate padding because it makes iOS scroll flicker */}