Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫
Something went wrong. Try again.
1.8 kB · 64 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import {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,}: { profile: Shadow<bsky.profile.AnyProfileView> logContext: Metrics['profile:follow']['logContext'] & Metrics['profile:unfollow']['logContext']}) { const {_} = useLingui() const requireAuth = useRequireAuth() const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue( profile, logContext, )
const follow = useCallback(() => { requireAuth(async () => { try { await queueFollow() } 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])
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, }}