Skip to content

Commit

Permalink
Fix: fetch follows on desktop search for typeahead (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee authored Oct 10, 2023
1 parent 60c0db0 commit d68b4ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/state/models/cache/my-follows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
moderateProfile,
} from '@atproto/api'
import {RootStoreModel} from '../root-store'
import {bundleAsync} from 'lib/async/bundle'

const MAX_SYNC_PAGES = 10
const SYNC_TTL = 60e3 * 10 // 10 minutes
Expand Down Expand Up @@ -56,7 +57,7 @@ export class MyFollowsCache {
* Syncs a subset of the user's follows
* for performance reasons, caps out at 1000 follows
*/
async syncIfNeeded() {
syncIfNeeded = bundleAsync(async () => {
if (this.lastSync > Date.now() - SYNC_TTL) {
return
}
Expand All @@ -81,7 +82,7 @@ export class MyFollowsCache {
}

this.lastSync = Date.now()
}
})

getFollowState(did: string): FollowState {
if (typeof this.byDid[did] === 'undefined') {
Expand Down
7 changes: 7 additions & 0 deletions src/view/shell/desktop/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export const DesktopSearch = observer(function DesktopSearch() {
)
const navigation = useNavigation<NavigationProp>()

// initial setup
React.useEffect(() => {
if (store.me.did) {
autocompleteView.setup()
}
}, [autocompleteView, store.me.did])

const onChangeQuery = React.useCallback(
(text: string) => {
setQuery(text)
Expand Down

0 comments on commit d68b4ca

Please sign in to comment.