Rework the me.follows cache to reduce network load (#384)

This commit is contained in:
Paul Frazee 2023-04-03 19:50:46 -05:00 committed by GitHub
parent 50f7f9877f
commit 25cc5b997f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 97 additions and 75 deletions

View file

@ -8,6 +8,7 @@ import {useStores} from 'state/index'
import {UserAvatar} from './UserAvatar'
import {observer} from 'mobx-react-lite'
import FollowButton from '../profile/FollowButton'
import {FollowState} from 'state/models/cache/my-follows'
interface PostMetaOpts {
authorAvatar?: string
@ -25,15 +26,22 @@ export const PostMeta = observer(function (opts: PostMetaOpts) {
const handle = opts.authorHandle
const store = useStores()
const isMe = opts.did === store.me.did
const isFollowing =
typeof opts.did === 'string' && store.me.follows.isFollowing(opts.did)
const followState =
typeof opts.did === 'string'
? store.me.follows.getFollowState(opts.did)
: FollowState.Unknown
const [didFollow, setDidFollow] = React.useState(false)
const onToggleFollow = React.useCallback(() => {
setDidFollow(true)
}, [setDidFollow])
if (opts.showFollowBtn && !isMe && (!isFollowing || didFollow) && opts.did) {
if (
opts.showFollowBtn &&
!isMe &&
(followState === FollowState.NotFollowing || didFollow) &&
opts.did
) {
// two-liner with follow button
return (
<View style={styles.metaTwoLine}>