Skip to content

Commit 81dadc1

Browse files
committed
fix: tweaks transition aniamtion details
1 parent caff723 commit 81dadc1

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

app/components/Package/List.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ watch(
112112
{ immediate: true },
113113
)
114114
115+
// Suppress per-card enter animation when the entire result set is replaced (new search).
116+
// Cards loaded incrementally via scroll should still animate in with the stagger effect.
117+
const suppressAnimation = shallowRef(false)
118+
115119
// Reset scroll state when results change significantly (new search)
116120
watch(
117121
() => props.results,
@@ -123,6 +127,10 @@ watch(
123127
(oldResults.length > 0 && newResults[0]?.package.name !== oldResults[0]?.package.name)
124128
) {
125129
hasScrolledToInitial.value = false
130+
suppressAnimation.value = true
131+
nextTick(() => {
132+
suppressAnimation.value = false
133+
})
126134
}
127135
},
128136
)
@@ -172,9 +180,13 @@ defineExpose({
172180
:show-publisher="showPublisher"
173181
:index="index"
174182
:search-query="searchQuery"
175-
class="motion-safe:animate-fade-in motion-safe:animate-fill-both"
183+
:class="
184+
!suppressAnimation && 'motion-safe:animate-fade-in motion-safe:animate-fill-both'
185+
"
186+
:style="
187+
!suppressAnimation ? { animationDelay: `${Math.min(index * 0.02, 0.3)}s` } : {}
188+
"
176189
:filters="filters"
177-
:style="{ animationDelay: `${Math.min(index * 0.02, 0.3)}s` }"
178190
@click-keyword="emit('clickKeyword', $event)"
179191
/>
180192
</div>
@@ -224,8 +236,10 @@ defineExpose({
224236
:show-publisher="showPublisher"
225237
:index="index"
226238
:search-query="searchQuery"
227-
class="motion-safe:animate-fade-in motion-safe:animate-fill-both"
228-
:style="{ animationDelay: `${Math.min(index * 0.02, 0.3)}s` }"
239+
:class="
240+
!suppressAnimation && 'motion-safe:animate-fade-in motion-safe:animate-fill-both'
241+
"
242+
:style="!suppressAnimation ? { animationDelay: `${Math.min(index * 0.02, 0.3)}s` } : {}"
229243
:filters="filters"
230244
@click-keyword="emit('clickKeyword', $event)"
231245
/>

app/composables/useGlobalSearch.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { debounce } from 'perfect-debounce'
44
// Pages that have their own local filter using ?q
55
const pagesWithLocalFilter = new Set(['~username', 'org'])
66

7+
const SEARCH_DEBOUNCE_MS = 250
8+
79
export function useGlobalSearch(place: 'header' | 'content' = 'content') {
810
const { settings } = useSettings()
911
const { searchProvider } = useSearchProvider()
@@ -27,10 +29,14 @@ export function useGlobalSearch(place: 'header' | 'content' = 'content') {
2729
// Syncs instantly when instantSearch is on, but only on Enter press when off
2830
const committedSearchQuery = useState<string>('committed-search-query', () => searchQuery.value)
2931

32+
const commitSearchQuery = debounce((val: string) => {
33+
committedSearchQuery.value = val
34+
}, SEARCH_DEBOUNCE_MS)
35+
3036
// This is basically doing instant search as user types
3137
watch(searchQuery, val => {
3238
if (settings.value.instantSearch) {
33-
committedSearchQuery.value = val
39+
commitSearchQuery(val)
3440
}
3541
})
3642

@@ -71,10 +77,11 @@ export function useGlobalSearch(place: 'header' | 'content' = 'content') {
7177
})
7278
}
7379

74-
const updateUrlQuery = debounce(updateUrlQueryImpl, 250)
80+
const updateUrlQuery = debounce(updateUrlQueryImpl, SEARCH_DEBOUNCE_MS)
7581

7682
function flushUpdateUrlQuery() {
7783
// Commit the current query when explicitly submitted (Enter pressed)
84+
commitSearchQuery.cancel()
7885
committedSearchQuery.value = searchQuery.value
7986
// When instant search is off the debounce queue is empty, so call directly
8087
if (!settings.value.instantSearch) {

0 commit comments

Comments
 (0)