From c8c308e31e63607280648e3e9f1f56a371adcd05 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 10 Nov 2023 15:34:25 -0800 Subject: Refactor feeds to use react-query (#1862) * Update to react-query v5 * Introduce post-feed react query * Add feed refresh behaviors * Only fetch feeds of visible pages * Implement polling for latest on feeds * Add moderation filtering to slices * Handle block errors * Update feed error messages * Remove old models * Replace simple-feed option with disable-tuner option * Add missing useMemo * Implement the mergefeed and fixes to polling * Correctly handle failed load more state * Improve error and empty state behaviors * Clearer naming --- src/lib/api/feed/author.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/lib/api/feed/author.ts') diff --git a/src/lib/api/feed/author.ts b/src/lib/api/feed/author.ts index ec8795e1a..77c167869 100644 --- a/src/lib/api/feed/author.ts +++ b/src/lib/api/feed/author.ts @@ -1,38 +1,37 @@ import { AppBskyFeedDefs, AppBskyFeedGetAuthorFeed as GetAuthorFeed, + BskyAgent, } from '@atproto/api' -import {RootStoreModel} from 'state/index' import {FeedAPI, FeedAPIResponse} from './types' export class AuthorFeedAPI implements FeedAPI { - cursor: string | undefined - constructor( - public rootStore: RootStoreModel, + public agent: BskyAgent, public params: GetAuthorFeed.QueryParams, ) {} - reset() { - this.cursor = undefined - } - async peekLatest(): Promise { - const res = await this.rootStore.agent.getAuthorFeed({ + const res = await this.agent.getAuthorFeed({ ...this.params, limit: 1, }) return res.data.feed[0] } - async fetchNext({limit}: {limit: number}): Promise { - const res = await this.rootStore.agent.getAuthorFeed({ + async fetch({ + cursor, + limit, + }: { + cursor: string | undefined + limit: number + }): Promise { + const res = await this.agent.getAuthorFeed({ ...this.params, - cursor: this.cursor, + cursor, limit, }) if (res.success) { - this.cursor = res.data.cursor return { cursor: res.data.cursor, feed: this._filter(res.data.feed), -- cgit 1.4.1