-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new home feed-api wrapper and give a header indicating the fall…
…back behavior (#2534) * Add a new home feed-api wrapper and give a header indicating the fallback behavior * Sneak in a quick fix: use the correct text color in the delete modal * Use imported constant
- Loading branch information
Showing
7 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {AppBskyFeedDefs} from '@atproto/api' | ||
import {FeedAPI, FeedAPIResponse} from './types' | ||
import {FollowingFeedAPI} from './following' | ||
import {CustomFeedAPI} from './custom' | ||
import {PROD_DEFAULT_FEED} from '#/lib/constants' | ||
|
||
// HACK | ||
// the feed API does not include any facilities for passing down | ||
// non-post elements. adding that is a bit of a heavy lift, and we | ||
// have just one temporary usecase for it: flagging when the home feed | ||
// falls back to discover. | ||
// we use this fallback marker post to drive this instead. see Feed.tsx | ||
// for the usage. | ||
// -prf | ||
export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = { | ||
post: { | ||
uri: 'fallback-marker-post', | ||
cid: 'fake', | ||
record: {}, | ||
author: { | ||
did: 'did:fake', | ||
handle: 'fake.com', | ||
}, | ||
indexedAt: new Date().toISOString(), | ||
}, | ||
} | ||
|
||
export class HomeFeedAPI implements FeedAPI { | ||
following: FollowingFeedAPI | ||
discover: CustomFeedAPI | ||
usingDiscover = false | ||
itemCursor = 0 | ||
|
||
constructor() { | ||
this.following = new FollowingFeedAPI() | ||
this.discover = new CustomFeedAPI({feed: PROD_DEFAULT_FEED('whats-hot')}) | ||
} | ||
|
||
reset() { | ||
this.following = new FollowingFeedAPI() | ||
this.discover = new CustomFeedAPI({feed: PROD_DEFAULT_FEED('whats-hot')}) | ||
this.usingDiscover = false | ||
this.itemCursor = 0 | ||
} | ||
|
||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> { | ||
if (this.usingDiscover) { | ||
return this.discover.peekLatest() | ||
} | ||
return this.following.peekLatest() | ||
} | ||
|
||
async fetch({ | ||
cursor, | ||
limit, | ||
}: { | ||
cursor: string | undefined | ||
limit: number | ||
}): Promise<FeedAPIResponse> { | ||
if (!cursor) { | ||
this.reset() | ||
} | ||
|
||
let returnCursor | ||
let posts: AppBskyFeedDefs.FeedViewPost[] = [] | ||
|
||
if (!this.usingDiscover) { | ||
const res = await this.following.fetch({cursor, limit}) | ||
returnCursor = res.cursor | ||
posts = posts.concat(res.feed) | ||
if (res.feed.length === 0 || !cursor) { | ||
posts.push(FALLBACK_MARKER_POST) | ||
this.usingDiscover = true | ||
} | ||
} | ||
|
||
if (this.usingDiscover) { | ||
const res = await this.discover.fetch({cursor, limit}) | ||
returnCursor = res.cursor | ||
posts = posts.concat(res.feed) | ||
} | ||
|
||
return { | ||
cursor: returnCursor, | ||
feed: posts, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import {View} from 'react-native' | ||
import {Trans} from '@lingui/macro' | ||
import {Text} from '../util/text/Text' | ||
import {usePalette} from '#/lib/hooks/usePalette' | ||
import {TextLink} from '../util/Link' | ||
import {InfoCircleIcon} from '#/lib/icons' | ||
|
||
export function DiscoverFallbackHeader() { | ||
const pal = usePalette('default') | ||
return ( | ||
<View | ||
style={[ | ||
{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
paddingVertical: 12, | ||
paddingHorizontal: 12, | ||
borderTopWidth: 1, | ||
}, | ||
pal.border, | ||
pal.viewLight, | ||
]}> | ||
<View style={{width: 68, paddingLeft: 12}}> | ||
<InfoCircleIcon size={36} style={pal.textLight} strokeWidth={1.5} /> | ||
</View> | ||
<View style={{flex: 1}}> | ||
<Text type="md" style={pal.text}> | ||
<Trans> | ||
We ran out of posts from your follows. Here's the latest from | ||
</Trans>{' '} | ||
<TextLink | ||
type="md-medium" | ||
href="/profile/bsky.app/feed/whats-hot" | ||
text="Discover" | ||
style={pal.link} | ||
/> | ||
. | ||
</Text> | ||
</View> | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters