Ensure root store is not undefined

This commit is contained in:
renahlee
2023-05-09 20:08:58 -07:00
parent d9c6553b44
commit c0484dc20d
2 changed files with 10 additions and 5 deletions
+8 -3
View File
@@ -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)
} }
+2 -2
View File
@@ -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[] = []