Ensure root store is not undefined
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import {AppBskyFeedPost} from '@atproto/api'
|
import {AppBskyFeedPost} from '@atproto/api'
|
||||||
import {SEARCH_HOST} from 'lib/constants'
|
import {SEARCH_HOST} from 'lib/constants'
|
||||||
|
import {RootStoreModel} from 'state/index'
|
||||||
|
|
||||||
export interface ProfileSearchItem {
|
export interface ProfileSearchItem {
|
||||||
$type: string
|
$type: string
|
||||||
@@ -31,15 +32,19 @@ export interface PostSearchItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function searchProfiles(
|
export async function searchProfiles(
|
||||||
|
rootStore: RootStoreModel,
|
||||||
query: string,
|
query: string,
|
||||||
): Promise<ProfileSearchItem[]> {
|
): Promise<ProfileSearchItem[]> {
|
||||||
const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '')
|
const host = SEARCH_HOST(rootStore.session.currentSession?.service || '')
|
||||||
const endpoint = `${host}/search/profiles`
|
const endpoint = `${host}/search/profiles`
|
||||||
return await doFetch<ProfileSearchItem[]>(endpoint, query)
|
return await doFetch<ProfileSearchItem[]>(endpoint, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchPosts(query: string): Promise<PostSearchItem[]> {
|
export async function searchPosts(
|
||||||
const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '')
|
rootStore: RootStoreModel,
|
||||||
|
query: string,
|
||||||
|
): Promise<PostSearchItem[]> {
|
||||||
|
const host = SEARCH_HOST(rootStore.session.currentSession?.service || '')
|
||||||
const endpoint = `${host}/search/posts`
|
const endpoint = `${host}/search/posts`
|
||||||
return await doFetch<PostSearchItem[]>(endpoint, query)
|
return await doFetch<PostSearchItem[]>(endpoint, query)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ export class SearchUIModel {
|
|||||||
this.isProfilesLoading = true
|
this.isProfilesLoading = true
|
||||||
|
|
||||||
const [postsSearch, profilesSearch] = await Promise.all([
|
const [postsSearch, profilesSearch] = await Promise.all([
|
||||||
searchPosts(q).catch(_e => []),
|
searchPosts(this.rootStore, q).catch(_e => []),
|
||||||
searchProfiles(q).catch(_e => []),
|
searchProfiles(this.rootStore, q).catch(_e => []),
|
||||||
])
|
])
|
||||||
|
|
||||||
let posts: AppBskyFeedDefs.PostView[] = []
|
let posts: AppBskyFeedDefs.PostView[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user