Something went wrong. Try again.
cee sky
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import {useCallback} from 'react'import {msg} from '@lingui/core/macro'import {useLingui} from '@lingui/react'
import {logger} from '#/logger'import {type Shadow} from '#/state/cache/types'import {useProfileFollowMutationQueue} from '#/state/queries/profile'import {useRequireAuth} from '#/state/session'import * as Toast from '#/components/Toast'import {type Metrics} from '#/analytics/metrics'import type * as bsky from '#/types/bsky'
export function useFollowMethods({ profile, logContext, onFollow,}: { profile: Shadow<bsky.profile.AnyProfileView> logContext: Metrics['profile:follow']['logContext'] & Metrics['profile:unfollow']['logContext'] /** Called once a follow succeeds. */ onFollow?: () => void}) { const {_} = useLingui() const requireAuth = useRequireAuth() const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue( profile, logContext, )
const follow = useCallback(() => { requireAuth(async () => { try { await queueFollow() onFollow?.() } catch (e: any) { logger.error(`useFollowMethods: failed to follow`, {message: String(e)}) if (e?.name !== 'AbortError') { Toast.show(_(msg`An issue occurred, please try again.`), { type: 'error', }) } } }) }, [_, queueFollow, requireAuth, onFollow])
const unfollow = useCallback(() => { requireAuth(async () => { try { await queueUnfollow() } catch (e: any) { logger.error(`useFollowMethods: failed to unfollow`, { message: String(e), }) if (e?.name !== 'AbortError') { Toast.show(_(msg`An issue occurred, please try again.`), { type: 'error', }) } } }) }, [_, queueUnfollow, requireAuth])
return { follow, unfollow, }}