Skip to content

Commit b97cffa

Browse files
committed
minor: fix latte actions preview animation
1 parent e8b8c57 commit b97cffa

File tree

3 files changed

+55
-50
lines changed

3 files changed

+55
-50
lines changed

apps/web/src/components/LatteChat/_components/ChatInteraction/CollapsedInteractionSteps.tsx

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,46 @@
1-
import { useState, useEffect, useRef } from 'react'
1+
import { useState, useEffect } from 'react'
22
import { LatteInteractionStep } from '$/hooks/latte/types'
33
import { InteractionStep } from './InteractionStep'
4-
import { cn } from '@latitude-data/web-ui/utils'
4+
5+
const STEP_LINE_HEIGHT = 1.25 // rem
56

67
export const CollapsedInteractionSteps = ({
78
steps,
9+
isLoading = false,
810
}: {
911
steps: LatteInteractionStep[]
12+
isLoading?: boolean
1013
}) => {
11-
const [displayedItem, setDisplayedItem] = useState<'last' | 'previous'>(
12-
'last',
13-
)
14-
const isFirstRender = useRef(true)
14+
const [currentLine, setCurrentLine] = useState(0)
1515

1616
useEffect(() => {
17-
if (isFirstRender.current) {
18-
isFirstRender.current = false
19-
return
20-
}
21-
22-
if (steps.length === 0) return
23-
24-
setDisplayedItem('previous')
25-
setTimeout(() => {
26-
setDisplayedItem('last')
27-
}, 1) // Delay to allow the transition to take effect
17+
setCurrentLine(steps.length) // +1 for the initial thinking step
18+
console.log('current line =', steps.length)
2819
}, [steps.length])
2920

3021
return (
3122
<div className='w-full relative overflow-hidden h-6 leading-6'>
3223
<div
33-
className={cn('absolute inset-x-0 top-0 transform', {
34-
'transition-transform duration-500 ease-in-out':
35-
displayedItem === 'last',
36-
37-
'-translate-y-full': displayedItem === 'last',
38-
'translate-y-0': displayedItem === 'previous',
39-
})}
40-
>
41-
<InteractionStep
42-
key={steps.length - 2}
43-
step={steps[steps.length - 2]}
44-
singleLine
45-
/>
46-
</div>
47-
48-
<div
49-
className={cn('absolute inset-x-0 top-0 transform', {
50-
'transition-transform duration-500 ease-in-out':
51-
displayedItem === 'last',
52-
53-
'translate-y-0': displayedItem === 'last',
54-
'translate-y-full': displayedItem === 'previous',
55-
})}
24+
className='absolute inset-x-0 transition-transform duration-500 ease-in-out flex flex-col justify-center'
25+
style={{
26+
transform: `translateY(-${currentLine * STEP_LINE_HEIGHT}rem)`,
27+
}}
5628
>
29+
{/* Thinking step*/}
5730
<InteractionStep
58-
key={steps.length - 1}
59-
step={steps[steps.length - 1]}
31+
key={-1}
32+
step={undefined}
33+
isLoading={isLoading}
6034
singleLine
61-
/>
35+
/>{' '}
36+
{steps.map((step, index) => (
37+
<InteractionStep
38+
key={index}
39+
step={step}
40+
isLoading={isLoading && index === steps.length - 1}
41+
singleLine
42+
/>
43+
))}
6244
</div>
6345
</div>
6446
)

apps/web/src/components/LatteChat/_components/ChatInteraction/InteractionStep.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { Text } from '@latitude-data/web-ui/atoms/Text'
66
export function InteractionStep({
77
step,
88
singleLine,
9+
isLoading = false,
910
}: {
1011
step?: LatteInteractionStep
1112
singleLine?: boolean
13+
isLoading?: boolean
1214
}) {
1315
if (!step) {
1416
return (
@@ -30,25 +32,34 @@ export function InteractionStep({
3032
noWrap={singleLine}
3133
ellipsis={singleLine}
3234
whiteSpace='preWrap'
35+
animate={isLoading}
3336
>
3437
{step.content}
3538
</Text.H5>
3639
)
3740
}
3841

3942
if (step.type === 'action') {
40-
return <EditActionStep step={step} singleLine={singleLine} />
43+
return (
44+
<EditActionStep
45+
step={step}
46+
singleLine={singleLine}
47+
isLoading={isLoading}
48+
/>
49+
)
4150
}
4251

43-
return <ToolStep step={step} singleLine={singleLine} />
52+
return <ToolStep step={step} singleLine={singleLine} isLoading={isLoading} />
4453
}
4554

4655
function ToolStep({
4756
step,
4857
singleLine,
58+
isLoading,
4959
}: {
5060
step: Extract<LatteInteractionStep, { type: 'tool' }>
5161
singleLine?: boolean
62+
isLoading?: boolean
5263
}) {
5364
return (
5465
<div className='flex flex-row gap-2 items-start max-w-full'>
@@ -62,6 +73,7 @@ function ToolStep({
6273
noWrap={singleLine}
6374
ellipsis={singleLine}
6475
color='foregroundMuted'
76+
animate={isLoading}
6577
>
6678
{step.finished
6779
? (step.finishedDescription ?? step.activeDescription)
@@ -104,9 +116,11 @@ const editAction = (
104116
function EditActionStep({
105117
step,
106118
singleLine,
119+
isLoading,
107120
}: {
108121
step: Extract<LatteInteractionStep, { type: 'action' }>
109122
singleLine?: boolean
123+
isLoading?: boolean
110124
}) {
111125
const { icon, operationDescription } = editAction(step.action)
112126

@@ -117,6 +131,7 @@ function EditActionStep({
117131
noWrap={singleLine}
118132
ellipsis={singleLine}
119133
color='foregroundMuted'
134+
animate={isLoading}
120135
>
121136
{operationDescription}
122137
</Text.H5>

apps/web/src/components/LatteChat/_components/ChatInteraction/index.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ export function ChatInteraction({
3636
})}
3737
/>
3838
<div className='flex flex-col gap-4 flex-grow max-w-full px-2'>
39-
{interaction.steps.length == 0 ? (
40-
<InteractionStep />
41-
) : isOpen ? (
39+
{isOpen && interaction.steps.length > 0 ? (
4240
interaction.steps.map((step, i) => (
43-
<InteractionStep key={i} step={step} />
41+
<InteractionStep
42+
key={i}
43+
step={step}
44+
isLoading={
45+
interaction.output === undefined &&
46+
i === interaction.steps.length - 1
47+
}
48+
/>
4449
))
4550
) : (
46-
<CollapsedInteractionSteps steps={interaction.steps} />
51+
<CollapsedInteractionSteps
52+
steps={interaction.steps}
53+
isLoading={interaction.output === undefined}
54+
/>
4755
)}
4856
</div>
4957
</div>

0 commit comments

Comments
 (0)