fix(app): keep background hint visible for at least one second (#46715)

This commit is contained in:
Brendan Allan
2026-09-02 10:23:00 +08:00
committed by GitHub
Unverified
parent ddda404d99
commit e0c7712f20
2 changed files with 36 additions and 16 deletions
+30 -15
View File
@@ -1,25 +1,40 @@
import { createMemo, type Accessor } from "solid-js"
import { createMemo, createSignal, onCleanup, type Accessor } from "solid-js"
import createPresence from "solid-presence"
export function createAnimatedPresence<T>(
value: Accessor<T | undefined>,
element: Accessor<HTMLElement | null>,
identity?: Accessor<unknown>,
minimumDuration = 0,
) {
const animation = createMemo<{ identity?: unknown; show: boolean; animate: boolean; value: T | undefined }>(
(previous) => {
const currentIdentity = identity?.()
const current = value()
const show = current !== undefined
const same = !identity || previous?.identity === currentIdentity
return {
identity: currentIdentity,
show,
animate: previous !== undefined && same && (previous.animate || previous.show !== show),
value: current ?? (same ? previous?.value : undefined),
}
},
)
const [tick, setTick] = createSignal(0)
const animation = createMemo<{
identity?: unknown
show: boolean
animate: boolean
value: T | undefined
started: number
}>((previous) => {
tick()
const currentIdentity = identity?.()
const current = value()
const same = !identity || previous?.identity === currentIdentity
const started = same && previous?.show ? previous.started : performance.now()
const remaining =
current === undefined && same && previous?.show ? minimumDuration - (performance.now() - started) : 0
const show = current !== undefined || remaining > 0
if (remaining > 0) {
const timer = setTimeout(() => setTick((value) => value + 1), remaining)
onCleanup(() => clearTimeout(timer))
}
return {
identity: currentIdentity,
show,
started,
animate: previous !== undefined && same && (previous.animate || previous.show !== show),
value: current ?? (same ? previous?.value : undefined),
}
})
const presence = createPresence({ show: () => animation().show, element })
return {
...presence,
@@ -539,7 +539,12 @@ function MessageTimelineView(
.findLast((ref) => blocking.has(ref.partID))?.partID
})
const [backgroundHintRef, setBackgroundHintRef] = createSignal<HTMLDivElement>()
const backgroundHintPresence = createAnimatedPresence(backgroundHintPartID, () => backgroundHintRef() ?? null)
const backgroundHintPresence = createAnimatedPresence(
backgroundHintPartID,
() => backgroundHintRef() ?? null,
sessionID,
1000,
)
const showWorking = createMemo(() => {
const id = sessionID()
if (!id || sessionStatus().type !== "busy") return false