* Refactor mobile search screen * Remove 'staleness' fetch trigger on search * Implement a temporary fulltext search solution * Add missing key from profile search result * A few UI & UX improvements to the search suggestions * Update web search suggestions * Implement search in web build
This commit is contained in:
parent
48e18662f6
commit
a7e3ce2585
16 changed files with 587 additions and 283 deletions
51
src/state/models/ui/search.ts
Normal file
51
src/state/models/ui/search.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {searchProfiles, searchPosts} from 'lib/api/search'
|
||||
import {AppBskyActorProfile as Profile} from '@atproto/api'
|
||||
import {RootStoreModel} from '../root-store'
|
||||
|
||||
export class SearchUIModel {
|
||||
isPostsLoading = false
|
||||
isProfilesLoading = false
|
||||
query: string = ''
|
||||
postUris: string[] = []
|
||||
profiles: Profile.View[] = []
|
||||
|
||||
constructor(public rootStore: RootStoreModel) {
|
||||
makeAutoObservable(this)
|
||||
}
|
||||
|
||||
async fetch(q: string) {
|
||||
this.postUris = []
|
||||
this.profiles = []
|
||||
this.query = q
|
||||
if (!q.trim()) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isPostsLoading = true
|
||||
this.isProfilesLoading = true
|
||||
|
||||
const [postsSearch, profilesSearch] = await Promise.all([
|
||||
searchPosts(q).catch(_e => []),
|
||||
searchProfiles(q).catch(_e => []),
|
||||
])
|
||||
runInAction(() => {
|
||||
this.postUris = postsSearch?.map(p => `at://${p.user.did}/${p.tid}`) || []
|
||||
this.isPostsLoading = false
|
||||
})
|
||||
|
||||
let profiles: Profile.View[] = []
|
||||
if (profilesSearch?.length) {
|
||||
do {
|
||||
const res = await this.rootStore.api.app.bsky.actor.getProfiles({
|
||||
actors: profilesSearch.splice(0, 25).map(p => p.did),
|
||||
})
|
||||
profiles = profiles.concat(res.data.profiles)
|
||||
} while (profilesSearch.length)
|
||||
}
|
||||
runInAction(() => {
|
||||
this.profiles = profiles
|
||||
this.isProfilesLoading = false
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue