refactor(HistoryDatabase): enhance card expansion logic with pending state management

- Introduced a pending state to track the target expansion state during animations.
- Improved debounce handling to ensure smoother transitions and prevent rapid state changes.
- Updated logic to check for new pending states after animations complete, enhancing responsiveness and stability.
This commit is contained in:
666ghj 2026-01-09 10:57:48 +08:00
parent f32f5713f8
commit 5a0c705cfb

View file

@ -106,6 +106,7 @@ const historyContainer = ref(null)
let observer = null
let isAnimating = false //
let expandDebounceTimer = null //
let pendingState = null //
// -
const CARDS_PER_ROW = 4
@ -316,35 +317,60 @@ onMounted(() => {
observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
//
if (isAnimating) return
const shouldExpand = entry.isIntersecting
//
if (shouldExpand === isExpanded.value) return
//
pendingState = shouldExpand
//
//
if (expandDebounceTimer) {
clearTimeout(expandDebounceTimer)
expandDebounceTimer = null
}
//
if (isAnimating) return
//
if (shouldExpand === isExpanded.value) {
pendingState = null
return
}
// 使
// (50ms)(200ms)
const delay = shouldExpand ? 50 : 200
expandDebounceTimer = setTimeout(() => {
//
//
if (isAnimating) return
//
if (pendingState === null || pendingState === isExpanded.value) return
//
isAnimating = true
isExpanded.value = shouldExpand
isExpanded.value = pendingState
pendingState = null
// 700ms
//
setTimeout(() => {
isAnimating = false
//
if (pendingState !== null && pendingState !== isExpanded.value) {
//
expandDebounceTimer = setTimeout(() => {
if (pendingState !== null && pendingState !== isExpanded.value) {
isAnimating = true
isExpanded.value = pendingState
pendingState = null
setTimeout(() => {
isAnimating = false
}, 750)
}
}, 100)
}
}, 750)
}, delay)
})