refactor(search): more search options

This commit is contained in:
三咲智子 2023-01-08 21:42:53 +08:00
parent 95a875f47b
commit 805f7731ad
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E

View file

@ -1,10 +1,10 @@
import type { MaybeRef } from '@vueuse/core' import type { MaybeComputedRef } from '@vueuse/core'
import type { Paginator, mastodon } from 'masto' import type { Paginator, mastodon } from 'masto'
import type { RouteLocation } from 'vue-router' import type { RouteLocation } from 'vue-router'
export interface UseSearchOptions { export type UseSearchOptions = MaybeComputedRef<
type?: MaybeRef<mastodon.v2.SearchType> Partial<Omit<mastodon.v1.SearchParams, keyof mastodon.DefaultPaginationParams | 'q'>>
} >
export interface BuildSearchResult<K extends keyof any, T> { export interface BuildSearchResult<K extends keyof any, T> {
id: string id: string
@ -20,7 +20,7 @@ export type StatusSearchResult = BuildSearchResult<'status', mastodon.v1.Status>
export type SearchResult = HashTagSearchResult | AccountSearchResult | StatusSearchResult export type SearchResult = HashTagSearchResult | AccountSearchResult | StatusSearchResult
export function useSearch(query: MaybeRef<string>, options?: UseSearchOptions) { export function useSearch(query: MaybeComputedRef<string>, options: UseSearchOptions = {}) {
const done = ref(false) const done = ref(false)
const masto = useMasto() const masto = useMasto()
const loading = ref(false) const loading = ref(false)
@ -71,9 +71,9 @@ export function useSearch(query: MaybeRef<string>, options?: UseSearchOptions) {
* but that doesn't seem to be the case. So instead we just create a new paginator with the new params. * 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({ paginator = masto.v2.search({
q: unref(query), q: resolveUnref(query),
...resolveUnref(options),
resolve: !!currentUser.value, resolve: !!currentUser.value,
type: unref(options?.type),
}) })
const nextResults = await paginator.next() const nextResults = await paginator.next()