feat(engine): 💄 Hide avatar if not last block
This commit is contained in:
@@ -10,10 +10,10 @@ import { Avatar } from '../avatars/Avatar'
|
|||||||
import { useFrame } from 'react-frame-component'
|
import { useFrame } from 'react-frame-component'
|
||||||
import { CSSTransition } from 'react-transition-group'
|
import { CSSTransition } from 'react-transition-group'
|
||||||
|
|
||||||
type Props = { hostAvatarSrc?: string }
|
type Props = { hostAvatarSrc?: string; keepShowing: boolean }
|
||||||
|
|
||||||
export const AvatarSideContainer = forwardRef(
|
export const AvatarSideContainer = forwardRef(
|
||||||
({ hostAvatarSrc }: Props, ref: ForwardedRef<unknown>) => {
|
({ hostAvatarSrc, keepShowing }: Props, ref: ForwardedRef<unknown>) => {
|
||||||
const { document } = useFrame()
|
const { document } = useFrame()
|
||||||
const [show, setShow] = useState(false)
|
const [show, setShow] = useState(false)
|
||||||
const [avatarTopOffset, setAvatarTopOffset] = useState(0)
|
const [avatarTopOffset, setAvatarTopOffset] = useState(0)
|
||||||
@@ -49,7 +49,7 @@ export const AvatarSideContainer = forwardRef(
|
|||||||
<CSSTransition
|
<CSSTransition
|
||||||
classNames="bubble"
|
classNames="bubble"
|
||||||
timeout={500}
|
timeout={500}
|
||||||
in={show}
|
in={show && keepShowing}
|
||||||
unmountOnExit
|
unmountOnExit
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type ChatBlockProps = {
|
|||||||
steps: Step[]
|
steps: Step[]
|
||||||
startStepIndex: number
|
startStepIndex: number
|
||||||
blockTitle: string
|
blockTitle: string
|
||||||
|
keepShowingHostAvatar: boolean
|
||||||
onScroll: () => void
|
onScroll: () => void
|
||||||
onBlockEnd: (
|
onBlockEnd: (
|
||||||
edgeId?: string,
|
edgeId?: string,
|
||||||
@@ -40,6 +41,7 @@ export const ChatBlock = ({
|
|||||||
blockTitle,
|
blockTitle,
|
||||||
onScroll,
|
onScroll,
|
||||||
onBlockEnd,
|
onBlockEnd,
|
||||||
|
keepShowingHostAvatar,
|
||||||
}: ChatBlockProps) => {
|
}: ChatBlockProps) => {
|
||||||
const {
|
const {
|
||||||
currentTypebotId,
|
currentTypebotId,
|
||||||
@@ -188,6 +190,7 @@ export const ChatBlock = ({
|
|||||||
}}
|
}}
|
||||||
hasGuestAvatar={typebot.theme.chat.guestAvatar?.isEnabled ?? false}
|
hasGuestAvatar={typebot.theme.chat.guestAvatar?.isEnabled ?? false}
|
||||||
onDisplayNextStep={displayNextStep}
|
onDisplayNextStep={displayNextStep}
|
||||||
|
keepShowingHostAvatar={keepShowingHostAvatar}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -199,12 +202,14 @@ type Props = {
|
|||||||
displayChunk: ChatDisplayChunk
|
displayChunk: ChatDisplayChunk
|
||||||
hostAvatar: { isEnabled: boolean; src?: string }
|
hostAvatar: { isEnabled: boolean; src?: string }
|
||||||
hasGuestAvatar: boolean
|
hasGuestAvatar: boolean
|
||||||
|
keepShowingHostAvatar: boolean
|
||||||
onDisplayNextStep: (answerContent?: string, isRetry?: boolean) => void
|
onDisplayNextStep: (answerContent?: string, isRetry?: boolean) => void
|
||||||
}
|
}
|
||||||
const ChatChunks = ({
|
const ChatChunks = ({
|
||||||
displayChunk: { bubbles, input },
|
displayChunk: { bubbles, input },
|
||||||
hostAvatar,
|
hostAvatar,
|
||||||
hasGuestAvatar,
|
hasGuestAvatar,
|
||||||
|
keepShowingHostAvatar,
|
||||||
onDisplayNextStep,
|
onDisplayNextStep,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -224,6 +229,7 @@ const ChatChunks = ({
|
|||||||
<AvatarSideContainer
|
<AvatarSideContainer
|
||||||
ref={avatarSideContainerRef}
|
ref={avatarSideContainerRef}
|
||||||
hostAvatarSrc={hostAvatar.src}
|
hostAvatarSrc={hostAvatar.src}
|
||||||
|
keepShowing={keepShowingHostAvatar || isDefined(input)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ export const ConversationContainer = ({
|
|||||||
onScroll={autoScrollToBottom}
|
onScroll={autoScrollToBottom}
|
||||||
onBlockEnd={displayNextBlock}
|
onBlockEnd={displayNextBlock}
|
||||||
blockTitle={displayedBlock.block.title}
|
blockTitle={displayedBlock.block.title}
|
||||||
|
keepShowingHostAvatar={idx === displayedBlocks.length - 1}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{/* We use a block to simulate padding because it makes iOS scroll flicker */}
|
{/* We use a block to simulate padding because it makes iOS scroll flicker */}
|
||||||
|
|||||||
Reference in New Issue
Block a user