mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
fix: trim spaces for search keyword
This commit is contained in:
parent
509eec5f87
commit
c28d1e1537
3 changed files with 20 additions and 16 deletions
|
@ -221,7 +221,7 @@ const onKeyDown = (e: KeyboardEvent) => {
|
|||
</template>
|
||||
<div v-else p5 text-center text-secondary italic>
|
||||
{{
|
||||
input.length
|
||||
input.trim().length
|
||||
? $t('common.not_found')
|
||||
: $t('search.search_desc')
|
||||
}}
|
||||
|
|
|
@ -77,17 +77,19 @@ const activate = () => {
|
|||
<!-- Results -->
|
||||
<div left-0 top-12 absolute w-full z10 group-focus-within="pointer-events-auto visible" invisible pointer-events-none>
|
||||
<div w-full bg-base border="~ base" rounded-3 max-h-100 overflow-auto py2>
|
||||
<span v-if="query.length === 0" block text-center text-sm text-secondary>
|
||||
<span v-if="query.trim().length === 0" block text-center text-sm text-secondary>
|
||||
{{ t('search.search_desc') }}
|
||||
</span>
|
||||
<template v-if="!loading">
|
||||
<SearchResult
|
||||
v-for="(result, i) in results" :key="result.id"
|
||||
:active="index === parseInt(i.toString())"
|
||||
:result="result"
|
||||
:tabindex="focused ? 0 : -1"
|
||||
/>
|
||||
<span v-if="query.length !== 0 && results.length === 0" block text-center text-sm text-secondary>
|
||||
<template v-else-if="!loading">
|
||||
<template v-if="results.length > 0">
|
||||
<SearchResult
|
||||
v-for="(result, i) in results" :key="result.id"
|
||||
:active="index === parseInt(i.toString())"
|
||||
:result="result"
|
||||
:tabindex="focused ? 0 : -1"
|
||||
/>
|
||||
</template>
|
||||
<span v-else block text-center text-sm text-secondary>
|
||||
{{ t('search.search_empty') }}
|
||||
</span>
|
||||
</template>
|
||||
|
|
|
@ -28,6 +28,8 @@ export function useSearch(query: MaybeComputedRef<string>, options: UseSearchOpt
|
|||
const hashtags = ref<HashTagSearchResult[]>([])
|
||||
const statuses = ref<StatusSearchResult[]>([])
|
||||
|
||||
const q = $computed(() => resolveUnref(query).trim())
|
||||
|
||||
let paginator: Paginator<mastodon.v2.Search, mastodon.v2.SearchParams> | undefined
|
||||
|
||||
const appendResults = (results: mastodon.v2.Search, empty = false) => {
|
||||
|
@ -56,12 +58,12 @@ export function useSearch(query: MaybeComputedRef<string>, options: UseSearchOpt
|
|||
}))]
|
||||
}
|
||||
|
||||
watch(() => unref(query), () => {
|
||||
loading.value = !!(unref(query) && isMastoInitialised.value)
|
||||
watch(() => resolveUnref(query), () => {
|
||||
loading.value = !!(q && isMastoInitialised.value)
|
||||
})
|
||||
|
||||
debouncedWatch(() => unref(query), async () => {
|
||||
if (!unref(query) || !isMastoInitialised.value)
|
||||
debouncedWatch(() => resolveUnref(query), async () => {
|
||||
if (!q || !isMastoInitialised.value)
|
||||
return
|
||||
|
||||
loading.value = true
|
||||
|
@ -71,7 +73,7 @@ export function useSearch(query: MaybeComputedRef<string>, options: UseSearchOpt
|
|||
* but that doesn't seem to be the case. So instead we just create a new paginator with the new params.
|
||||
*/
|
||||
paginator = masto.v2.search({
|
||||
q: resolveUnref(query),
|
||||
q,
|
||||
...resolveUnref(options),
|
||||
resolve: !!currentUser.value,
|
||||
})
|
||||
|
@ -85,7 +87,7 @@ export function useSearch(query: MaybeComputedRef<string>, options: UseSearchOpt
|
|||
}, { debounce: 300 })
|
||||
|
||||
const next = async () => {
|
||||
if (!unref(query) || !isMastoInitialised.value || !paginator)
|
||||
if (!q || !isMastoInitialised.value || !paginator)
|
||||
return
|
||||
|
||||
loading.value = true
|
||||
|
|
Loading…
Reference in a new issue