Add likes tab (#1227)
* add likes tab (cherry picked from commit 6c5ffd964ca0b185ddfc37088d82712a006a1163) * only show Likes tab to authenticated user (cherry picked from commit ecc1254411d760158b6d7a4c5f05d940db872dfc) * Bump @atproto/api@0.6.5 * fix types --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>zio/stable
parent
548ec6c82d
commit
2b13dc0f3a
|
@ -24,7 +24,7 @@
|
||||||
"e2e:run": "detox test --configuration ios.sim.debug --take-screenshots all"
|
"e2e:run": "detox test --configuration ios.sim.debug --take-screenshots all"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@atproto/api": "^0.6.3",
|
"@atproto/api": "^0.6.5",
|
||||||
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
||||||
"@braintree/sanitize-url": "^6.0.2",
|
"@braintree/sanitize-url": "^6.0.2",
|
||||||
"@expo/html-elements": "^0.4.2",
|
"@expo/html-elements": "^0.4.2",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
AppBskyFeedGetTimeline as GetTimeline,
|
AppBskyFeedGetTimeline as GetTimeline,
|
||||||
AppBskyFeedGetAuthorFeed as GetAuthorFeed,
|
AppBskyFeedGetAuthorFeed as GetAuthorFeed,
|
||||||
AppBskyFeedGetFeed as GetCustomFeed,
|
AppBskyFeedGetFeed as GetCustomFeed,
|
||||||
|
AppBskyFeedGetActorLikes as GetActorLikes,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import AwaitLock from 'await-lock'
|
import AwaitLock from 'await-lock'
|
||||||
import {bundleAsync} from 'lib/async/bundle'
|
import {bundleAsync} from 'lib/async/bundle'
|
||||||
|
@ -57,7 +58,7 @@ export class PostsFeedModel {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public rootStore: RootStoreModel,
|
public rootStore: RootStoreModel,
|
||||||
public feedType: 'home' | 'author' | 'custom',
|
public feedType: 'home' | 'author' | 'custom' | 'likes',
|
||||||
params: QueryParams,
|
params: QueryParams,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
) {
|
) {
|
||||||
|
@ -429,10 +430,14 @@ export class PostsFeedModel {
|
||||||
res.data.feed = res.data.feed.slice(0, params.limit)
|
res.data.feed = res.data.feed.slice(0, params.limit)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
} else {
|
} else if (this.feedType === 'author') {
|
||||||
return this.rootStore.agent.getAuthorFeed(
|
return this.rootStore.agent.getAuthorFeed(
|
||||||
params as GetAuthorFeed.QueryParams,
|
params as GetAuthorFeed.QueryParams,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return this.rootStore.agent.getActorLikes(
|
||||||
|
params as GetActorLikes.QueryParams,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ export enum Sections {
|
||||||
PostsNoReplies = 'Posts',
|
PostsNoReplies = 'Posts',
|
||||||
PostsWithReplies = 'Posts & replies',
|
PostsWithReplies = 'Posts & replies',
|
||||||
PostsWithMedia = 'Media',
|
PostsWithMedia = 'Media',
|
||||||
|
Likes = 'Likes',
|
||||||
CustomAlgorithms = 'Feeds',
|
CustomAlgorithms = 'Feeds',
|
||||||
Lists = 'Lists',
|
Lists = 'Lists',
|
||||||
}
|
}
|
||||||
|
@ -22,6 +23,8 @@ export class ProfileUiModel {
|
||||||
static END_ITEM = {_reactKey: '__end__'}
|
static END_ITEM = {_reactKey: '__end__'}
|
||||||
static EMPTY_ITEM = {_reactKey: '__empty__'}
|
static EMPTY_ITEM = {_reactKey: '__empty__'}
|
||||||
|
|
||||||
|
isAuthenticatedUser = false
|
||||||
|
|
||||||
// data
|
// data
|
||||||
profile: ProfileModel
|
profile: ProfileModel
|
||||||
feed: PostsFeedModel
|
feed: PostsFeedModel
|
||||||
|
@ -57,7 +60,8 @@ export class ProfileUiModel {
|
||||||
if (
|
if (
|
||||||
this.selectedView === Sections.PostsNoReplies ||
|
this.selectedView === Sections.PostsNoReplies ||
|
||||||
this.selectedView === Sections.PostsWithReplies ||
|
this.selectedView === Sections.PostsWithReplies ||
|
||||||
this.selectedView === Sections.PostsWithMedia
|
this.selectedView === Sections.PostsWithMedia ||
|
||||||
|
this.selectedView === Sections.Likes
|
||||||
) {
|
) {
|
||||||
return this.feed
|
return this.feed
|
||||||
} else if (this.selectedView === Sections.Lists) {
|
} else if (this.selectedView === Sections.Lists) {
|
||||||
|
@ -83,7 +87,8 @@ export class ProfileUiModel {
|
||||||
Sections.PostsNoReplies,
|
Sections.PostsNoReplies,
|
||||||
Sections.PostsWithReplies,
|
Sections.PostsWithReplies,
|
||||||
Sections.PostsWithMedia,
|
Sections.PostsWithMedia,
|
||||||
]
|
this.isAuthenticatedUser && Sections.Likes,
|
||||||
|
].filter(Boolean) as string[]
|
||||||
if (this.algos.hasLoaded && !this.algos.isEmpty) {
|
if (this.algos.hasLoaded && !this.algos.isEmpty) {
|
||||||
items.push(Sections.CustomAlgorithms)
|
items.push(Sections.CustomAlgorithms)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +122,8 @@ export class ProfileUiModel {
|
||||||
if (
|
if (
|
||||||
this.selectedView === Sections.PostsNoReplies ||
|
this.selectedView === Sections.PostsNoReplies ||
|
||||||
this.selectedView === Sections.PostsWithReplies ||
|
this.selectedView === Sections.PostsWithReplies ||
|
||||||
this.selectedView === Sections.PostsWithMedia
|
this.selectedView === Sections.PostsWithMedia ||
|
||||||
|
this.selectedView === Sections.Likes
|
||||||
) {
|
) {
|
||||||
if (this.feed.hasContent) {
|
if (this.feed.hasContent) {
|
||||||
arr = this.feed.slices.slice()
|
arr = this.feed.slices.slice()
|
||||||
|
@ -151,7 +157,8 @@ export class ProfileUiModel {
|
||||||
if (
|
if (
|
||||||
this.selectedView === Sections.PostsNoReplies ||
|
this.selectedView === Sections.PostsNoReplies ||
|
||||||
this.selectedView === Sections.PostsWithReplies ||
|
this.selectedView === Sections.PostsWithReplies ||
|
||||||
this.selectedView === Sections.PostsWithMedia
|
this.selectedView === Sections.PostsWithMedia ||
|
||||||
|
this.selectedView === Sections.Likes
|
||||||
) {
|
) {
|
||||||
return this.feed.hasContent && this.feed.hasMore && this.feed.isLoading
|
return this.feed.hasContent && this.feed.hasMore && this.feed.isLoading
|
||||||
} else if (this.selectedView === Sections.Lists) {
|
} else if (this.selectedView === Sections.Lists) {
|
||||||
|
@ -169,27 +176,45 @@ export class ProfileUiModel {
|
||||||
|
|
||||||
this.selectedViewIndex = index
|
this.selectedViewIndex = index
|
||||||
|
|
||||||
let filter = 'posts_no_replies'
|
if (
|
||||||
if (this.selectedView === Sections.PostsWithReplies) {
|
this.selectedView === Sections.PostsNoReplies ||
|
||||||
filter = 'posts_with_replies'
|
this.selectedView === Sections.PostsWithReplies ||
|
||||||
} else if (this.selectedView === Sections.PostsWithMedia) {
|
this.selectedView === Sections.PostsWithMedia
|
||||||
filter = 'posts_with_media'
|
) {
|
||||||
}
|
let filter = 'posts_no_replies'
|
||||||
|
if (this.selectedView === Sections.PostsWithReplies) {
|
||||||
|
filter = 'posts_with_replies'
|
||||||
|
} else if (this.selectedView === Sections.PostsWithMedia) {
|
||||||
|
filter = 'posts_with_media'
|
||||||
|
}
|
||||||
|
|
||||||
this.feed = new PostsFeedModel(
|
this.feed = new PostsFeedModel(
|
||||||
this.rootStore,
|
this.rootStore,
|
||||||
'author',
|
'author',
|
||||||
{
|
{
|
||||||
actor: this.params.user,
|
actor: this.params.user,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
filter,
|
filter,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
isSimpleFeed: ['posts_with_media'].includes(filter),
|
isSimpleFeed: ['posts_with_media'].includes(filter),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.feed.setup()
|
||||||
|
} else if (this.selectedView === Sections.Likes) {
|
||||||
|
this.feed = new PostsFeedModel(
|
||||||
|
this.rootStore,
|
||||||
|
'likes',
|
||||||
|
{
|
||||||
|
actor: this.params.user,
|
||||||
|
limit: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isSimpleFeed: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if (this.currentView instanceof PostsFeedModel) {
|
|
||||||
this.feed.setup()
|
this.feed.setup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,6 +228,8 @@ export class ProfileUiModel {
|
||||||
.setup()
|
.setup()
|
||||||
.catch(err => this.rootStore.log.error('Failed to fetch feed', err)),
|
.catch(err => this.rootStore.log.error('Failed to fetch feed', err)),
|
||||||
])
|
])
|
||||||
|
this.isAuthenticatedUser =
|
||||||
|
this.profile.did === this.rootStore.session.currentSession?.did
|
||||||
this.algos.refresh()
|
this.algos.refresh()
|
||||||
// HACK: need to use the DID as a param, not the username -prf
|
// HACK: need to use the DID as a param, not the username -prf
|
||||||
this.lists.source = this.profile.did
|
this.lists.source = this.profile.did
|
||||||
|
|
|
@ -40,10 +40,10 @@
|
||||||
tlds "^1.234.0"
|
tlds "^1.234.0"
|
||||||
typed-emitter "^2.1.0"
|
typed-emitter "^2.1.0"
|
||||||
|
|
||||||
"@atproto/api@^0.6.3":
|
"@atproto/api@^0.6.5":
|
||||||
version "0.6.3"
|
version "0.6.5"
|
||||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.6.3.tgz#2d604897df9098d84f3dfb3bffe1d4859513b1ba"
|
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.6.5.tgz#496a011b7e8fbf2af32a30cec07a021aa6ef3f4b"
|
||||||
integrity sha512-vgwJn6M4wEyMm/oQKSATO3C0iRUZ/u5LTTl3E/MqV1mrWzvWLVhOqlATw7CDhEdzwJciO83ei72re6skhSp+Zg==
|
integrity sha512-u6NVkYpdUU5jKGxio2FIRmok0LL+eqqMzihm9LDfydZ4Pi4NqfrOrWw0H1WA7zO3vH9AaxnLSMTwSEAkRRb2FA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@atproto/common-web" "*"
|
"@atproto/common-web" "*"
|
||||||
"@atproto/uri" "*"
|
"@atproto/uri" "*"
|
||||||
|
|
Loading…
Reference in New Issue