refactor(search): more search options
parent
95a875f47b
commit
805f7731ad
|
@ -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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue