Replace getAgent() with reading agent (#4243)
* Replace getAgent() with agent * Replace {agent} with agent
This commit is contained in:
parent
8a2f43c218
commit
9bd411c151
74 changed files with 400 additions and 438 deletions
|
@ -90,7 +90,7 @@ export const ComposePost = observer(function ComposePost({
|
|||
imageUris: initImageUris,
|
||||
}: Props) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {data: currentProfile} = useProfileQuery({did: currentAccount!.did})
|
||||
const {isModalActive} = useModals()
|
||||
const {closeComposer} = useComposerControls()
|
||||
|
@ -260,7 +260,7 @@ export const ComposePost = observer(function ComposePost({
|
|||
let postUri
|
||||
try {
|
||||
postUri = (
|
||||
await apilib.post(getAgent(), {
|
||||
await apilib.post(agent, {
|
||||
rawText: richtext.text,
|
||||
replyTo: replyTo?.uri,
|
||||
images: gallery.images,
|
||||
|
|
|
@ -8,7 +8,7 @@ import {ComposerOpts} from 'state/shell/composer'
|
|||
export function useExternalLinkFetch({}: {
|
||||
setQuote: (opts: ComposerOpts['quote']) => void
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ export function useExternalLinkFetch({}: {
|
|||
return cleanup
|
||||
}
|
||||
if (!extLink.meta) {
|
||||
getLinkMeta(getAgent(), extLink.uri).then(meta => {
|
||||
getLinkMeta(agent, extLink.uri).then(meta => {
|
||||
if (aborted) {
|
||||
return
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ export function useExternalLinkFetch({}: {
|
|||
})
|
||||
}
|
||||
return cleanup
|
||||
}, [extLink, getAgent])
|
||||
}, [extLink, agent])
|
||||
|
||||
return {extLink, setExtLink}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ export function useExternalLinkFetch({
|
|||
)
|
||||
const getPost = useGetPost()
|
||||
const fetchDid = useFetchDid()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
useEffect(() => {
|
||||
let aborted = false
|
||||
|
@ -59,7 +59,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
||||
getFeedAsEmbed(getAgent(), fetchDid, extLink.uri).then(
|
||||
getFeedAsEmbed(agent, fetchDid, extLink.uri).then(
|
||||
({embed, meta}) => {
|
||||
if (aborted) {
|
||||
return
|
||||
|
@ -77,7 +77,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else if (isBskyListUrl(extLink.uri)) {
|
||||
getListAsEmbed(getAgent(), fetchDid, extLink.uri).then(
|
||||
getListAsEmbed(agent, fetchDid, extLink.uri).then(
|
||||
({embed, meta}) => {
|
||||
if (aborted) {
|
||||
return
|
||||
|
@ -95,7 +95,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else {
|
||||
getLinkMeta(getAgent(), extLink.uri).then(meta => {
|
||||
getLinkMeta(agent, extLink.uri).then(meta => {
|
||||
if (aborted) {
|
||||
return
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ export function useExternalLinkFetch({
|
|||
})
|
||||
}
|
||||
return cleanup
|
||||
}, [extLink, setQuote, getPost, fetchDid, getAgent])
|
||||
}, [extLink, setQuote, getPost, fetchDid, agent])
|
||||
|
||||
return {extLink, setExtLink}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export const snapPoints = ['90%']
|
|||
export function Component() {
|
||||
const pal = usePalette('default')
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||
const [email, setEmail] = useState<string>(currentAccount?.email || '')
|
||||
|
@ -45,12 +45,12 @@ export function Component() {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
const res = await getAgent().com.atproto.server.requestEmailUpdate()
|
||||
const res = await agent.com.atproto.server.requestEmailUpdate()
|
||||
if (res.data.tokenRequired) {
|
||||
setStage(Stages.ConfirmCode)
|
||||
} else {
|
||||
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.com.atproto.server.updateEmail({email: email.trim()})
|
||||
await agent.resumeSession(agent.session!)
|
||||
Toast.show(_(msg`Email updated`))
|
||||
setStage(Stages.Done)
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ export function Component() {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await getAgent().com.atproto.server.updateEmail({
|
||||
await agent.com.atproto.server.updateEmail({
|
||||
email: email.trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.resumeSession(agent.session!)
|
||||
Toast.show(_(msg`Email updated`))
|
||||
setStage(Stages.Done)
|
||||
} catch (e) {
|
||||
|
|
|
@ -35,12 +35,12 @@ export type Props = {onChanged: () => void}
|
|||
|
||||
export function Component(props: Props) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {
|
||||
isLoading,
|
||||
data: serviceInfo,
|
||||
error: serviceInfoError,
|
||||
} = useServiceQuery(getAgent().service.toString())
|
||||
} = useServiceQuery(agent.service.toString())
|
||||
|
||||
return isLoading || !currentAccount ? (
|
||||
<View style={{padding: 18}}>
|
||||
|
@ -71,7 +71,7 @@ export function Inner({
|
|||
const {closeModal} = useModalControls()
|
||||
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
|
||||
useUpdateHandleMutation()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const [error, setError] = useState<string>('')
|
||||
|
||||
|
@ -111,7 +111,7 @@ export function Inner({
|
|||
await updateHandle({
|
||||
handle: newHandle,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.resumeSession(agent.session!)
|
||||
closeModal()
|
||||
onChanged()
|
||||
} catch (err: any) {
|
||||
|
@ -129,7 +129,7 @@ export function Inner({
|
|||
closeModal,
|
||||
updateHandle,
|
||||
serviceInfo,
|
||||
getAgent,
|
||||
agent,
|
||||
])
|
||||
|
||||
// rendering
|
||||
|
|
|
@ -37,7 +37,7 @@ export const snapPoints = isAndroid ? ['90%'] : ['45%']
|
|||
export function Component() {
|
||||
const pal = usePalette('default')
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.RequestCode)
|
||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||
|
@ -46,7 +46,6 @@ export function Component() {
|
|||
const [error, setError] = useState<string>('')
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
const {closeModal} = useModalControls()
|
||||
const agent = getAgent()
|
||||
|
||||
const onRequestCode = async () => {
|
||||
if (
|
||||
|
|
|
@ -62,7 +62,7 @@ export function Component({
|
|||
const {_} = useLingui()
|
||||
const listCreateMutation = useListCreateMutation()
|
||||
const listMetadataMutation = useListMetadataMutation()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const activePurpose = useMemo(() => {
|
||||
if (list?.purpose) {
|
||||
|
@ -157,7 +157,7 @@ export function Component({
|
|||
{cleanNewlines: true},
|
||||
)
|
||||
|
||||
await richText.detectFacets(getAgent())
|
||||
await richText.detectFacets(agent)
|
||||
richText = shortenLinks(richText)
|
||||
|
||||
// filter out any mention facets that didn't map to a user
|
||||
|
@ -229,7 +229,7 @@ export function Component({
|
|||
listMetadataMutation,
|
||||
listCreateMutation,
|
||||
_,
|
||||
getAgent,
|
||||
agent,
|
||||
])
|
||||
|
||||
return (
|
||||
|
|
|
@ -31,7 +31,7 @@ export function Component({}: {}) {
|
|||
const pal = usePalette('default')
|
||||
const theme = useTheme()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {removeAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const {closeModal} = useModalControls()
|
||||
|
@ -45,7 +45,7 @@ export function Component({}: {}) {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await getAgent().com.atproto.server.requestAccountDelete()
|
||||
await agent.com.atproto.server.requestAccountDelete()
|
||||
setIsEmailSent(true)
|
||||
} catch (e: any) {
|
||||
setError(cleanError(e))
|
||||
|
@ -63,7 +63,7 @@ export function Component({}: {}) {
|
|||
|
||||
try {
|
||||
// inform chat service of intent to delete account
|
||||
const {success} = await getAgent().api.chat.bsky.actor.deleteAccount(
|
||||
const {success} = await agent.api.chat.bsky.actor.deleteAccount(
|
||||
undefined,
|
||||
{
|
||||
headers: DM_SERVICE_HEADERS,
|
||||
|
@ -72,7 +72,7 @@ export function Component({}: {}) {
|
|||
if (!success) {
|
||||
throw new Error('Failed to inform chat service of account deletion')
|
||||
}
|
||||
await getAgent().com.atproto.server.deleteAccount({
|
||||
await agent.com.atproto.server.deleteAccount({
|
||||
did: currentAccount.did,
|
||||
password,
|
||||
token,
|
||||
|
|
|
@ -41,7 +41,7 @@ export function Component({
|
|||
onSuccess?: () => void
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(
|
||||
|
@ -64,7 +64,7 @@ export function Component({
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await getAgent().com.atproto.server.requestEmailConfirmation()
|
||||
await agent.com.atproto.server.requestEmailConfirmation()
|
||||
setStage(Stages.ConfirmCode)
|
||||
} catch (e) {
|
||||
setError(cleanError(String(e)))
|
||||
|
@ -77,11 +77,11 @@ export function Component({
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await getAgent().com.atproto.server.confirmEmail({
|
||||
await agent.com.atproto.server.confirmEmail({
|
||||
email: (currentAccount?.email || '').trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.resumeSession(agent.session!)
|
||||
Toast.show(_(msg`Email verified`))
|
||||
closeModal()
|
||||
onSuccess?.()
|
||||
|
|
|
@ -470,7 +470,7 @@ function ProfileScreenLoaded({
|
|||
}
|
||||
|
||||
function useRichText(text: string): [RichTextAPI, boolean] {
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const [prevText, setPrevText] = React.useState(text)
|
||||
const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text}))
|
||||
const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null)
|
||||
|
@ -485,7 +485,7 @@ function useRichText(text: string): [RichTextAPI, boolean] {
|
|||
async function resolveRTFacets() {
|
||||
// new each time
|
||||
const resolvedRT = new RichTextAPI({text})
|
||||
await resolvedRT.detectFacets(getAgent())
|
||||
await resolvedRT.detectFacets(agent)
|
||||
if (!ignore) {
|
||||
setResolvedRT(resolvedRT)
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ function useRichText(text: string): [RichTextAPI, boolean] {
|
|||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
}, [text, getAgent])
|
||||
}, [text, agent])
|
||||
const isResolving = resolvedRT === null
|
||||
return [resolvedRT ?? rawRT, isResolving]
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export function DisableEmail2FADialog({
|
|||
const t = useTheme()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const [stage, setStage] = useState<Stages>(Stages.Email)
|
||||
const [confirmationCode, setConfirmationCode] = useState<string>('')
|
||||
|
@ -41,7 +41,7 @@ export function DisableEmail2FADialog({
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await getAgent().com.atproto.server.requestEmailUpdate()
|
||||
await agent.com.atproto.server.requestEmailUpdate()
|
||||
setStage(Stages.ConfirmCode)
|
||||
} catch (e) {
|
||||
setError(cleanError(String(e)))
|
||||
|
@ -55,12 +55,12 @@ export function DisableEmail2FADialog({
|
|||
setIsProcessing(true)
|
||||
try {
|
||||
if (currentAccount?.email) {
|
||||
await getAgent().com.atproto.server.updateEmail({
|
||||
await agent.com.atproto.server.updateEmail({
|
||||
email: currentAccount!.email,
|
||||
token: confirmationCode.trim(),
|
||||
emailAuthFactor: false,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.resumeSession(agent.session!)
|
||||
Toast.show(_(msg`Email 2FA disabled`))
|
||||
}
|
||||
control.close()
|
||||
|
|
|
@ -13,17 +13,17 @@ export function Email2FAToggle() {
|
|||
const {currentAccount} = useSession()
|
||||
const {openModal} = useModalControls()
|
||||
const disableDialogCtrl = useDialogControl()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
|
||||
const enableEmailAuthFactor = React.useCallback(async () => {
|
||||
if (currentAccount?.email) {
|
||||
await getAgent().com.atproto.server.updateEmail({
|
||||
await agent.com.atproto.server.updateEmail({
|
||||
email: currentAccount.email,
|
||||
emailAuthFactor: true,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
await agent.resumeSession(agent.session!)
|
||||
}
|
||||
}, [currentAccount, getAgent])
|
||||
}, [currentAccount, agent])
|
||||
|
||||
const onToggle = React.useCallback(() => {
|
||||
if (!currentAccount) {
|
||||
|
|
|
@ -21,11 +21,10 @@ export function ExportCarDialog({
|
|||
}) {
|
||||
const {_} = useLingui()
|
||||
const t = useTheme()
|
||||
const {getAgent} = useAgent()
|
||||
const agent = useAgent()
|
||||
const [loading, setLoading] = React.useState(false)
|
||||
|
||||
const download = React.useCallback(async () => {
|
||||
const agent = getAgent()
|
||||
if (!agent.session) {
|
||||
return // shouldnt ever happen
|
||||
}
|
||||
|
@ -49,7 +48,7 @@ export function ExportCarDialog({
|
|||
setLoading(false)
|
||||
control.close()
|
||||
}
|
||||
}, [_, control, getAgent])
|
||||
}, [_, control, agent])
|
||||
|
||||
return (
|
||||
<Dialog.Outer control={control}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue