Something went wrong. Try again.
hardened bluesky app fork with microcosm
Something went wrong. Try again.
1.6 kB · 62 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import {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 * as bsky from '#/types/bsky'
export function useFollowMethods({ profile, logContext,}: { profile: Shadow<bsky.profile.AnyProfileView> logContext: string}) { 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, }}